Samsung Smart TV - No control?

thank you for that . I was always told it was 8001 because i could access the api via a browser

it seems to work yet this error keeps appearing

2019-10-21 19:37:05 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 273, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 314, in _async_write_ha_state
    attr.update(self.state_attributes or {})
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 832, in state_attributes
    for attr in ATTR_TO_PROPERTY
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 833, in <dictcomp>
    if getattr(self, attr) is not None
  File "/config/custom_components/samsungtv_custom/media_player.py", line 304, in source_list
    self._gen_installed_app_list()
  File "/config/custom_components/samsungtv_custom/media_player.py", line 219, in _gen_installed_app_list
    app_list = self._remote.app_list()
  File "/usr/local/lib/python3.7/site-packages/samsungtvws/remote.py", line 175, in app_list
    self._ws_send(payload)
  File "/usr/local/lib/python3.7/site-packages/samsungtvws/remote.py", line 91, in _ws_send
    self.connection.send(payload)
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 250, in send
    return self.send_frame(frame)
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 275, in send_frame
    l = self._send(data)
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 445, in _send
    return send(self.sock, data)
  File "/usr/local/lib/python3.7/site-packages/websocket/_socket.py", line 117, in send
    return sock.send(data)
  File "/usr/local/lib/python3.7/ssl.py", line 1003, in send
    return self._sslobj.write(data)
BrokenPipeError: [Errno 32] Broken pipe
2019-10-21 19:37:22 WARNING (MainThread) [homeassistant.helpers.entity] Updating state for media_player.samsung_tv (<class 'custom_components.samsungtv_custom.media_player.SamsungTVDevice'>) took 2.734 seconds. Please report platform to the developers at https://goo.gl/Nvioub

Without a scan with Nmap I can not help you

here you go

i appreciate the help

