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.32k stars 30.62k forks source link

SamsungTV doesn't add an entity #36901

Closed steve-gombos closed 3 years ago

steve-gombos commented 4 years ago

The problem

Disclaimer: Just got this TV today, so don't have any prior history of this working in Home Assistant. Integration: samsungtv Model: UN50TU8000 (not listed on the integration page) OS: Tizen

The samsungtv integration doesn't add any entities after setting up via the config flow. I input my IP address and name, click submit, then there is a notification on the TV. I hit allow on the Home Assistant TV notification and I get a success message:

success

After hitting finish, no entities are added, no more popup on the TV.

image

Environment

Problem-relevant configuration.yaml

Traceback/Error logs

Initial Configuration:

2020-06-18 00:09:58 DEBUG (SyncWorker_14) [homeassistant.components.samsungtv] Try config: {'name': 'HomeAssistant', 'description': 'HomeAssistant', 'id': 'ha.component.samsung', 'host': '192.168.1.219', 'method': 'legacy', 'port': None, 'timeout': 31}
2020-06-18 00:09:58 DEBUG (SyncWorker_14) [homeassistant.components.samsungtv] Failing config: {'name': 'HomeAssistant', 'description': 'HomeAssistant', 'id': 'ha.component.samsung', 'host': '192.168.1.219', 'method': 'legacy', 'port': None, 'timeout': 31}, error: [Errno 111] Connection refused
2020-06-18 00:09:58 DEBUG (SyncWorker_14) [homeassistant.components.samsungtv] Try config: {'name': 'HomeAssistant', 'host': '192.168.1.219', 'method': 'websocket', 'port': 8001, 'timeout': 31}
2020-06-18 00:09:58 DEBUG (SyncWorker_14) [samsungtvws.remote] WS url ws://192.168.1.219:8001/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==
2020-06-18 00:09:58 DEBUG (SyncWorker_14) [samsungtvws.remote] Connection closed.
2020-06-18 00:09:58 DEBUG (SyncWorker_14) [samsungtvws.remote] Connection closed.
2020-06-18 00:09:58 DEBUG (SyncWorker_14) [homeassistant.components.samsungtv] Failing config: {'name': 'HomeAssistant', 'host': '192.168.1.219', 'method': 'websocket', 'port': 8001, 'timeout': 31}, error: {'event': 'ms.channel.unauthorized'}
2020-06-18 00:09:58 DEBUG (SyncWorker_14) [homeassistant.components.samsungtv] Try config: {'name': 'HomeAssistant', 'host': '192.168.1.219', 'method': 'websocket', 'port': 8002, 'timeout': 31}
2020-06-18 00:09:58 DEBUG (SyncWorker_14) [samsungtvws.remote] WS url wss://192.168.1.219:8002/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==&token=None
2020-06-18 00:10:02 DEBUG (SyncWorker_14) [samsungtvws.remote] Got token 11907123
2020-06-18 00:10:02 INFO (SyncWorker_14) [samsungtvws.remote] New token 11907123
2020-06-18 00:10:02 DEBUG (SyncWorker_14) [samsungtvws.remote] Connection closed.
2020-06-18 00:10:02 DEBUG (SyncWorker_14) [homeassistant.components.samsungtv] Working config: {'name': 'HomeAssistant', 'host': '192.168.1.219', 'method': 'websocket', 'port': 8002, 'timeout': 31, 'token': '*****'}
2020-06-18 00:10:13 DEBUG (SyncWorker_9) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-06-18 00:10:13 DEBUG (SyncWorker_9) [samsungtvws.remote] WS url wss://192.168.1.219:8002/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==&token=11907123
2020-06-18 00:10:24 DEBUG (SyncWorker_16) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-06-18 00:10:24 DEBUG (SyncWorker_16) [samsungtvws.remote] WS url wss://192.168.1.219:8002/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==&token=11907123
2020-06-18 00:10:35 DEBUG (SyncWorker_13) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-06-18 00:10:35 DEBUG (SyncWorker_13) [samsungtvws.remote] WS url wss://192.168.1.219:8002/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==&token=11907123
2020-06-18 00:10:46 DEBUG (SyncWorker_15) [homeassistant.components.samsungtv] Create SamsungTVWS

