Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TV not turning on despite reporting so #68

Open
KnifeWrench opened this issue Dec 31, 2024 · 16 comments
Open

TV not turning on despite reporting so #68

KnifeWrench opened this issue Dec 31, 2024 · 16 comments

Comments

@KnifeWrench
Copy link

KnifeWrench commented Dec 31, 2024

Using a 2024 MacBook Pro MacOS Sequoia with the lid closes (similar behavior with lid open). When it goes to sleep, this works beautifully. Trying to wake it on the other hand is less successful. According to the logs when the lid is open the TV turns back on, sets the hdmi input and switches it to pc mode, however the the TV does not actually turn on.

Same behavior with the lid closed apart from the logs are a bit more honest.

Lid open:

2024-12-30 23:38:45: Starting LGTV watcher...
2024-12-30 23:38:45: -- Done.
2024-12-30 23:50:06: Received event: 1
2024-12-30 23:50:06: Received event: 3
2024-12-30 23:50:06: TV is connected and going to sleep
2024-12-30 23:50:06: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.0.113  get_current_app
2024-12-30 23:50:07: TV is currently on input com.webos.app.hdmi2
2024-12-30 23:50:07: TV is configured to prevent sleep when using other input? true
2024-12-30 23:50:07: Computer should be connected to input HDMI_2
2024-12-30 23:50:07: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.0.113  get_current_app
2024-12-30 23:50:07: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.0.113  power_off
2024-12-30 23:50:08: TV screen was turned off with command `power_off`.
2024-12-30 23:50:08: Received event: 10
2024-12-30 23:50:32: Received event: 4
2024-12-30 23:50:32: Wake on LAN packet sent to 20:28:BC:**:**:**
2024-12-30 23:50:32: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.0.113  turn_screen_on
2024-12-30 23:50:35: TV was turned on
2024-12-30 23:50:35: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.0.113  get_current_app
2024-12-30 23:50:36: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.0.113  launch_app com.webos.app.hdmi2
2024-12-30 23:50:37: TV input switched to com.webos.app.hdmi2
2024-12-30 23:50:37: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.0.113  set_device_info HDMI_2 pc 'Mac'
2024-12-30 23:50:38: TV was set to PC mode
2024-12-30 23:50:38: Received event: 0
2024-12-30 23:50:38: Wake on LAN packet sent to 20:28:BC:**:**:**
2024-12-30 23:50:38: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.0.113  turn_screen_on
2024-12-30 23:50:38: TV was turned on
2024-12-30 23:50:38: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.0.113  get_current_app
2024-12-30 23:50:39: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.0.113  set_device_info HDMI_2 pc 'Mac'
2024-12-30 23:50:40: TV was set to PC mode
2024-12-30 23:50:40: Received event: 11
2024-12-30 23:50:40: Wake on LAN packet sent to 20:28:BC:**:**:**
2024-12-30 23:50:40: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.0.113  turn_screen_on
2024-12-30 23:50:41: TV was turned on
2024-12-30 23:50:41: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.0.113  get_current_app
2024-12-30 23:50:41: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.0.113  set_device_info HDMI_2 pc 'Mac'
2024-12-30 23:50:42: TV was set to PC mode

Lid closed:

2024-12-31 00:01:48: Received event: 1
2024-12-31 00:01:48: Received event: 3
2024-12-31 00:01:48: TV is connected and going to sleep
2024-12-31 00:01:48: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.0.113  get_current_app
2024-12-31 00:01:49: TV is currently on input com.webos.app.hdmi2
2024-12-31 00:01:49: TV is configured to prevent sleep when using other input? true
2024-12-31 00:01:49: Computer should be connected to input HDMI_2
2024-12-31 00:01:49: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.0.113  get_current_app
2024-12-31 00:01:50: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.0.113  power_off
2024-12-31 00:01:51: TV screen was turned off with command `power_off`.
2024-12-31 00:01:51: Received event: 10
2024-12-31 00:02:07: Received event: 11
2024-12-31 00:02:07: Received event: 0
2024-12-31 00:02:07: Received event: 4
@cmer
Copy link
Owner

cmer commented Jan 11, 2025