Starting Nmap 7.80 ( https://nmap.org ) at 2019-10-21 20:58 GMT Summer Time

NSE: Loaded 151 scripts for scanning.

NSE: Script Pre-scanning.

Initiating NSE at 20:58

Completed NSE at 20:58, 0.02s elapsed

Initiating NSE at 20:58

Completed NSE at 20:58, 0.00s elapsed

Initiating NSE at 20:58

Completed NSE at 20:58, 0.00s elapsed

Initiating ARP Ping Scan at 20:58

Scanning 10.0.0.39 [1 port]

Completed ARP Ping Scan at 20:58, 0.11s elapsed (1 total hosts)

Initiating Parallel DNS resolution of 1 host. at 20:58

Completed Parallel DNS resolution of 1 host. at 20:59, 11.05s elapsed

Initiating SYN Stealth Scan at 20:59

Scanning 10.0.0.39 [1000 ports]

Discovered open port 8080/tcp on 10.0.0.39

Discovered open port 8002/tcp on 10.0.0.39

Discovered open port 32770/tcp on 10.0.0.39

Discovered open port 7676/tcp on 10.0.0.39

Discovered open port 32769/tcp on 10.0.0.39

Discovered open port 32771/tcp on 10.0.0.39

Discovered open port 32768/tcp on 10.0.0.39

Discovered open port 8001/tcp on 10.0.0.39

Completed SYN Stealth Scan at 20:59, 0.33s elapsed (1000 total ports)

Initiating Service scan at 20:59

Scanning 8 services on 10.0.0.39

Completed Service scan at 20:59, 25.12s elapsed (8 services on 1 host)

Initiating OS detection (try #1) against 10.0.0.39

NSE: Script scanning 10.0.0.39.

Initiating NSE at 20:59

Completed NSE at 20:59, 0.27s elapsed

Initiating NSE at 20:59

Completed NSE at 20:59, 0.19s elapsed

Initiating NSE at 20:59

Completed NSE at 20:59, 0.00s elapsed

Nmap scan report for 10.0.0.39

Host is up (0.000034s latency).

Not shown: 992 closed ports

PORT      STATE SERVICE         VERSION

7676/tcp  open  upnp            Samsung AllShare upnpd 1.0 (UPnP 1.1)

8001/tcp  open  nagios-nsca     Nagios NSCA

8002/tcp  open  ssl/nagios-nsca Nagios NSCA

| ssl-cert: Subject: commonName=SmartViewSDK/organizationName=SmartViewSDK/countryName=KR

| Subject Alternative Name: IP Address:127.0.0.1

| Issuer: commonName=SmartViewSDK Root Ceritificate Authority/organizationName=SmartViewSDK/countryName=KR

| Public Key type: rsa

| Public Key bits: 2048

| Signature Algorithm: sha256WithRSAEncryption

| Not valid before: 2016-09-21T08:36:31

| Not valid after:  2036-09-21T08:36:31

| MD5:   63a6 649e c484 50bc 61e5 de02 1702 1064

|_SHA-1: 2d48 b837 dabe a9e6 7588 ecd8 b809 3529 5656 d10c

|_ssl-date: TLS randomness does not represent time

8080/tcp  open  http            lighttpd

| http-methods: 

|_  Supported Methods: OPTIONS GET HEAD POST

|_http-server-header: WebServer

|_http-title: 404 - Not Found

32768/tcp open  nagios-nsca     Nagios NSCA

32769/tcp open  nagios-nsca     Nagios NSCA

32770/tcp open  nagios-nsca     Nagios NSCA

32771/tcp open  nagios-nsca     Nagios NSCA

MAC Address: my mac address (Samsung Electronics)

Device type: general purpose

Running: Linux 3.X|4.X

OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4

OS details: Linux 3.2 - 4.9

Uptime guess: 0.025 days (since Mon Oct 21 20:22:56 2019)

Network Distance: 1 hop

TCP Sequence Prediction: Difficulty=257 (Good luck!)

IP ID Sequence Generation: All zeros



TRACEROUTE

HOP RTT     ADDRESS

1   0.03 ms 10.0.0.39



NSE: Script Post-scanning.

Initiating NSE at 20:59

Completed NSE at 20:59, 0.00s elapsed

Initiating NSE at 20:59

Completed NSE at 20:59, 0.00s elapsed

Initiating NSE at 20:59

Completed NSE at 20:59, 0.00s elapsed

Read data files from: C:\Program Files (x86)\Nmap

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .

Nmap done: 1 IP address (1 host up) scanned in 41.90 seconds

           Raw packets sent: 1023 (45.806KB) | Rcvd: 1020 (41.590KB)

paste here this response: https://YOUR TV IP:8002/api/v2/

{"device":{"FrameTVSupport":"false","GamePadSupport":"true","ImeSyncedSupport":"true","OS":"Tizen","TokenAuthSupport":"true","VoiceSupport":"false","countryCode":"GB","description":"Samsung DTV RCR","developerIP":"0.0.0.0","developerMode":"0","duid":"uuid:20dc570e-d031-4afa-bcc9-84f520a9ccc3","firmwareVersion":"Unknown","id":"uuid:20dc570e-d031-4afa-bcc9-84f520a9ccc3","ip":"10.0.0.39","model":"17_KANTM_UHD_BASIC","modelName":"UE55MU6120","name":"[TV]Spare Room samsung","networkType":"wireless","resolution":"3840x2160","smartHubAgreement":"true","ssid":"38:94:ed:bd:06:60","type":"Samsung SmartTV","udn":"uuid:20dc570e-d031-4afa-bcc9-84f520a9ccc3","wifiMac":"mymac address"},"id":"uuid:20dc570e-d031-4afa-bcc9-84f520a9ccc3","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":"[TV]Spare Room samsung","remote":"1.0","type":"Samsung SmartTV","uri":"https://10.0.0.39:8002/api/v2/","version":"2.0.25"}

{
“device”:{

“TokenAuthSupport”:“true”, <-- Your connection port is 8002

“networkType”:“wireless”, <-- This network type dont support wakeonlan (WOL) then HA can’t turn it on

},

}

Maybe you also have to clean Device List: Settings/general/external device manager/device connection manager

1 Like

I’ve rebooted a few times now and the error seems to have gone away.

I’ve noticed it doesnt seem to pick up the sources If you restart HA with the tv off, I only see tv and hdmi. They all appear if left on

Also one more thing (sorry for being a pest)

I see all sources expect my two connected hdmi’s I tried

tv_channel_hdmi:
  alias: Channel hdmi1
  sequence:
  - service: media_player.play_media
    data:
      entity_id: media_player.samsung_tv
      media_content_id: KEY_HDMI1
      media_content_type: "send_key"

But nothing happened.

The “change source” keys don’t seem to work well on Tizen TVs.
To really advance it I would need a dump of the TV file system to see samsung.remote.control and other system apps binaries

@xchwarze thanks will test after work today and let you know.

If its possible for a dump of the tv file system let me know how and i can do this for you. Would be handy if it worked HDMI 1 or 2 rather than just toggle, If not its ok.

This looks great! Any plans to integrate this into an HA release?

Maybe HA need to split the component into:
Legacy (=>2015 tv)
Tizen(2015-Today)

That might be the right approach, and there is a precedent with Pioneer and Onkyo, where the former component only works for older pioneer models, and the latter works for the newer ones.
The main question, I guess, is whether you have the motivation to integrate this into Home Assistant. I’m more than happy to try to help, but eventually you know your component best.

I think i dont have time to do all the unit test needed for make the PR
Anyway, I’m still working on this. I have some ideas that I want to try

I like the approach that @roberodin is taking by including a config option for protocol. We can have multiple options there that can take care of the different options. It will be great if that branch can be bought up to speed with the latest fixes in the @xchwarze branch.

Most televisions are Tizen, so I don’t think is a good idea to mix the components

Samsung TV SDK (4.x - 5.x)—> Legacy https://github.com/Ape/samsungctl/
Samsung Tizen (beta - 1.0) —> Broken?
Samsung Tizen (2.0 to present) —> WS (API V2) https://github.com/xchwarze/samsung-tv-ws-api

installed latest version and works good so far on cable.,has held the state as well.

Thanks again!

I can help with tests.
Also, there’s other work being done, maybe you can integrate your changes into that?


Hi,
I am trying to integrate my samsung UE55NU8002 and get “Failed to call service media_player/turn_off. timed out”. I tried 8001 port and 8002 but without lack on both components: samsungtv and samsungtv_custom
NMAP shows:

Discovered open port 8080/tcp on 192.168.3.153
Discovered open port 8001/tcp on 192.168.3.153
Discovered open port 32769/tcp on 192.168.3.153
Discovered open port 32768/tcp on 192.168.3.153
Discovered open port 8002/tcp on 192.168.3.153
Discovered open port 9080/tcp on 192.168.3.153

HA logs:


2019-10-27 20:52:38 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.samsung_tv_remote fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/websocket/_socket.py", line 81, in recv
    bytes_ = sock.recv(bufsize)
socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 261, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 441, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/samsungtv/media_player.py", line 151, in update
    self.send_key("KEY")
  File "/usr/src/homeassistant/homeassistant/components/samsungtv/media_player.py", line 171, in send_key
    self.get_remote().control(key)
  File "/usr/src/homeassistant/homeassistant/components/samsungtv/media_player.py", line 157, in get_remote
    self._remote = self._remote_class(self._config)
  File "/usr/local/lib/python3.7/site-packages/samsungctl/remote.py", line 11, in __init__
    self.remote = RemoteWebsocket(config)
  File "/usr/local/lib/python3.7/site-packages/samsungctl/remote_websocket.py", line 28, in __init__
    self.connection = websocket.create_connection(url, config["timeout"])
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 511, in create_connection
    websock.connect(url, **options)
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 223, in connect
    self.handshake_response = handshake(self.sock, *addrs, **options)
  File "/usr/local/lib/python3.7/site-packages/websocket/_handshake.py", line 79, in handshake
    status, resp = _get_resp_headers(sock)
  File "/usr/local/lib/python3.7/site-packages/websocket/_handshake.py", line 150, in _get_resp_headers
    status, resp_headers, status_message = read_headers(sock)
  File "/usr/local/lib/python3.7/site-packages/websocket/_http.py", line 298, in read_headers
    line = recv_line(sock)
  File "/usr/local/lib/python3.7/site-packages/websocket/_socket.py", line 102, in recv_line
    c = recv(sock, 1)
  File "/usr/local/lib/python3.7/site-packages/websocket/_socket.py", line 84, in recv
    raise WebSocketTimeoutException(message)
websocket._exceptions.WebSocketTimeoutException: timed out

I even tried to manually create file:
image

I found error in HA
image

Any suggestion what can be wrong?

What other files are in your samsungtv_custom folder? you should have:

media_player.py
_ init _.py (without the spaces)
manifest.json

Looking at the LS command you ran on the folder, It looks as if there are only 2 files there. If it cant detect the “manifest.json” it wont know which requirements is needed for the component to work

"requirements": [
    "samsungtvws[websocket-client]==1.1.3", //this seems to be what your missing? 
    "wakeonlan==1.1.6"
  ],

Hi pegatron89
I have
image
image
Maybe I should mentio that I use docker version for HA