home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.68k stars 30.81k forks source link

Samsung TV integration disconnects and repeat reauth on TV. Since 0.114 #41305

Closed pandabear41 closed 3 years ago

pandabear41 commented 4 years ago

The problem

I am connecting to a Samsung Smart TV for a while using HA. It works for 12-24 hours and then stops working. The TV keeps showing up with the allow/deny HomeAssistant access to the TV. I press accept every time, but it just pops up again after a few seconds. I had this same issue in 0.114 and 0.115. Versions 0.113 and before that worked fine with no issues at all. The only way to fix is remove integration from HA, restart HA twice, add the TV integration again, restart HA, and then press allow on TV.

Environment

Problem-relevant configuration.yaml

wake_on_lan:

samsungtv:
  - host: 192.168.15.10
    name: Living Room TV
    turn_on_action:
      - service: wake_on_lan.send_magic_packet
        data:
          mac: f8:3f:51:99:18:a5

Traceback/Error logs

HA Logs: (Not sure why it gets a new token and then doesn't use it, but might be part of the problem or unrelated)

2020-10-05 12:57:36 DEBUG (SyncWorker_28) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-10-05 12:57:36 DEBUG (SyncWorker_28) [samsungtvws.remote] WS url wss://192.168.15.10:8002/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==&token=46491441
2020-10-05 12:57:38 DEBUG (SyncWorker_28) [samsungtvws.remote] Connection closed.
2020-10-05 12:57:38 DEBUG (SyncWorker_28) [homeassistant.components.samsungtv] Access denied in getting remote object
2020-10-05 12:57:46 DEBUG (SyncWorker_36) [samsungtvws.remote] Connection closed.
2020-10-05 12:57:46 DEBUG (SyncWorker_36) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-10-05 12:57:46 DEBUG (SyncWorker_36) [samsungtvws.remote] WS url wss://192.168.15.10:8002/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==&token=46491441
2020-10-05 12:57:49 DEBUG (SyncWorker_36) [samsungtvws.remote] Got token 17306397
2020-10-05 12:57:49 INFO (SyncWorker_36) [samsungtvws.remote] New token 17306397
2020-10-05 12:57:56 DEBUG (SyncWorker_14) [samsungtvws.remote] Connection closed.
2020-10-05 12:57:56 DEBUG (SyncWorker_14) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-10-05 12:57:56 DEBUG (SyncWorker_14) [samsungtvws.remote] WS url wss://192.168.15.10:8002/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==&token=46491441
2020-10-05 12:58:03 DEBUG (SyncWorker_14) [samsungtvws.remote] Connection closed.
2020-10-05 12:58:03 DEBUG (SyncWorker_14) [homeassistant.components.samsungtv] Access denied in getting remote object

Listening to socket from TV: (You see clientConnect when I press the accept button, otherwise you see clientDisconnect repeated every few seconds)

< {"data":{"attributes":{"name":"SG9tZUFzc2lzdGFudA==","token":"46491441"},"connectTime":1601927875820,"deviceName":"SG9tZUFzc2lzdGFudA==","id":"fbe11d57-6785-45a0-be2a-1b97b7198081","isHost":false},"event":"ms.channel.clientConnect"}

< {"data":{"attributes":{"name":"SG9tZUFzc2lzdGFudA==","token":"46491441"},"connectTime":1601927875820,"deviceName":"SG9tZUFzc2lzdGFudA==","id":"fbe11d57-6785-45a0-be2a-1b97b7198081","isHost":false},"event":"ms.channel.clientDisconnect"}

< {"data":{"attributes":{"name":"SG9tZUFzc2lzdGFudA==","token":"46491441"},"connectTime":1601928875841,"deviceName":"SG9tZUFzc2lzdGFudA==","id":"57508fc8-9be8-457c-9734-b542afb5f21","isHost":false},"event":"ms.channel.clientDisconnect"}

< {"data":{"attributes":{"name":"SG9tZUFzc2lzdGFudA==","token":"46491441"},"connectTime":1601928906013,"deviceName":"SG9tZUFzc2lzdGFudA==","id":"e461ae91-928e-4463-81b7-535b4f46f7dd","isHost":false},"event":"ms.channel.clientDisconnect"}

TV information (2017 4k TV. Model:UN55MU650D):

{"device":{"FrameTVSupport":"false","GamePadSupport":"true","ImeSyncedSupport":"true","OS":"Tizen","TokenAuthSupport":"true","VoiceSupport":"true","countryCode":"US","description":"Samsung DTV RCR","developerIP":"0.0.0.0","developerMode":"0","duid":"uuid:8048012d-aaa0-4dee-9c32-dfdcea618906","firmwareVersion":"Unknown","id":"uuid:8048012d-aaa0-4dee-9c32-dfdcea618906","ip":"192.168.15.10","model":"17_KANTM_UHD_BASIC","modelName":"UN55MU650D","name":"[TV] Samsung 6 Series (55)","networkType":"wireless","resolution":"3840x2160","smartHubAgreement":"true","ssid":"e0:63:da:75:0f:94","type":"Samsung SmartTV","udn":"uuid:8048012d-aaa0-4dee-9c32-dfdcea618906","wifiMac":"F8:3F:51:99:18:A5"},"id":"uuid:8048012d-aaa0-4dee-9c32-dfdcea618906","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\":\"true\"}\n","name":"[TV] Samsung 6 Series (55)","remote":"1.0","type":"Samsung SmartTV","uri":"http://192.168.15.10:8001/api/v2/","version":"2.0.25"}

Additional information

Might be related to https://stackoverflow.com/questions/61137232/websockets-closing-unexpectedly as I can curl the API of the TV, but a simple python code using websockets doesn't work.

Running samsung-tv-ws-api using their sample code also works. Also use the Samsung Smart TV remote app and don't have any issues.

I can monitor and provide wireshark if needed.

probot-home-assistant[bot] commented 4 years ago

Hey there @escoand, mind taking a look at this issue as its been labeled with an integration (samsungtv) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

narcico commented 4 years ago

I've solved it unconfiguring the Samsung Integration in HA, and re-configuring it, by adding the TV again (if not autodiscovered). It asked me for a confirmation on the TV once and stopped repeating the same authorization message.

pandabear41 commented 4 years ago

I've solved it unconfiguring the Samsung Integration in HA, and re-configuring it, by adding the TV again (if not autodiscovered). It asked me for a confirmation on the TV once and stopped repeating the same authorization message.

How exactly do you unconfigure the integration and re-configure it? Do you clean up everything from DB? I remove yaml and delete integration using three-dot icon -> Delete on integration list page. Followed by a restart of HA (sometimes twice restart if everything isn't removed). Then add yaml it back in and press allow on TV. It fixes it for about a day until spamming me with re-auth prompts on TV again.

andersnp1 commented 4 years ago

I'm seeing the same issue with my Samsung TV. I have connected Home Assistant to the TV manually in the GUI, but using hostname. After about a week, Home Assistant will start to request permission every few seconds regardless of how fast I press accept. I too can fix it by removing the integration, restarting Home Assistant and adding it again, but after some days (usually a week's time) it will happen again. I have noticed, that it seems to always be preceeded by "Smart Device" requesting permission.

derme302 commented 4 years ago

I am having the same issue, but the difference for me is that it has been working fine for the last month or so and has only started happening today.

lajuffermans commented 4 years ago

Same issue here since I updated to 0.116.2

solid-pixel commented 4 years ago

same here, it's driving me insane!

escoand commented 3 years ago

Sorry guys, my private life is quite demanding at the moment. I wont have the time in the near future for long debugging and coding sessions. I could maybe review some code or give comments, but don't expect more.

So I would encourage everybody to look deeper into the code and try to find the fix. I was at the same point some time ago. There was a some kind of working samsungtv integration and I started to hack it.

solid-pixel commented 3 years ago

No worries man, thanks for what you've done!

As a fix, for me it helped to remove the integration via UI and set it up through configuration.yaml. no more prompts!

heinemml commented 3 years ago

HA notified me now for some time that I should configure my Samsung TV Integration. Ignoring that I already had it configured and still working. When I gave in to the configuration dialog I ended up in this Authorization loop.

From what I see I now have two entities representing the same TV. And they seem to take turns in which one is talking to the actual TV.

image

All their states (like On/Off, Muted) are changing independently. I have no knowledge on how the Samsung Protocol is working. To me it seems like there is some kind of auth mechanism involved that is leads to invalidate the others entities credentials triggering the Pop-Up on the TV over and over.

From that I'm wondering: why is the TV discovered again when it is already set-up and working? (That would also explain why it is not an issue when it is configured via the config).

8osman commented 3 years ago

It's exactly that, if you don't reconfigure it and just reboot HA it goes away, if you reconfigure then you have a second entity and they just start bouncing.

Linked to https://github.com/home-assistant/core/pull/35773 I think.

The author is no longer able to maintain the code.

I'm seeing lots of 2021-01-20 12:45:34 DEBUG (SyncWorker_3) [homeassistant.components.samsungtv] Create SamsungTVWS

darrylb83 commented 3 years ago

Just to add, I am interested in this, as I have the same problem which I listed in 45509.

Mariusthvdb commented 3 years ago

and I: https://github.com/home-assistant/core/issues/49288 ;-)

escoand commented 3 years ago

This is normally caused by a changing IP address and should be fixed with: #48022