tavicu / homebridge-samsung-tizen

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

TV power state erroneously triggers HomeKit automation #474

Closed ramm64 closed 2 years ago

ramm64 commented 2 years ago

Hi @tavicu — Posting this here in case you have any insight. One issue comes up related to the TV power state: I have an automation in the Home app to turn OFF some Hue lights if/when the Samsung TV turns OFF. Most of the time this works as expected, but many times the lights will turn OFF even though the TV continues to be ON. I can trace this issue to the automation itself, so somehow HomeKit thinks the TV has turned off (even though it’s still on) so my lights get turned off as well.

I set Homebridge to DEBUG mode but I see very few messages related to the plugin in the logs. I see the messages indicating that the lights have been switched off, but no messages from your plugin that would indicate the TV has powered off as a trigger to the automation being fired.

One message that I see in the log is this one:

[16/02/2022, 12:34:51] [My TV] [DEBUG] https://api.smartthings.com/v1/devices/MY DEVICE ID/status undefined

Does this ring a bell with you? Could this be the possible source of the issue? Any insight would be welcome. Thanks again for all your efforts with this plugin.

tavicu commented 2 years ago

Hi @ramm64

The message from the log it's ok, it just indicates that it made a request to that URL, it's not an error.

From what you describe looks like when the plugin checks if the TV is on/off somehow it sees it as OFF.

If you are comfortable with editing a few lines a cod i will guide you how to do it.

First tell me if you know the path where the plugins are installed. If not, let me know how you run homebridge server (docker/installing it with npm install -g/other)

ramm64 commented 2 years ago

Hi @tavicu, thanks for replying.

Correct, HomeKit sees the TV as off and it fires the automation to turn off my Hue lights. It happens sporadically, sometimes it will work perfectly but others it will malfunction.

Happy to add new lines of code but — I’m afraid I have my Homebridge server running on an RPi using homebridge-config-ui-x, so I don’t know the path where the plugins are installed. Does this give you enough to help? Let me know if you need anything else.

tavicu commented 2 years ago

Can you run this command in the terminal please? npm root -g This will tell us the path where global npm packages are installed.

Then in that folder it should be another folder called homebridge-samsung-tizen

For example, if the path returned by the command is /usr/local/lib/node_modules the plugin should be in /usr/local/lib/node_modules/homebridge-samsung-tizen

Could you please check and confirm for me?

ramm64 commented 2 years ago

Confirmed: Path to plugins is /usr/local/lib/node_modules and the homebridge-samsung-tizen plugin folder is present within that directory.

tavicu commented 2 years ago

Cool. Before we proceed with changing settings i suspect your TV is responding slower to requests. So i will ask you to change a parameter (timeout) and see if the problem persists. If it does we will start changing files.

You can also check what we did here because i think it's the same problem: https://github.com/tavicu/homebridge-samsung-tizen/issues/417

Let's change the timeout to 1500ms (1.5 seconds) like this:

{
    "platform": "SamsungTizen",
    "devices": [
        {
            "name": "Bedroom TV",
            "ip": "10.20.30.40",
            "mac": "A0:B1:C2:D3:E4:F5",
            "timeout": 1500
        }
    ]
}

After that, please restart the homebridge server.

Let me know in the following days if the problem persist.

Also, please note that this is not normal, the TV should respond in a few ms. This means there is a problem somewhere and i suspect it's on your PI (this happened before and it was always the server). But first change the timeout and will see after that :)

ramm64 commented 2 years ago

Perfect! I just added the 1500 ms timeout to the config file. I’ll keep an eye on performance and will report in a few days. I will also consider connecting my Pi to the LAN via Ethernet (it’s currently on wi-fi. I know, I know…😉).

Now I’m gonna get that new beta version installed… Thank you, @tavicu!

HawkBYU commented 2 years ago

I have been experiencing a similar issue. I have an automation setup that turns on Art Mode on my Samsung Frame TV when the TV turns off. Because of the way Apple TV works with the Frame TV, it powers off completely when using the remote. Therefore, I use this automation to turn on the Art Mode. When I have this automation enabled, the TV will randomly run the automation. I have tried charging the config file, as suggested, but I am still having the same result. Any suggestions?

ramm64 commented 2 years ago

A report from my side: Changing the timeout period to 1500ms seems to have stabilized my setup. In the last 12 days my TV has only turned off once unexpectedly by my automation.

tavicu commented 2 years ago

A report from my side: Changing the timeout period to 1500ms seems to have stabilized my setup. In the last 12 days my TV has only turned off once unexpectedly by my automation.

You can start following this and find out what is responding slow in your network. As you could see there the response should be in ~7ms, so 1500ms it's huge and somewhere it's definitely a problem :) https://github.com/tavicu/homebridge-samsung-tizen/issues/324#issuecomment-804746398

