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 · 7 comments
Open

TV not turning on despite reporting so #68

KnifeWrench opened this issue Dec 31, 2024 · 7 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

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