tavicu / homebridge-samsung-tizen

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

TV tile switches between “on” and “off” in Home app #535

Closed ramm64 closed 2 years ago

ramm64 commented 2 years ago

Recently I’ve noticed that when my TV is powered on, it constantly switches between “on” and “off” states in the Home app (but the TV’s physical power status doesn’t change, it remains “on”). Running the latest version of the plugin and latest versions of iOS. TV model is a recent 4K smart TV.

Output of http://MY_TV_IP:8001/api/v2/ is below. Also, see comment below my post to see the Home app behavior.

{"device":{"FrameTVSupport":"false","GamePadSupport":"true","ImeSyncedSupport":"true","Language":"en_US","OS":"Tizen","PowerState":"on","TokenAuthSupport":"true","VoiceSupport":"false","WallScreenRatio":"-1","WallService":"false","countryCode":"MX","description":"Samsung DTV RCR","developerIP":"0.0.0.0","developerMode":"0","duid":"uuid:MY_UUID","firmwareVersion":"Unknown","id":"uuid:MY_UUID","ip":"MY_TV_IP","model":"21_KANTSU2E_UHD_BASIC","modelName":"UN43AU7000FXZX","name":"Samsung TV","networkType":"wireless","resolution":"3840x2160","smartHubAgreement":"true","ssid":"84:d8:1b:e4:8c:87","type":"Samsung SmartTV","udn":"MY_UUID","wifiMac":"MY_TV_MAC"},"id":"MY_UUID","isSupport":"{\"DMP_DRM_PLAYREADY\":\"false\",\"DMP_DRM_WIDEVINE\":\"false\",\"DMP_available\":\"true\",\"EDEN_available\":\"true\",\"FrameTVSupport\":\"false\",\"ImeSyncedSupport\":\"true\",\"TokenAuthSupport\":\"true\",\"remote_available\":\"true\",\"remote_fourDirections\":\"true\",\"remote_touchPad\":\"true\",\"remote_voiceControl\":\"false\"}\n","name":"Samsung TV","remote":"1.0","type":"Samsung SmartTV","uri":"http://MY_TV_IP:8001/api/v2/","version":"2.0.25"}

ramm64 commented 2 years ago

Home App GIF

tavicu commented 2 years ago

Hei,

I can see from the logs that your tv supports PowerState.

The process of checking if TV is on:

My guess is that your TV sometimes don't respond to the /api/v2/ request. Right now if the request is failing then the plugin thinks the TV is off.

I am planning to change this and if the request failed to just set the state of the ping.

For now please hard restart your TV by holding the power button from the physical remote until the Samsung logo appears.

Then follow the home app and if this is still happening I will guide you to see exactly what is failing in the check process.

Edit: don't remove the TV from home app or something, it will not help :)

ramm64 commented 2 years ago

For now please hard restart your TV by holding the power button from the physical remote until the Samsung logo appears.

I just tried restarting the TV and the behavior did not change. Still cycling on/off in Home.app.

tavicu commented 2 years ago

From the server where you are running homebridge server please run this command multiple times in a terminal and show me the result. This will tell us how much time it takes for your TV to respond.

curl -o /dev/null -s -w 'Total: %{time_total}s\n' 'http://TV_IP:8001/api/v2/'

ramm64 commented 2 years ago

Wow, it’s all over the place 🤦🏽‍♂️

Total: 0.058923s
Total: 0.002704s
Total: 0.052228s
Total: 0.049464s
Total: 5.049289s
Total: 2.842806s
Total: 0.064257s
Total: 0.462300s
Total: 0.122701s
Total: 2.839250s
Total: 1.578057s
tavicu commented 2 years ago

That's not good. My TVs usually responds in ~5ms (Total: 0.005121s)

On what machine you are running homebridge server? Did you changed anything? Like adding something new that uses more resources from the machine?

ramm64 commented 2 years ago

I run Homebridge on a Raspberry Pi 4. I can’t think of any changes made recently, really. The server is connected via ethernet to my network. The only thing I can think of is that we had a series of power outages here recently. This issue started happening recently after months of solid performance. Perhaps the server should be rebooted?

tavicu commented 2 years ago

Yup, try to reboot the server and after that run the command again. Let me know if there is any improvement.

ramm64 commented 2 years ago

Ok, rebooted the server and ran curl commands. No improvement. Still a pretty consistent response time divergence between 0.05s and 5s. Will connect my TV to the LAN via ethernet and see if anything changes.

tavicu commented 2 years ago

From the previous experience with people having the same problem, it was never the TV. The problem always come from the server.

Do you have other laptop/pc to try the command? This will help you see if it's the TV or the server.

ramm64 commented 2 years ago

From the previous experience with people having the same problem, it was never the TV. The problem always come from the server.

Makes sense. I just moved the TV to ethernet and still no change. So my server has somehow deteriorated in performance, I'm not sure why... BTW, the plugin is running as a child bridge.

Do you have other laptop/pc to try the command? This will help you see if it's the TV or the server.

