Samsung Smart TV - No control?

@xchwarze The latest update works a lot better. I will test more in the coming days.

hey @pegatron89

I am not on rpi I am using NUC running docker.

Its a shame none of the features of this custom component work for my TV.

@bachoo786 wifi dont support WOL. The only solution for this is a broadlink rm mini 3

@pegatron89 @arsaboo
Based on your feedback I made a new release

so for WOL i need to connect my tv to the internet via ethernet cable?

Unfortunately yes

1 Like

@xchwarze
hi im trying to install this but i get the following error

Platform error media_player.samsungtv_custom - No module named ‘samsungtvws’

i have a UE55MU6120
running on port 8001

am i doing something wrong

@phairplay

  1. Delete pycache folder
  2. Install last release from: https://github.com/xchwarze/ha-samsungtv-custom/releases
  3. Config example:
    platform: samsungtv_custom
    host: xxx.xxx.xxx.xxx
    mac: xx:xx:xx:xx:xx
    port: 8002

my port is 8001
is this only for tvs on 8001
i did what you suggested but im getting this error

2019-10-21 19:01:38 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)
ConnectionResetError: [Errno 104] Connection reset by peer
2019-10-21 19:01:49 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.samsung_tv fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 268, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 448, 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/util/__init__.py", line 240, in wrapper
    result = method(*args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 240, in wrapper
    result = method(*args, **kwargs)
  File "/config/custom_components/samsungtv_custom/media_player.py", line 236, in update
    self._ping_device()
  File "/config/custom_components/samsungtv_custom/media_player.py", line 216, in _ping_device
    self.send_command("KEY")
  File "/config/custom_components/samsungtv_custom/media_player.py", line 252, in send_command
    self._remote.send_key(payload)
  File "/usr/local/lib/python3.7/site-packages/samsungtvws/remote.py", line 136, in send_key
    self._ws_send(payload)
  File "/usr/local/lib/python3.7/site-packages/samsungtvws/remote.py", line 89, in _ws_send
    self.open()
  File "/usr/local/lib/python3.7/site-packages/samsungtvws/remote.py", line 107, in open
    response = json.loads(self.connection.recv())
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 310, in recv
    opcode, data = self.recv_data()
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 327, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 340, in recv_data_frame
    frame = self.recv_frame()
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 374, in recv_frame
    return self.frame_buffer.recv_frame()
  File "/usr/local/lib/python3.7/site-packages/websocket/_abnf.py", line 383, in recv_frame
    frame.validate(self.skip_utf8_validation)
  File "/usr/local/lib/python3.7/site-packages/websocket/_abnf.py", line 182, in validate
    raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.
2019-10-21 19:02:00 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)
ConnectionResetError: [Errno 104] Connection reset by peer

Download Nmap https://nmap.org/download.html and scan your TV
After that paste the scan result here

---- edit
Your TV is a ‎SmartTV Tizen 2017, the correct port should be 8002. You should also accept the pop up that appears on the TV

1 Like

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)