After restart:

2020-06-18 11:53:33 DEBUG (SyncWorker_16) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-06-18 11:53:33 DEBUG (SyncWorker_16) [samsungtvws.remote] WS url wss://192.168.1.219:8002/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==&token=11907123
2020-06-18 11:53:43 DEBUG (SyncWorker_19) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-06-18 11:53:43 DEBUG (SyncWorker_19) [samsungtvws.remote] WS url wss://192.168.1.219:8002/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==&token=11907123
2020-06-18 11:53:54 DEBUG (SyncWorker_11) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-06-18 11:53:54 DEBUG (SyncWorker_11) [samsungtvws.remote] WS url wss://192.168.1.219:8002/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==&token=11907123
2020-06-18 11:54:05 DEBUG (SyncWorker_5) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-06-18 11:54:05 DEBUG (SyncWorker_5) [samsungtvws.remote] WS url wss://192.168.1.219:8002/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==&token=11907123
2020-06-18 11:54:16 DEBUG (SyncWorker_18) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-06-18 11:54:16 DEBUG (SyncWorker_18) [samsungtvws.remote] WS url wss://192.168.1.219:8002/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==&token=11907123
2020-06-18 11:54:27 DEBUG (SyncWorker_6) [homeassistant.components.samsungtv] Create SamsungTVWS

Additional information

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

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

escoand commented 4 years ago

I suppose you've added the TV manually, not by discovery, right? Then it should be visible after a restart of HA.

steve-gombos commented 4 years ago

I did add it manually since discovery wasn't picking it up. I have restarted a couple of times and still hasn't shown up.

escoand commented 4 years ago

OK, when you say it's a completely new TV it's maybe a matter of a new discovery protocol. Are you familiar with git and code checkout and able to test this PR? https://github.com/home-assistant/core/pull/35773

steve-gombos commented 4 years ago

Yeah, I will try this out later this evening.

steve-gombos commented 4 years ago

@escoand So I got the patch-1 branch from your repo setup on my dev environment. Discovery is finding the TV, but once it is added I am still not seeing any devices get added. I have restarted a few times. This is all I see in the logs.

2020-06-18 19:24:32 DEBUG (SyncWorker_0) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-06-18 19:24:32 DEBUG (SyncWorker_0) [samsungtvws.remote] WS url ws://192.168.1.219:8001/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==
2020-06-18 19:24:32 DEBUG (SyncWorker_0) [samsungtvws.remote] Connection closed.
2020-06-18 19:24:32 DEBUG (SyncWorker_0) [samsungtvws.remote] Get device info via rest api

I verified in fiddler I am able to hit the endpoint it looks like this is stopping at.

image

edit: Didn't check the HA UI log, but I do see this error:

Logger: homeassistant.components.media_player
Source: helpers/device_registry.py:133
Integration: Media player (documentation, issues)
First occurred: 10:34:19 PM (1 occurrences)
Last logged: 10:34:19 PM

Error while setting up samsungtv platform for media_player
Traceback (most recent call last):
  File "/mnt/c/src/HomeAssistant/escoand/home-assistant/homeassistant/helpers/entity_platform.py", line 186, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/mnt/c/src/HomeAssistant/escoand/home-assistant/homeassistant/helpers/entity_platform.py", line 295, in async_add_entities
    await asyncio.gather(*tasks)
  File "/mnt/c/src/HomeAssistant/escoand/home-assistant/homeassistant/helpers/entity_platform.py", line 362, in _async_add_entity
    device = device_registry.async_get_or_create(**processed_dev_info)
  File "/mnt/c/src/HomeAssistant/escoand/home-assistant/homeassistant/helpers/device_registry.py", line 131, in async_get_or_create
    connections = {
  File "/mnt/c/src/HomeAssistant/escoand/home-assistant/homeassistant/helpers/device_registry.py", line 133, in <setcomp>
    for key, value in connections
ValueError: too many values to unpack (expected 2)
escoand commented 4 years ago

Interesting, will check this.

steve-gombos commented 4 years ago

@escoand I will have a commit to your branch here in a little bit.

steve-gombos commented 4 years ago

@escoand Sent a PR to your branch since I couldn't commit to it directly. Made a fix for the connections in the media_player, this gets the device added to the UI. Device is always showing as off now.

escoand commented 4 years ago

Nice, thanks, one step further. My problem is, I don't own such a new TV.

Could you try to use samsungtvws directly? Is this able to show the state and control the device?

steve-gombos commented 4 years ago

http://{host}:8001/api/v2/ api endpoint is returning data. Sample:

{
    "device": {
        "FrameTVSupport": "false",
        "GamePadSupport": "true",
        "ImeSyncedSupport": "true",
        "Language": "en_US",
        "OS": "Tizen",
        "PowerState": "on",
        "TokenAuthSupport": "true",
        "VoiceSupport": "true",
        "WallScreenRatio": "0",
        "WallService": "false",
        "countryCode": "US",
        "description": "Samsung DTV RCR",
        "developerIP": "0.0.0.0",
        "developerMode": "0",
        "duid": "uuid:33ADA541-6483-4CC1-A5AD-9D2EEFE8B7C7",
        "firmwareVersion": "Unknown",
        "id": "uuid:33ADA541-6483-4CC1-A5AD-9D2EEFE8B7C7",
        "ip": "192.168.1.123",
        "model": "20_NIKEL_UHD_BASIC",
        "modelName": "UN50TU8000FXZA",
        "name": "[TV] Samsung 8 Series",
        "networkType": "wireless",
        "resolution": "3840x2160",
        "smartHubAgreement": "true",
        "ssid": "12:34:56:78:90:12",
        "type": "Samsung SmartTV",
        "udn": "uuid:33ADA541-6483-4CC1-A5AD-9D2EEFE8B7C7",
        "wifiMac": "12:34:56:12:34:56"
    },
    "id": "uuid:33ADA541-6483-4CC1-A5AD-9D2EEFE8B7C7",
    "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 8 Series",
    "remote": "1.0",
    "type": "Samsung SmartTV",
    "uri": "http://192.168.1.123:8001/api/v2/",
    "version": "2.0.25"
}

Functions I tested/verified (checked) against samsungtvws directly:

I will do some more research tomorrow, since I didn't try anything with sources or buttons.

escoand commented 4 years ago

Uhhh, there is a property ​"​PowerState​"​: ​"​on​"​. Is this API endpoint also request-able when switched off? And is there a way to switch it on with samsungtvws (without wake-on-lan)?

steve-gombos commented 4 years ago

No the endpoint is not available. I have only gotten it to turn on with wakeonlan, I tried just using the power toggle in the samsungtvws library, but didn't do anything to power it on.

steve-gombos commented 4 years ago

So I am talking a look at this again tonight. Seems like this isn't setting up the remote right. A WebSocketException is being thrown here: https://github.com/escoand/home-assistant/blob/200754217418f7ef3365d218ca2b461e4578d718/homeassistant/components/samsungtv/bridge.py#L281

steve-gombos commented 4 years ago

I just sent another PR to your repo. It increases the timeout in the _get_remote method. This seems to resolve most of the issues I was having. I will do some more testing tomorrow.

escoand commented 4 years ago

Thanks. A timeout of 5 seconds on a local network seems quite much. I wouldn't even on the internet expect that much. Probably the TV device is responding too slow.

escoand commented 4 years ago

I think I've merged too fast, some tests will fail because of the changed values...

steve-gombos commented 4 years ago

@escoand Sorry about that. I did some more testing with the time out. 1 second just isn't enough and closes before receiving anything from the WS. The minium I have gotten this to work with is 2 seconds. So we can leave it 5 or reduce to 2 potentially.

arsaboo commented 4 years ago

Wondering if what I am seeing is the same issue. I keep seeing the Allow prompt on the TV continuously and even after allowing it the TV entity is not being created: image

Here are the logs (the initial failures were probably due to the time it took to me to allow on the TV):

2020-08-05 09:14:52 DEBUG (SyncWorker_6) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:15:00 DEBUG (SyncWorker_6) [homeassistant.components.samsungtv] Access denied in getting remote object
2020-08-05 09:15:02 DEBUG (SyncWorker_18) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:15:22 DEBUG (SyncWorker_14) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:15:42 DEBUG (SyncWorker_32) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:15:52 DEBUG (SyncWorker_38) [homeassistant.components.samsungtv] Try config: {'name': 'HomeAssistant', 'description': 'HomeAssistant', 'id': 'ha.component.samsung', 'host': '192.168.2.252', 'method': 'legacy', 'port': None, 'timeout': 31}
2020-08-05 09:15:52 DEBUG (SyncWorker_38) [homeassistant.components.samsungtv] Failing config: {'name': 'HomeAssistant', 'description': 'HomeAssistant', 'id': 'ha.component.samsung', 'host': '192.168.2.252', 'method': 'legacy', 'port': None, 'timeout': 31}, error: [Errno 111] Connection refused
2020-08-05 09:15:52 DEBUG (SyncWorker_38) [homeassistant.components.samsungtv] Try config: {'name': 'HomeAssistant', 'host': '192.168.2.252', 'method': 'websocket', 'port': 8001, 'timeout': 31}
2020-08-05 09:15:55 DEBUG (SyncWorker_38) [homeassistant.components.samsungtv] Failing config: {'name': 'HomeAssistant', 'host': '192.168.2.252', 'method': 'websocket', 'port': 8001, 'timeout': 31}, error: {'event': 'ms.channel.unauthorized'}
2020-08-05 09:15:55 DEBUG (SyncWorker_38) [homeassistant.components.samsungtv] Try config: {'name': 'HomeAssistant', 'host': '192.168.2.252', 'method': 'websocket', 'port': 8002, 'timeout': 31}
2020-08-05 09:16:02 DEBUG (SyncWorker_38) [homeassistant.components.samsungtv] Working config: {'name': 'HomeAssistant', 'host': '192.168.2.252', 'method': 'websocket', 'port': 8002, 'timeout': 31, 'token': '*****'}
2020-08-05 09:16:02 DEBUG (SyncWorker_12) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:16:12 DEBUG (SyncWorker_16) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:16:15 DEBUG (SyncWorker_32) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:16:22 DEBUG (SyncWorker_5) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:16:25 DEBUG (SyncWorker_30) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:16:32 DEBUG (SyncWorker_22) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:16:34 DEBUG (SyncWorker_33) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:16:42 DEBUG (SyncWorker_39) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:16:44 DEBUG (SyncWorker_36) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:16:52 DEBUG (SyncWorker_5) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:16:54 DEBUG (SyncWorker_13) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:17:02 DEBUG (SyncWorker_1) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:17:04 DEBUG (SyncWorker_7) [homeassistant.components.samsungtv] Create SamsungTVWS
2020-08-05 09:17:12 DEBUG (SyncWorker_31) [homeassistant.components.samsungtv] Create SamsungTVWS

The Create SamsungTVWS just keeps repeating.

steve-gombos commented 4 years ago

@arsaboo This is the same issue I was having. The linked PR here has resolved the issues for me, it just needs to be code reviewed/merged. You can probably try pulling it down and running it to verify if you are seeing the same. https://github.com/home-assistant/core/pull/35773

github-actions[bot] commented 3 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.