Did you enable Wake on LAN as mentioned here? This might be your issue.

@KnifeWrench
Copy link
Author

KnifeWrench commented Jan 12, 2025

Yup followed the readme initially, but obvs double checked. Both wake on LAN and the mobile one are on.

Debugging the script I could see that when lid was closed lgtv_is_connected() was returning false as soon as the the machine and tv entered sleep. I had wifi and lan both connected. Disconnecting wifi fixed this (for the most part, would still sometimes disconnect) meaning it was now behaving the same lid open or closed. Not the actual issue but nice.

Also in lgtv_exec_command I think you need to have if rc == 0 instead of if rc == nil . Think it may be hiding the timeouts.

@PylotLight
Copy link

This is also happening for me, I was previously using the windows app which worked fine for turning off and on.
Now using this mac version, turn off seems to work fine, but it does not turn on, despite the logs suggesting that it is.

2025-01-17 11:19:17: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  turn_screen_on
2025-01-17 11:19:18: TV was turned on
2025-01-17 11:19:18: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  get_current_app
2025-01-17 11:19:19: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  set_device_info HDMI_1 pc 'Mac'
2025-01-17 11:19:20: TV was set to PC mode

@cmer
Copy link
Owner

cmer commented Jan 17, 2025

Can you try running the command directly from the terminal to see if there's a hint?

@cmer
Copy link
Owner

cmer commented Jan 17, 2025

Try installing the new version. I improved logging a little bit.

@PylotLight
Copy link

PylotLight commented Jan 17, 2025

TV on:
❯ ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  turn_screen_on
Traceback (most recent call last):
  File "/private/var/folders/l7/qqxmqd5170nfkmjpgpzjx6cc0000gn/T/tmp.2qwVc3ZXId/venv/bin/bscpylgtvcommand.py", line 8, in <module>
  File "bscpylgtv/utils.py", line 111, in bscpylgtvcommand
  File "asyncio/runners.py", line 194, in run
  File "asyncio/runners.py", line 118, in run
  File "asyncio/base_events.py", line 721, in run_until_complete
  File "bscpylgtv/utils.py", line 18, in runloop
  File "bscpylgtv/webos_client.py", line 886, in turn_screen_on
  File "bscpylgtv/webos_client.py", line 671, in request
bscpylgtv.exceptions.PyLGTVCmdError: {'type': 'error', 'id': 0, 'error': '500 Application error', 'payload': {'returnValue': False, 'state': 'Active', 'errorCode': '-102', 'errorText': "The current sub state must be 'screen off'"}}
[PYI-45869:ERROR] Failed to execute script 'bscpylgtvcommand' due to unhandled exception!

TV off:
~ 
❯ ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  turn_screen_on
Traceback (most recent call last):
  File "/private/var/folders/l7/qqxmqd5170nfkmjpgpzjx6cc0000gn/T/tmp.2qwVc3ZXId/venv/bin/bscpylgtvcommand.py", line 8, in <module>
  File "bscpylgtv/utils.py", line 111, in bscpylgtvcommand
  File "asyncio/runners.py", line 194, in run
  File "asyncio/runners.py", line 118, in run
  File "asyncio/base_events.py", line 721, in run_until_complete
  File "bscpylgtv/utils.py", line 17, in runloop
  File "bscpylgtv/webos_client.py", line 150, in connect
  File "bscpylgtv/webos_client.py", line 199, in connect_handler
  File "websockets/asyncio/connection.py", line 313, in recv
websockets.exceptions.ConnectionClosedError: received 1008 (policy violation) Try Again Later (EWS); then sent 1008 (policy violation) Try Again Later (EWS)
[PYI-45947:ERROR] Failed to execute script 'bscpylgtvcommand' due to unhandled exception!

2025-01-17 16:02:56: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  get_current_app
2025-01-17 16:02:57: Current app ID: com.webos.app.hdmi1
2025-01-17 16:02:57: -- Loading extension: screen
2025-01-17 16:02:57: Connected screens: { [1] = hs.screen: LG TV SSCR2 (0x600000ca4138),[2] = hs.screen: Built-in Retina Display (0x600000ca4178),} 
2025-01-17 16:02:57: TV is connected? true
2025-01-17 16:02:57: 
-------------------------------------------------------------------------------------------------------------------


