merdok / homebridge-webos-tv

Homebridge plugin for LG webOS TVs
MIT License
664 stars 89 forks source link

[TV] Polling Erroneously Triggers Automation #528

Open JasonGoldenDDT opened 7 months ago

JasonGoldenDDT commented 7 months ago

Hello,

I have an LG TV and it use the TV's power status to control automation. I'm finding polling activity will trigger automation.

Use case:

When "TV Turns On" turn off Fan.

When LG server is polled and returns "on" value the automation is triggered again.

Is it possible to only inform HomeKit of actual changes instead of repeating known values? If polling returns the same value the push message sent when the device was turned on, nothing should happen.

Push (User powers on TV) - Tells HomeKit device is ON. Polling - "Devices is on" - this equals the last Push message, do nothing. Push (User powers off TV) - Tells HomeKit device is OFF. Polling - "Devices is off" - This equals the last Push message, do nothing.

Could logic like this be applied to this plug in to avoid duplicate message being sent to HomeKit?

merdok commented 7 months ago

Hi, i am not quite sure if i understand your issue correctly, but did you should be able to do what you describe in HomeKit already. You trigger some actions or automations based on the TV status. Is there an issue with that?

JasonGoldenDDT commented 7 months ago

It a problem I have with other plugins on home bridge.

I'm not sure what the technical cause for this problem is. It expressed as repeated triggering of a "device controlled" automation in HomeKit.

If you turn on the tv, HomeKit reflects this instantly.

When the plug in polls the api, it seems like it tells HomeKit again the device is on, trigging the device is on automation again.

merdok commented 7 months ago

What LG TV do you have?

JasonGoldenDDT commented 7 months ago

Model number 32LQ63BPUA, webOSTV 7.0(2.4.4), TV Firmware 4.40.91.

The TV powers on and off perfectly with HomeKit. It's the repeated automation triggers that makes it difficult to tie automation to its use.

merdok commented 7 months ago

As far as i can see your TV does not use polling to get the status but rather listens to the TV events as it is a newer one. The TV only sends the events when something happens and as far as i know it only sends the turn on event once. What you could is to enable deepDebugLog start homebridge in debug mode and check the log when the situations which you find is not correct happens, you can then post the log here so i can have a look.

JasonGoldenDDT commented 7 months ago

I see this in the log.

Idk if this causes an update to HomeKit or not.

image

merdok commented 7 months ago

That just states that the plugin is trying to connect to the tv, there might be something that causes it to disconnect, hence you need to enable the deepDebugLog so we can see the full log of what is happening. https://github.com/merdok/homebridge-webos-tv?tab=readme-ov-file#troubleshooting

JasonGoldenDDT commented 7 months ago

okay, I added,

{ "name": "Display", "ip": "10.0.145.9", "mac": "4c:ba:d7:e5:02:ea", "broadcastAdr": "10.0.145.233", "hideTvService": false, "volumeLimit": 100, "volumeControl": "none", "channelControl": false, **"deepDebugLog": true** }

And after rebooting homebridge, I see this in the log:

[4/20/2024, 8:42:45 AM] [homebridge-webos-tv] [Display] Error - Error: connect ETIMEDOUT 10.0.145.9:3000 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1605:16) { errno: -110, code: 'ETIMEDOUT', syscall: 'connect', address: '10.0.145.9', port: 3000 } [4/20/2024, 8:42:50 AM] [homebridge-webos-tv] [Display] Connecting to TV [4/20/2024, 8:43:27 AM] [homebridge-webos-tv] [Display] Connecting to TV [4/20/2024, 8:44:04 AM] [homebridge-webos-tv] [Display] Connecting to TV [4/20/2024, 8:44:41 AM] [homebridge-webos-tv] [Display] Connecting to TV [4/20/2024, 8:45:18 AM] [homebridge-webos-tv] [Display] Connecting to TV [4/20/2024, 8:45:55 AM] [homebridge-webos-tv] [Display] Connecting to TV [4/20/2024, 8:46:31 AM] [homebridge-webos-tv] [Display] Connecting to TV

It's unclear how homebridge updates HomeKit. Automation I have tied to the TV's state repeat.

merdok commented 7 months ago

But did you start homebridge in debug mode? This log only indicates that the plugin is trying to connect to your TV, based on that the plugin should not even work.

JasonGoldenDDT commented 7 months ago

Yep, I've had it turned on to troubleshoot multiple plugins that can't keep homekit in sync. I added the "deep debug" to this webos plug in and started homebridge. What you see is the result. Without interacting with the TV (which I don't usually do during the day), I just get repeated "Connecting messages."

Running 2.4.4 of the plugin.

Screenshot 2024-04-20 at 10 22 35 AM
merdok commented 7 months ago

Yeah, well that is certainly not the complete log so i guess that you are missing something. I would need the complete log, as without that it is impossible for me to tell why your TV constantly re-connects.

JasonGoldenDDT commented 4 months ago

My use case for this is to trigger scenes based on device status. To turn off lights when the TV turns on for example.

There is a large delay between when the TV status changes and when and if a scene fires. Unsure how to track this down, but it's a rare use case for me so I'm not tracking it closely.

merdok commented 4 months ago

I understand your use case, but that does not help much here to identify your issues. I would still need a proper debug log.

JasonGoldenDDT commented 3 months ago

I'll pull deeplogs over the weekend. I suspect I'm dealing with wifi stability issues that are difficult to pin down. I live in a congested radio environment in a downtown area. I'm finding that fluctuations in radio signals can cause Homekit and related devices to disconnect and reconned despite having created separate SSIDs and having multiple APs tuned to reduce this.

It seems like every time the wifi device reconnects its status is repeated through the system causing triggers to fire again.

Seems like a programing solution could be implemented that checks to see what the last message received said and if the new message is the same, don't do anything.

merdok commented 3 months ago

Every time the TV reconnects then the full state of the TV needs to be pulled, as there is no way to know for what reason the TV has gone offline. I guess the core issue here seems to be the highly unstable wifi connection, you would need to try to investigate that and possibly try out a wired connection and check if that fixes the issue.

JasonGoldenDDT commented 3 months ago

I'm still trying out different options like extending the "refresh" to 60000 ms.

I rent, my options for creating a wired network are limited. Wifi is it sadly. I've tuned my network with multiple SSIDs, two MESH configured Amplifi Alien APs and using inSSIDER regularly to pick the "best" channel. since the router can't figure it out.

I acknowledge this isn't a life threatening problem. It's a luxury to have the ability to automate your home with technology. Having said that, it does improves quality of life, reduces energy consumption, and when it works well can have an economic benefit.

It would be awesome if the community as a whole could create solutions that are more resilient to common situations like mine. Assuming everyone has the ability to create a wired network eliminates a large population of people who could benefit from technology and ruins their experience with its advances. And waiting for the next version and the expense of replacing your hardware to take advantage of often incomplete promises of improved tech is hostile to consumers. Something I wish we would change as it waste a lot of time and money.

It would be great if code was written to be resilient, like always asking a device "did you get that command?" or providing better tools for tuning a product you your environment.

Thank you for your response and work on making this plugin in better. I'll do what I can to assist in it's evolution.