cmer / lg-tv-control-macos

Automatically wake/sleep and change the input of your LG TV when used as a monitor on macOS
129 stars 13 forks source link

Followed setup instructions but input not changing #22

Closed jsaltzman closed 9 months ago

jsaltzman commented 1 year ago

I followed the setup instructions. I got the LG remote downloaded, the tv paired, and manually sending commands worked. I downloaded the provided script and edited to change HDMI input to correct input. Hammerspoon is running. But when I plugin my hdmi cable, nothing happens. Can you please help me troubleshoot? Is there a log I can look to?

devantler commented 1 year ago

If you open Hammerspoon it has a log :-)

It looks something like this depending on your OS:

image

jsaltzman commented 1 year ago

Here is the full log. Does this mean it is not loading the lgtv_init file?

my init.lua file has one line: require "lgtv_init"

2023-09-12 16:11:43: Welcome to the Hammerspoon Console! You can run any Lua code in here.

2023-09-12 16:11:43: -- Lazy extension loading enabled 2023-09-12 16:11:43: -- Loading ~/.hammerspoon/init.lua 2023-09-12 16:11:43: -- Loading extension: caffeinate 2023-09-12 16:11:43: -- Done. 2023-09-12 16:12:44: -- Lazy extension loading enabled 2023-09-12 16:12:44: -- Loading ~/.hammerspoon/init.lua 2023-09-12 16:12:44: -- Done. 2023-09-12 16:13:01: -- Lazy extension loading enabled 2023-09-12 16:13:01: -- Loading ~/.hammerspoon/init.lua 2023-09-12 16:13:01: -- Loading extension: caffeinate 2023-09-12 16:13:01: -- Done.

devantler commented 1 year ago

Did you put lgtv_init.lua in ~/.hammerspoon. It should be the same location as the init.lua file?

If yes, try clicking "Reload Config" in the Hammerspoon UI

jsaltzman commented 1 year ago

Yes it is there, and I have reloaded the config a bunch.

image
devantler commented 1 year ago

Hmm if that is indeed in your home folder, I am not sure what is going on here. It should work like that. Maybe it can bring luck to try to reinstall Hammerspoon:

brew uninstall hammerspoon && brew install hammerspoon

EDIT: Oh wait. Did you enable debugging in the lgtv_init.lua script?

jsaltzman commented 1 year ago

I did not have debugging on, thanks.

I am still not getting the tv to turn on or switch HDMI when I plug in. I am going to paste my logs. At the end of the log I plug in HDMI and nothing happens. and throughout I was plugging in and unplugging HDMI to test the script.

2023-09-12 20:11:20: Welcome to the Hammerspoon Console! You can run any Lua code in here.

2023-09-12 20:11:20: -- Lazy extension loading enabled 2023-09-12 20:11:20: -- Loading ~/.hammerspoon/init.lua 2023-09-12 20:11:20: TV name: MyTV 2023-09-12 20:11:20: TV input: HDMI_2 2023-09-12 20:11:20: LGTV path: ~/opt/lgtv/bin/lgtv 2023-09-12 20:11:20: LGTV command: ~/opt/lgtv/bin/lgtv MyTV 2023-09-12 20:11:20: SSL: true 2023-09-12 20:11:20: App ID: com.webos.app.hdmi2 2023-09-12 20:11:20: lgtv_disabled: false 2023-09-12 20:11:20: Executing command: ~/opt/lgtv/bin/lgtv MyTV swInfo ssl 2023-09-12 20:11:20: {"type": "response", "id": "sw_info_0", "payload": {"returnValue": true, "product_name": "webOSTV 7.0", "model_name": "HE_DTV_W22O_AFABATAA", "sw_type": "FIRMWARE", "major_ver": "03", "minor_ver": "33.16", "country": "US2", "country_group": "US", "device_id": "ac:5a:f0:73:5f:2c", "auth_flag": "N", "ignore_disable": "N", "eco_info": "01", "config_key": "00", "language_code": "en-US"}} {"closing": {"code": 1000, "reason": ""}}

2023-09-12 20:11:20: Executing command: ~/opt/lgtv/bin/lgtv MyTV getForegroundAppInfo ssl 2023-09-12 20:11:20: {"type": "response", "id": "0", "payload": {"returnValue": true, "appId": "com.webos.app.hdmi1", "processId": "", "windowId": ""}} {"closing": {"code": 1000, "reason": ""}}