ramm64 commented 2 years ago

Well, even with the huge timeout value the issue seems to have gone away for me. Can you tell me what are the negative repercussions of leaving timeout = 1500? Should I try reducing the value before I start changing code (which is inherently risky for a newbie like me)?

EDITS

I decided to take the plunge and edited base.js as you directed in #324. Below are the results:

debug from console:

getInfo - time 62
getInfo - time 79
getInfo - time 77
getInfo - time 76
getInfo - time 66
getInfo - time 80
getInfo - time 65
getInfo - time 62
>>getInfo - time 347
getInfo - time 69
getInfo - time 71
getInfo - time 65
getInfo - time 83
>>getInfo - time 120
getInfo - time 57

curl commands:

Total: 0.266948s
Total: 0.081549s
>>Total: 0.661845s
Total: 0.294135s
Total: 0.087112s
Total: 0.077667s
Total: 0.088679s
Total: 0.074781s
Total: 0.128029s
Total: 0.076287s
Total: 0.162303s
Total: 0.139054s
Total: 0.084647s
Total: 0.085501s
>>Total: 1.262662s
Total: 0.092731s
Total: 0.098782s
Total: 0.072975s

I can see a couple of long result times, but they seem like exceptions (see ">>" above). Does this help give you an idea of what's going on? I'll wait to hear from you before changing anything (timeout value, connect everything to ethernet).

Thanks.

tavicu commented 2 years ago

Hi, sorry for late reply!

The default timeout for getInfo it's 500 ms, so 347 and 120 are not great but they are still in the acceptable range.

Also the Curl commands appears to take a lot!

Did you tried to force restart the TV? Holding power button until the Samsung logo appears. If this doesn't solve the problem the problem may come from your machine where you host the homebridge server or from your network (maybe on WiFi and having low signal)

Having a big timeout will affects how fast the plugin reacts to your commands and depending on how big it is some request may overlap. But 1500 it's not that huge of a deal. But for sure somewhere in your ecosystem there is a problem because as you could see on my examples it should respond in ~6 milliseconds!

ramm64 commented 2 years ago

Ok, thanks for your feedback. I was doing well with my RPi connected to Ethernet the last few days, but just today my lights started turning off unexpectedly again (while TV was on). I just rebooted the TV and increased value of the timeout parameter to 1000. I’ll keep an eye on the setup over the next few days.

ramm64 commented 2 years ago

@tavicu — Quick update: Things appear to be working worse now regarding this issue. After several days of my lights staying on without issue, the last couple of days the lights keep turning themselves off even though the TV remains on. This seemed to work better on the beta versions of the plugin. Is it possible that a regression was introduced with the release of the final plugin version? I have reset the TV a few times, have my RPi connected via Ethernet, set the timeout parameter to 1500, and the automation repeatedly triggers as if the TV has turned off even though it hasn’t.

Any suggestions? Thanks in advance.

tavicu commented 2 years ago

@tavicu — Quick update: Things appear to be working worse now regarding this issue. After several days of my lights staying on without issue, the last couple of days the lights keep turning themselves off even though the TV remains on. This seemed to work better on the beta versions of the plugin. Is it possible that a regression was introduced with the release of the final plugin version? I have reset the TV a few times, have my RPi connected via Ethernet, set the timeout parameter to 1500, and the automation repeatedly triggers as if the TV has turned off even though it hasn’t.

Nothing was changed between beta and actual release.

Any suggestions? Thanks in advance.

As I already told you, timeout it's not a fix. Because requests may respond in 200ms now and tomorrow in 3 seconds. You must find out what is keeping your connection low.

FIrst you could start by checking the inputs you set, try to not have too many inputs of type app! Each input will result in one request at 30 seconds. If you have 10 inputs this will result in 10 requests each 30 seconds and it will slow your TV response.

Then see how many plugins you have in your Homebridge server. Try to split them in multiple bridges. You can do this from Config UI X.

How is your PI? It is running only this server or you have other things too? Like a Plex server or something. Because depending on what you run on it it may run slower. What is the temperature of the Pi CPU when running? After ~75degree it will start to underclock the CPU.

If you have other PC in the house, try to run the curl command and see the results. If they are better that means the problem is somewhere on the PI. If they are still bad means your TV may actually respond slow or the network connection it's not good. You could also try to force restart the TV by holding the power button on the remote until you see the samsung logo.

ramm64 commented 2 years ago

Got it. Thank you for confirming. I will continue to troubleshoot my RPi and network and see if I can get this to stabilize. I’m also trying a few things using a shortcut within the automation so that the automation doesn’t fire if the trigger is erroneously set.

If you feel this is addressed from your side, please feel free to close the issue. And THANK YOU once more for all your efforts with this plugin, I appreciate it.