2025-01-17 16:02:57: Starting LGTV watcher...
2025-01-17 16:02:57: -- Done.
2025-01-17 16:03:16: Received event: 10 (screensDidLock)
2025-01-17 16:03:21: Received event: 3 (screensDidSleep)
2025-01-17 16:03:21: TV is connected and going to sleep
2025-01-17 16:03:21: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  get_current_app
2025-01-17 16:03:22: TV is currently on input com.webos.app.hdmi1
2025-01-17 16:03:22: TV is configured to prevent sleep when using other input? true
2025-01-17 16:03:22: Computer should be connected to input HDMI_1
2025-01-17 16:03:22: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  get_current_app
2025-01-17 16:03:23: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  power_off
2025-01-17 16:03:24: TV screen was turned off with command `power_off`.
2025-01-17 16:03:24: Received event: 4 (screensDidWake)
2025-01-17 16:03:24: Wake on LAN packet sent to 34:E6:E6:A:F4:90
2025-01-17 16:03:24: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  turn_screen_on
2025-01-17 16:03:26: Command timed out or failed (exit code: 1): ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  turn_screen_on
2025-01-17 16:03:26: TV was turned on
2025-01-17 16:03:26: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  get_current_app
2025-01-17 16:03:27: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  set_device_info HDMI_1 pc 'Mac'
2025-01-17 16:03:28: Command timed out or failed (exit code: 1): ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  set_device_info HDMI_1 pc 'Mac'
2025-01-17 16:03:28: TV was set to PC mode
2025-01-17 16:03:28: Received event: 11 (screensDidUnlock)
2025-01-17 16:03:28: Wake on LAN packet sent to 34:E6:E6:A:F4:90
2025-01-17 16:03:28: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  turn_screen_on
2025-01-17 16:03:29: Command timed out or failed (exit code: 1): ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  turn_screen_on
2025-01-17 16:03:29: TV was turned on
2025-01-17 16:03:29: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  get_current_app
2025-01-17 16:03:30: Command timed out or failed (exit code: 1): ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  get_current_app
2025-01-17 16:03:30: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  launch_app com.webos.app.hdmi1
2025-01-17 16:03:30: Command timed out or failed (exit code: 1): ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  launch_app com.webos.app.hdmi1
2025-01-17 16:03:30: TV input switched to com.webos.app.hdmi1
2025-01-17 16:03:30: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  set_device_info HDMI_1 pc 'Mac'
2025-01-17 16:03:31: Command timed out or failed (exit code: 1): ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5  set_device_info HDMI_1 pc 'Mac'
2025-01-17 16:03:31: TV was set to PC mode

@cmer
Copy link
Owner

cmer commented Jan 17, 2025

@PylotLight Looks like the TV is rejecting the request. See: https://www.perplexity.ai/search/i-m-trying-to-turn-on-and-off-fuEMHdyLR6SgnHJLD4ICIg

@cmer
Copy link
Owner

cmer commented Jan 18, 2025

I just pushed out a pretty big update which should hopefully resolve these issues. Let me know!

@PylotLight
Copy link

PylotLight commented Jan 18, 2025

Ok sweet it does look like thats improved.

  1. The screen turns on as requested
  2. However, I'm noticing the off functionality isn't working.. it's going to no signal instead of turning off, which is not super ideal.
