Samsung Smart TV - No control?

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

Ok, I have found one thing. Pegatron89 you pointed me to pycache and I changed owner to my user for ha and now it generally works! Only “On” not work, “Off”, “Volume” works fine.
Mac adresss is correct one

  - platform: samsungtv_custom
    host: 192.168.3.153
    port: 8002
    mac: 70:2a:d5:98:3e:6b

hi how do i install the last version. where do i paste the downloaded files?

i have it working perfecty even WOL on wifi. just sources not working.

under config_folder/custom_components/samsungtv_custom

Getting same issue. Using Samsung UE55MU6400. Error in Home Assistant Log:

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

Running latest HA 0.101 on Docker (Synology).
Tried deleting “pycache” folder numerous times. Also installed latest release from: https://github.com/xchwarze/ha-samsungtv-custom/releases 1

Config in HA configuration.yaml as follows:

# Samsung TV UE55MU6400
media_player:
  - platform: samsungtv_custom    
    host: 192.168.*.*   
    port: 8002   
    mac: 9c:8c:6e:XX:XX:XX

Output from API:

{"device":{"FrameTVSupport":"false","GamePadSupport":"true","ImeSyncedSupport":"true","OS":"Tizen","TokenAuthSupport":"true","VoiceSupport":"true","countryCode":"IE","description":"Samsung DTV RCR","developerIP":"0.0.0.0","developerMode":"0","duid":"uuid:659a783e-234c-4d22-9adc-8adc96ae377d","firmwareVersion":"Unknown","id":"uuid:659a783e-234c-4d22-9adc-8adc96ae377d","ip":"192.168.*.**","model":"17_KANTM_UHD_BASIC","modelName":"UE55MU6400","name":"[TV] Samsung TV","networkType":"none","resolution":"3840x2160","smartHubAgreement":"true","type":"Samsung SmartTV","udn":"uuid:659a783e-234c-4d22-9adc-8adc96ae377d","wifiMac":"none"},"id":"uuid:659a783e-234c-4d22-9adc-8adc96ae377d","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 TV","remote":"1.0","type":"Samsung SmartTV","uri":"https://192.168.*.*:8002/api/v2/","version":"2.0.25"}

Any help greatly appreciated :smiley:

For what it is worth I have tried a KS7000 which will switch on… thats about as much as I can get out of it. I also have a Q6F which I’ve only managed to get to work with the fork of this code in

Hopefully it helps.

Has anyone managed to control the Ambient mode through HA? Would be nice to integrate that.

1 Like

I have the same error and i tried deleting “pycache” numerous times too and dont worked here.
My HA is running in Synology too.

1 Like

I had this problem too. Fixed by:

  1. Delete pycache folder
  2. Open terminal and type pip3 install samsungtvws
  3. Remove the ‘samsungtv_custom’ section from configuration.yaml and restart HA
  4. Add ‘samsungtv_custom’ section back into configuration.yaml
  5. Restart HA again

Cant get it working.

Latest HASS
Latest from https://github.com/roberodin/ha-samsungtv-custom

image
Listening on port 8001

TV: Samsung The Frame 55 inch

Can turn on, but nothing else…

Failed to call service media_player/turn_off. {‘event’: ‘ms.channel.unauthorized’}

Any tips?

EDIT:
some more ino…

I have changed to port 8002 now:

  • platform: samsungtv_custom
    host: 192.168.1.134
    port: 8002
    mac: 00:c3:f4:b1:b0:84
    sourcelist: ‘{“TV”: “KEY_TV”, “HDMI”: “KEY_HDMI”, “ONKYO”: “KEY_HDMI4”}’
    protocol: ctl_qled
    name: Samsung The Frame

But I cannot control it again. only turn on. What is strange: if I press on HA “the on button” here:
image
the accept dialog on the TV appears and I click “accept”
Bu nothing happens and I can continue to do that… click on, accept, on accept, etc…

1 Like

How do you do this for Docker?

Hi @Saggerus, I got your solution to work and I’m getting a bit further now. The following applies to Synology Docker users:

  1. Delete pycache folder
  2. Go into “Docker” in Synology". Go into your “Containers” and open up your Home Assistant Container. Go to the “Terminal” Menu tap and Choose the down arrow beside “Create” and choose “Launch with command”. Paste in “pip3 install samsungtvws” and press “OK”
  3. Remove the ‘samsungtv_custom’ section from configuration.yaml and restart HA
  4. Add ‘samsungtv_custom’ section back into configuration.yaml
  5. Restart HA again

I’m no longer getting the error

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

But i’m now getting the following error:

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 275, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 316, 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)
ConnectionResetError: [Errno 104] Connection reset by peer

Any help or suggestions as ever are greatly appreciated!

Hi, great component and working pretty well for me on my new Q70 and lets me switch between apps. I’m in Australia and we have a video app called “Stan”. Any way I can grab the code for that app somehow and modify the application.py so I can start it up?

While app switching works well, any of the other controls I try, on/off, play even volume etc pop up the “you must give permission” dialogue box on the TV but doesn’t seem to actually do anything?

Cheers