I do have a laptop. Should I run the command from a terminal window in my MacBook Pro? I've done this before to troubleshoot a similar issue so I can try again.

ramm64 commented 2 years ago

Ok, tried running curl from a terminal window in laptop. Below are results:

Total: 0.082641s
Total: 4.466961s
Total: 0.133633s
Total: 0.051123s
Total: 0.257822s
Total: 7.547218s
Total: 0.169135s
Total: 0.282361s
Total: 5.366429s
Total: 0.060625s
Total: 0.052782s
Total: 0.277979s
Total: 5.061068s
Total: 1.143707s
Total: 2.610979s
Total: 0.279691s
Total: 6.293457s
tavicu commented 2 years ago

Still huge. So it’s not the server.

Try to restart your router

ramm64 commented 2 years ago

Restarted router and all access points. No joy. I’m out of ideas 😩

Edit: After looking at previous (related) issues, I added a timeout value to the config file. I also removed all inputs from the config (I wasn’t using them anyway, only an Apple TV on HDMI 1) and the issue has gone away. Not sure if the timeout or the input deletion made a difference…

tavicu commented 2 years ago

The timeout did the difference but that’s not a fix :). Also you have some pings up to 7 seconds.

Try one more thing, unplug the TV from the power outlet and leave it like that for a few hours if you can. Maybe overnight

ramm64 commented 2 years ago

Hi @tavicu -- Happy Friday!

A quick update from me on this issue:

When you get a chance, could you please comment on why this fork would be allowing my TV to function as expected in Home.app, without the power off/power on behavior I described? I'm going to guess that its "bareboness" is why the behavior in Home.app is different.

Thanks in advance and enjoy your weekend.

tavicu commented 2 years ago

Hi @ramm64,

That fork is "working" ok because it's an older version of the plugin which only used the ping method to check the TV status. Now beside checking the ping, we also make the request to /api/v2/.

Since the request is failing the plugin see your TV as offline. I will make an update to the plugin this weekend and if the request is failing to use the status from the ping, test it for 1-2 days and release it mid next week.

But this may be looking like the problem is fixed, but it's not. It will only be a "workaround". Your TV still responds slow to request.

Since you already tried another computer, the problem is clearly not from the homebridge server. Are you able to also try another router? Maybe you have an older one you could try.

My guess is your problem is on the network because if it was the TV, it should improve the results after a hard restart, but yours didn't.

If the problem persists even with another router, I would try a factory reset on the TV. But this will be the last resort.

Have an awesome weekend too :)

ramm64 commented 2 years ago

Hi @tavicu,

Thanks for the response. Completely coincidentally (!), yesterday my TV downloaded a software update (v. 2002) and it installed itself. After, I rebooted the TV and… The problem seems to have resolved itself! The TV tile remains powered “on” in the Home app. Amazing. I don’t even have a timeout command in the json config anymore!

I will keep an eye on this (and perhaps disable auto updates on the TV!) but, as you suspected, the culprit here may have been the TV all along, and the update addressed the slow response time (at least for now). I’ll head over to the Samsung web site and see if they published change notes with that update.

Let me know if you’d still like to make that change and use me to test it for you.

Thank you, sir! 🙏🏽

tavicu commented 2 years ago

Awesome to hear that! From my experience Samsung never said what changes an update have ...

Does the curl command return normal values now?

Let me know if you’d still like to make that change and use me to test it for you.

This will not be needed since the change it's not that big :) But thanks!

ramm64 commented 2 years ago

Does the curl command return normal values now?

Let me do some testing on this over the weekend and will publish my curl results shortly. Maybe you won’t need to make that change after all 😉

Thanks.

MarkBarbieri commented 2 years ago

This is the only site I've ever seen that has some form of (unofficial) detailed change logs https://eu.community.samsung.com/t5/tv/tv-firmware-changelogs-on-german-community/td-p/1846870

ramm64 commented 2 years ago

Hi @tavicu,

I just ran curl commands from my RPi terminal. See results below. As you will see, there’s a night-and-day difference in my TV’s response now (with latest firmware) and the previous results. Whatever the firmware update contained, it certainly addressed the TV’s response to API requests over the internet.

Total: 0.032778s
Total: 0.018363s
Total: 0.013989s
Total: 0.014126s
Total: 0.013030s
Total: 0.017305s
Total: 0.014135s
Total: 0.012972s
Total: 0.017253s
Total: 0.018374s
Total: 0.018653s
Total: 0.013989s
Total: 0.012905s
Total: 0.014016s
Total: 0.018392s
Total: 0.013031s
Total: 0.014198s
Total: 0.014009s

I’ll keep an eye on my setup (and will disable auto updates on the TV!), but I think we’ve determined that this issue was not due to bugs in the plugin. I will go ahead and close the issue, and — as usual, thank you for your willingness to help me troubleshoot this. I really appreciate it.

🙏🏽

dpamping commented 2 years ago

I have the same problem, the tv is on and then off in a cycle

dpamping commented 2 years ago

I have updated the tv today to the last version, it’s from 2020 and still same issue