2025-01-18 18:37:53: MacBook Pro Speakers (eqMac) is the current audio device.
2025-01-18 18:37:53: Received event: 10 (screensDidLock)
2025-01-18 18:37:58: Received event: 3 (screensDidSleep)
2025-01-18 18:37:58: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5 get_current_app
2025-01-18 18:38:00: TV is connected and going to sleep
2025-01-18 18:38:00: Current TV input: com.webos.app.hdmi1
2025-01-18 18:38:00: Prevent sleep on other input: true
2025-01-18 18:38:00: Expected computer input: HDMI_1
2025-01-18 18:38:00: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5 screen_off
2025-01-18 18:38:01: Command failed or timed out (exit code: 1): ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5 screen_off
2025-01-18 18:38:01: Command stdout: 
2025-01-18 18:38:01: -- Loading extension: timer
2025-01-18 18:38:02: Retrying command after 1 second delay...
2025-01-18 18:38:02: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5 screen_off
2025-01-18 18:38:03: Command failed or timed out (exit code: 1): ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5 screen_off
2025-01-18 18:38:03: Command stdout: 
2025-01-18 18:38:12: Received event: 4 (screensDidWake)
2025-01-18 18:38:12: Wake on LAN packet sent to 34:E6:E6:A:F4:90
2025-01-18 18:38:12: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5 turn_screen_on
2025-01-18 18:38:13: Command failed or timed out (exit code: 1): ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5 turn_screen_on
2025-01-18 18:38:13: Command stdout: 
2025-01-18 18:38:14: Retrying command after 1 second delay...
2025-01-18 18:38:14: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5 turn_screen_on
2025-01-18 18:38:15: Command failed or timed out (exit code: 1): ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5 turn_screen_on
2025-01-18 18:38:15: Command stdout: 
2025-01-18 18:38:15: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5 get_current_app
2025-01-18 18:38:16: Executing command: ~/bin/bscpylgtvcommand -p ~/.aiopylgtv.sqlite 192.168.1.5 set_device_info HDMI_1 pc 'Mac'
2025-01-18 18:38:17: Set TV to PC mode
2025-01-18 18:38:17: Received event: 11 (screensDidUnlock)
2025-01-18 18:38:17: Skipping wake execution - debounced.
  1. I know it's possible to turn off and fully turn on again, while I am on wireless and I can test wired, it should also be possible with wireless as windows worked fine.
  2. Getting debug log spam, which seems to be added to on key press:
2025-01-18 18:37:24: MacBook Pro Speakers (eqMac) is the current audio device.
2025-01-18 18:37:24: MacBook Pro Speakers (eqMac) is the current audio device.
2025-01-18 18:37:24: MacBook Pro Speakers (eqMac) is the current audio device.
2025-01-18 18:37:25: MacBook Pro Speakers (eqMac) is the current audio device.
2025-01-18 18:37:25: MacBook Pro Speakers (eqMac) is the current audio device.
2025-01-18 18:37:25: MacBook Pro Speakers (eqMac) is the current audio device.
2025-01-18 18:37:27: MacBook Pro Speakers (eqMac) is the current audio device.
2025-01-18 18:37:27: MacBook Pro Speakers (eqMac) is the current audio device.

@cmer
Copy link
Owner

cmer commented Jan 18, 2025

What TV are you using? I have a C2. Mine works as expected. I'm on a desktop Mac though. Previously Mac Studio, now Mac Mini. I wonder if we're on a different firmware.

FYI I changed power_off to screen_off to fix the policy error.

I fixed the "log spam".

@PylotLight
Copy link

PylotLight commented Jan 19, 2025

What TV are you using? I have a C2

I have a C4

FYI I changed power_off to screen_off to fix the policy error.

Will test later

I fixed the "log spam".

Thanks!

Thanks again for your work on this one, good to make sure there's a solution for this on all platforms :D

@PylotLight
Copy link

PylotLight commented Jan 19, 2025

hmm yep, looks like I can currently choose between auto screen off, or auto screen on but not both.
I'm certain it worked via windows version so curious why the script fails for the same thing. Might try look at the Windows version to compare at some point.
While it might be a wifi/lan thing here, the windows version worked fine with wifi as well, so it 'should' be possible. See how we go.
Cheers for your efforts for now.

@cmer
Copy link
Owner

cmer commented Feb 4, 2025

What WebOS version are you on?

@PylotLight
Copy link

webOS24 / 9.2.2.2-1805 (latest)

@cmer
Copy link
Owner

cmer commented Feb 4, 2025

My C2 doesn't seem to have webOS24 available. I'm still on 23. Everything works well for me.

@PylotLight
Copy link

what difference does that make?
Should be basically the same controls no?
Anything I should test/check from my side to see if something has changed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants