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

Samsung TV integration (UE48JU6400/UE40H6600) #66029

Closed megasauro closed 2 years ago

megasauro commented 2 years ago

The problem

I followed the instructions for integrating my Samsung UE48JU6472 TV into Home Assistant, but the TV does not receive the request for pairing from HA, and therefore in fact there is no pairing and it does not receive commands. The pairing procedure on the TV works correctly, because I tested it on the Smartphone with an Android app (TV Remote) that simulates the Samsung remote control via IP, and requires pairing to work. I'm sure I'm doing something wrong, but I don't understand where.

What version of Home Assistant Core has the issue?

core-2022.2.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Samsung Smart TV

Link to integration documentation on our website

https://www.home-assistant.io/integrations/samsungtv

Diagnostics information

{ "home_assistant": { "installation_type": "Home Assistant OS", "version": "2022.2.3", "dev": false, "hassio": true, "virtualenv": false, "python_version": "3.9.7", "docker": true, "arch": "x86_64", "timezone": "Europe/Rome", "os_name": "Linux", "os_version": "5.10.91", "supervisor": "2022.01.1", "host_os": "Home Assistant OS 7.2", "docker_version": "20.10.9", "chassis": "vm", "run_as_root": true }, "custom_components": {}, "integration_manifest": { "domain": "samsungtv", "name": "Samsung Smart TV", "documentation": "https://www.home-assistant.io/integrations/samsungtv", "requirements": [ "getmac==0.8.2", "samsungctl[websocket]==0.7.1", "samsungtvws==1.6.0", "wakeonlan==2.0.1" ], "ssdp": [ { "st": "urn:samsung.com:device:RemoteControlReceiver:1" } ], "zeroconf": [ { "type": "_airplay._tcp.local.", "properties": { "manufacturer": "samsung" } } ], "dhcp": [ { "hostname": "tizen" }, { "macaddress": "8CC8CD" }, { "macaddress": "606BBD" }, { "macaddress": "F47B5E" }, { "macaddress": "4844F7" } ], "codeowners": [ "@escoand", "@chemelli74" ], "config_flow": true, "iot_class": "local_polling", "is_built_in": true }, "data": { "entry": { "entry_id": "280ed00d545ccff8a2b5c9afe8aec4c8", "version": 2, "domain": "samsungtv", "title": "UE48JU6472 (UE48JU6400)", "data": { "host": "192.168.70.190", "mac": "14:bb:6e:ff:89:90", "manufacturer": "Samsung Electronics", "method": "websocket", "model": "UE48JU6400", "name": "UE48JU6472", "port": 8002 }, "options": {}, "pref_disable_new_entities": false, "pref_disable_polling": false, "source": "ssdp", "unique_id": "d91609ab-3ae8-4d97-aa87-3470b44b4124", "disabled_by": null } } }

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

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

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


samsungtv documentation samsungtv source (message by IssueLinks)

megasauro commented 2 years ago

As additional info: both HA and TV have ETH wired connections and not WiFi, and both have static IPs

chemelli74 commented 2 years ago

Please add the following to configuration.yaml , restart HA, and post the log:

logger:
  default: warning
  logs:
    homeassistant.components.samsungtv: debug
    samsungtvws: debug
    samsungctl: debug

Note: it is better to drag the log into the comment (which will add it as an attachment) and not copy paste as it is hard to read logs in GitHub.

taiBsu commented 2 years ago

I'm having very much the same issue, here's my debug output @chemelli74 :

home-assistant    | 2022-02-08 19:57:25 DEBUG (SyncWorker_1) [samsungtvws.remote] Sending key KEY_VOLUP
home-assistant    | 2022-02-08 19:57:26 DEBUG (SyncWorker_6) [samsungtvws.remote] Connection closed.
home-assistant    | 2022-02-08 19:57:26 DEBUG (SyncWorker_6) [homeassistant.components.samsungtv] Create SamsungTVWSBridge for name (192.168.2.***)
home-assistant    | 2022-02-08 19:57:26 DEBUG (SyncWorker_6) [samsungtvws.remote] WS url ws://192.168.2.***:8001/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==
home-assistant    | 2022-02-08 19:57:35 DEBUG (SyncWorker_1) [samsungtvws.remote] Connection closed.
home-assistant    | 2022-02-08 19:57:35 DEBUG (SyncWorker_1) [homeassistant.components.samsungtv] Create SamsungTVWSBridge for name (192.168.2.***)
home-assistant    | 2022-02-08 19:57:35 DEBUG (SyncWorker_1) [samsungtvws.remote] WS url ws://192.168.2.***:8001/api/v2/channels/samsung.remote.control?name=SG9tZUFzc2lzdGFudA==
megasauro commented 2 years ago

Hi Simone, sorry for the late reply but this days I'm full of work. Here below my logs: HA_samsungTV_debug_log_Sauro.txt

megasauro commented 2 years ago

Ciao @chemelli74, did you have time to take a look at the debug log? Sorry if I bother you, but I am unable to control the TV from direct Samsung integration I also tried via a WiFi-to-IR controller (which is connected in WiFi and simulates the IR remote), but Tuya integration doesn't seem to support it (although on the Smart Life app it works).

I'm basically stuck

chemelli74 commented 2 years ago

Hi Simone, sorry for the late reply but this days I'm full of work. Here below my logs: HA_samsungTV_debug_log_Sauro.txt

I see in the log:

token=None

but is expected as pairing doesn't work,

I would suggest a test using directly the upstream library; I wrote a simple script (you need to update the ip in ip): https://pastebin.com/raw/sFzPJvMA

If you need help on this task, you can join HomeAssistant on Discord and then contact me: chemelli74#2180

Simone

epenet commented 2 years ago

Can you please check if the new patch release 2022.2.8 has improved the situation?

megasauro commented 2 years ago

I just installed the patch release 2022.2.8, I also deleted the integration and reinstalled it, but unfortunately the problem remains: HA is unable to forward the correct request for a pairing code to the TV. Therefore the TV does not receive it and therefore doesn't generate the new code and so doesn't pair

werehamster999 commented 2 years ago

Hi Folks, Here's another "me too" I'm afraid. On the upside, mine does appear to just be a simple case of misdetection. My TV only responds to the legacy /ms/v1 api but integration keeps selecting the more modern bridge and attempting to use that. The results are the same though, no request for a PIN and no control either.

Regards, Keith Diagnostics attached config_entry-samsungtv-c3a741dbeed8609abc3415e9f4a083f7.json.txt ssdp discovery.txt HA-Log.txt

epenet commented 2 years ago

@werehamster999 could you please provide a clean full log with the debug options enabled? 1 - enable debug 2 - remove all existing samsungtv integrations 3 - restart HA 4 - wait for discovery 5 - copy-paste the full log into a text file and drop it here

werehamster999 commented 2 years ago

@epenet All done :-)

epenet commented 2 years ago

@werehamster999 / @taiBsu Since you are connecting on port 8001 (no-SSL and no-pairing) I think you should open a separate request and not get it mixed up with the original issue from megasauro

epenet commented 2 years ago

@megasauro could you post a fresh HA log following the same steps? 1 - enable debug 2 - remove all existing samsungtv integrations 3 - restart HA 4 - wait for discovery 5 - copy-paste the full log into a text file and drop it here

epenet commented 2 years ago

I have also adjusted slightly the code from @chemelli74 Please try it like this:

from samsungtvws import SamsungTVWS
import logging

logging.basicConfig(level=logging.DEBUG)

tv = SamsungTVWS(host="192.168.0.14", port=8002)
info = tv.rest_device_info()
logging.info(info)
tv.send_key("KEY_VOLUP")
werehamster999 commented 2 years ago

@epenet - Thanks for your support. I've actually solved part of my problem. It looks like the TV itself had some sticky bits somewhere. Ports 8000,8001,8080,8443 have all suddenly now appeared again. I'm just going to do a few reboots and see what happens but I'm still not seeing responses to volume buttons nor has it prompted for authentication. A clean start might cure that though. Fingers crossed! Regards, Keith

megasauro commented 2 years ago

@epenet - first of all I enable debug and remove Samsung integration. Then I update HA to 2022.2.9, and HA restart. Wait for discovery and capture the diagnostic log here below: samsung UE48JU6472 - diagnostic log_2.txt

unfortunately the problem remains and I don't see anything new in the log

epenet commented 2 years ago

You are sending the diagnostics, but not the HA logs. Please post the full HomeAssistant logs from Configuration > Parameters > Logs

megasauro commented 2 years ago

sorry I didn't understand home-assistant.log

ooohaaa commented 2 years ago

Hi all, looks like I have the same issue.

@werehamster999 could you please provide a clean full log with the debug options enabled? 1 - enable debug 2 - remove all existing samsungtv integrations 3 - restart HA 4 - wait for discovery 5 - copy-paste the full log into a text file and drop it here

I followed the steps above - you can find my logs attached. My Version is: core-2022.2.9

HA-Core Log.txt config_entry-samsungtv-c80704e7b4f672d65728ab1c49e18169.json.txt

werehamster999 commented 2 years ago

Hi folks.

I thought I'd better add a comment for closure before I disappear off. :-)

The reboot didn't work so I did some more digging, wiresharked stuff etc. The problem is definately my end. Although the TV model isn't directly excluded in the samsungctl/samsungTVWS documentation, it appears to be a "new" version of an older H series model with a wierd multi-stage PIN negotiation that isn't covered.

I'm not too worried about getting my tv working so I won't put in a feature request :-). Both the H-series and J-series TV's have the same PIN api so there's a slight possibility that @megasauro and @ooohaaa might be being caught by the same issue. (If the the JU series is related to the J series etc)

Keith PS: If it's of any use Kevin Schlosser carried on building on Ape's samsungctl and eventually added support for the H and J series TVs. It's not on Pypi. https://github.com/kdschlosser/samsungctl

epenet commented 2 years ago

@werehamster999 The work by kdscholler is NOT available on pypi so it cannot be used in home assistant. All the code regarding websocket now goes through a separate dependency. In the next few days we will be updating that dependency to be fully async. Once that is done I plan to add more debugging it make it all easier to debug the remaining issues.

epenet commented 2 years ago

I have looked more in depth at this, and I am afraid @werehamster999 is right: H-series and J-series TV are not currently supported by the "legacy" bridge (samsungctl library), nor by the "websocket" bridge (samsungtvws library).

It should be possible to add a third bridge to handle this. I have found multiple implementations that are based on the work from https://github.com/eclair4151/SmartCrypto but none are available on pypi.

epenet commented 2 years ago

The dev branch has been updated today with quite a lot of fixes for SamsungTV. I don't expect any of it to fix your issue, but it would allow us to get more information about your model, and to maybe start work on a future implementation. Could you please try these steps and provide fresh logs?

image

epenet commented 2 years ago

If you wish to move forward on this, I invite you to join me on the PR/discussion https://github.com/epenet/home-assistant-core/pull/71

ooohaaa commented 2 years ago

Could you please try these steps and provide fresh logs?

Of course! Here are the logs - let me know if you neet more information!

config_entry-samsungtv-403f48e506ded119406a029cb6c419b2.json.txt HA-Core Log.txt

epenet commented 2 years ago

Those logs are surprising! They show that communication using the websocket API is working on UE48JU6400, but the app_list and key commands are not being accepted.

Anyway, let's carry on this discussion in https://github.com/epenet/home-assistant-core/pull/71

epenet commented 2 years ago

I have opened the core PR: https://github.com/home-assistant/core/pull/68301

Please test "in anger" now :)