tavicu / homebridge-samsung-tizen

Homebridge plugin for Samsung TV's with Tizen OS
MIT License
638 stars 86 forks source link

HomeKit (Apple Home App) - Automation - Samsung TV state #598

Closed HeyWatchOutDude closed 1 year ago

HeyWatchOutDude commented 1 year ago

Hi,

I'm using an automation on my HomePod Mini to turn the LEDs (Govee) on/off when the Samsung TV get turned on/off.

But now comes the strange part ... sometimes the LEDs are turning off for like 2-3 seconds and then back on even when TV is still on.

I found out how to determine the cause of that issue:

Option 1: When navigating through the TV (with remote control) the "state" never changes to "inactive" (obviously)

Option 2: I have turned off the automation for turning off the LEDs synchrone with my TV - Which also means that I have to turn off the LEDs manually.

It seems like the automation isn't using the "power state" of the TV.

Note:

Any idea how to solve that issue?

jonnyborbs commented 1 year ago

I have this exact same problem and it seems relatively recent. This automation was stable before, but now the Govee LEDs are constantly turning on and off, because the TV’s state is constantly fluctuating. But those fluctuations aren’t recorded in the Homebridge logs, like they are when the TV actually changes state.

danyaero commented 1 year ago

Hi! Im also experiencing this behaviour. It's true that I've always had it, but usually had a work around of using a dummy switch to allow the enough time for the TV to be back on and not trigger my lights and accessories accidentally. But since a few weeks ago, not even with the dummy switch im able to get things to work. In my case, even when the TV is off, there must be some packages being sent that makes homebridge think the TV is on and triggers my automations. It happens the same as @HeyWatchOutDude, it triggers the automation and 2-3 seconds after it's turned off... very strange. Im running the latest version of everything, and my home bridge server is setup on a Mac Mini connected via ethernet, and the TV automations are the only ones that are not behaving properly. Don't know @tavicu if there's a work around or a fix for this?

tavicu commented 1 year ago

Samsung don't offer us any valid option to check the real state of TV. So we make improvisations trying to get a state close to the real state of TV.

How we check if the TV is on. First we ping the IP address, if the TV is awake then it will respond to ping. And we assume the TV is on. But there is also a standby state of TV when it's actually off but it responds to ping. That's why if we get a ping from the TV, we also make a HTTP call to /api/v2/ which tells us if the TV is in standby or not.

That's great, but sometimes the TV don't respond to the HTTP request and it's failing, and if it does, as fallback the TV will have the state of the ping. Why the HTTP request is failing? There are multiple reasons, slow network, older TV that respond slower or just a TV that had too much on his mind and it's responding very hard (just like a PC when you want to much from it and it starts lagging).

One scenario is that sometimes the TV wakes up to do stuff in the background even if it's OFF. If it wakes up then it will respond to ping, but at the beginning there may not respond to the HTTP request, and it will fallback to the ping status which is true(on), even if the TV is actually OFF..

The default timeout for the request is set to 250ms, that should be enough if there are no problems. The TV responds in approximate 5ms. What you can do is to hard restart your TV. You can do this by holding the power button pressed until the TV restarts and Samsung logo appears. You can also increase the timeout to 1000, that's 1 second. You can find how to do it here: https://github.com/tavicu/homebridge-samsung-tizen/issues/200#issuecomment-623593964

If you want to have 100% working automations the only option with Samsung TVs are to buy a power plug which reports the power consumption in real time. Then you will be able to monitor the power consumption and see if the TV is actually ON :)

HeyWatchOutDude commented 1 year ago

Thanks for your reply, I have already tested it with different timeout values, issue is still occurring.

As you mentioned I think I will get a "smart power adapter".

jonnyborbs commented 1 year ago

For me, adjusting that timeout to 1000 as advised has corrected the issue perfectly! There's a slight delay when actually turning the TV on now, which is acceptable. The Govee lights don't flap anymore and that's what counts. I'll experiment with tuning that timeout downwards to see if I can strike a better balance but this is fine as is if need be. Thanks for the tip.

samwhu30 commented 1 year ago

Ah I was also going to report this. I will run the recommended steps and hopefully that will solve the issue 🤞