2023-09-12 20:11:20: -- Loading extension: screen 2023-09-12 20:11:20: Connected screens: { [1] = hs.screen: Built-in Retina Display (0x600002cfd138),[2] = hs.screen: LG TV SSCR2 (0x600002cfd178),} 2023-09-12 20:11:20: LG TV is connected 2023-09-12 20:11:20: TV is connected? true 2023-09-12 20:11:20: -- Loading extension: caffeinate 2023-09-12 20:11:20: -- Loading extension: eventtap 2023-09-12 20:11:20: -- Done. 2023-09-12 20:11:22: -- Loading extension: audiodevice 2023-09-12 20:11:22: MacBook Pro Speakers is the current audio device. 2023-09-12 20:11:22: MacBook Pro Speakers is the current audio device. 2023-09-12 20:11:24: MacBook Pro Speakers is the current audio device. 2023-09-12 20:11:24: MacBook Pro Speakers is the current audio device. 2023-09-12 20:11:27: MacBook Pro Speakers is the current audio device. 2023-09-12 20:11:29: MacBook Pro Speakers is the current audio device. 2023-09-12 20:11:30: MacBook Pro Speakers is the current audio device. 2023-09-12 20:11:30: MacBook Pro Speakers is the current audio device. 2023-09-12 20:21:51: Received event: 3 screensDidSleep 2023-09-12 20:21:51: No screens are connected. Please check the 'connected_tv_identifier' in the 'lgtv_init.lua' script matches your connected screen. 2023-09-12 20:21:51: TV was not turned off because it is not connected 2023-09-12 20:21:52: Received event: 10 screensDidLock 2023-09-12 20:21:52: Event ignored 2023-09-12 20:21:53: Received event: 4 screensDidWake 2023-09-12 20:21:53: No screens are connected. Please check the 'connected_tv_identifier' in the 'lgtv_init.lua' script matches your connected screen. 2023-09-12 20:21:53: TV was not turned on because it is not connected 2023-09-12 20:21:53: Received event: 11 screensDidUnlock 2023-09-12 20:21:53: No screens are connected. Please check the 'connected_tv_identifier' in the 'lgtv_init.lua' script matches your connected screen. 2023-09-12 20:21:53: TV was not turned on because it is not connected 2023-09-12 20:21:57: MacBook Pro Speakers is the current audio device. 2023-09-12 20:21:57: MacBook Pro Speakers is the current audio device. 2023-09-12 20:21:59: MacBook Pro Speakers is the current audio device. 2023-09-12 20:21:59: MacBook Pro Speakers is the current audio device. 2023-09-12 20:22:48: MacBook Pro Speakers is the current audio device. 2023-09-12 20:22:48: MacBook Pro Speakers is the current audio device. 2023-09-12 20:23:10: MacBook Pro Speakers is the current audio device. 2023-09-12 20:23:10: MacBook Pro Speakers is the current audio device. 2023-09-12 20:33:22: Received event: 3 screensDidSleep 2023-09-12 20:33:22: No screens are connected. Please check the 'connected_tv_identifier' in the 'lgtv_init.lua' script matches your connected screen. 2023-09-12 20:33:22: TV was not turned off because it is not connected 2023-09-12 20:33:22: Received event: 10 screensDidLock 2023-09-12 20:33:22: Event ignored 2023-09-12 20:43:16: Received event: 1 systemWillSleep 2023-09-12 20:43:16: No screens are connected. Please check the 'connected_tv_identifier' in the 'lgtv_init.lua' script matches your connected screen. 2023-09-12 20:43:16: TV was not turned off because it is not connected 2023-09-12 20:50:39: Received event: 0 systemDidWake 2023-09-12 20:50:39: No screens are connected. Please check the 'connected_tv_identifier' in the 'lgtv_init.lua' script matches your connected screen. 2023-09-12 20:50:39: TV was not turned on because it is not connected 2023-09-12 20:50:40: Received event: 4 screensDidWake 2023-09-12 20:50:40: No screens are connected. Please check the 'connected_tv_identifier' in the 'lgtv_init.lua' script matches your connected screen. 2023-09-12 20:50:40: TV was not turned on because it is not connected 2023-09-12 20:50:40: Received event: 11 screensDidUnlock 2023-09-12 20:50:40: No screens are connected. Please check the 'connected_tv_identifier' in the 'lgtv_init.lua' script matches your connected screen. 2023-09-12 20:50:40: TV was not turned on because it is not connected 2023-09-12 20:50:42: MacBook Pro Speakers is the current audio device. 2023-09-12 20:50:42: MacBook Pro Speakers is the current audio device. 2023-09-12 20:50:44: MacBook Pro Speakers is the current audio device. 2023-09-12 20:50:44: MacBook Pro Speakers is the current audio device. 2023-09-12 20:52:23: MacBook Pro Speakers is the current audio device. 2023-09-12 20:52:23: MacBook Pro Speakers is the current audio device. 2023-09-12 20:52:26: MacBook Pro Speakers is the current audio device. 2023-09-12 20:52:26: MacBook Pro Speakers is the current audio device. 2023-09-12 20:56:15: MacBook Pro Speakers is the current audio device. 2023-09-12 20:56:15: MacBook Pro Speakers is the current audio device. 2023-09-12 20:56:41: MacBook Pro Speakers is the current audio device. 2023-09-12 20:56:41: MacBook Pro Speakers is the current audio device. 2023-09-12 20:56:42: MacBook Pro Speakers is the current audio device. 2023-09-12 20:56:42: MacBook Pro Speakers is the current audio device. 2023-09-12 20:56:46: MacBook Pro Speakers is the current audio device. 2023-09-12 20:56:46: MacBook Pro Speakers is the current audio device.

devantler commented 1 year ago

Try to connect your TV to an HDMI port. Make sure the correct HDMI port and TV name is set in the script, and then start the script. Then the logs should guide you.

"I am still not getting the tv to turn on or switch HDMI when I plug in."

The script is not able to determine the HDMI port dynamically, and thus it cannot "switch" the HDMI when plugged in. The HDMI port and the TV name are hardcoded values in the script.

sanioka commented 1 year ago

jsaltzman Thanks for logs. Explanation:

(1)

2023-09-12 20:11:20: Connected screens: { [1] = hs.screen: Built-in Retina Display (0x600002cfd138),[2] = hs.screen: LG TV SSCR2 (0x600002cfd178),}

Ok, your TV name looks like LG TV SSCR2

(2)

2023-09-12 20:33:22: No screens are connected. Please check the 'connected_tv_identifier' in the 'lgtv_init.lua' script matches your connected screen.

It looks like inside lgtv_init.lua file your 12 line does not contain this name. Check 12 line: local connected_tv_identifiers = {"LG TV", "LG TV SSCR2", "HDMI"}