Improving Samsung TV Control

@jaruba sometimes when TV is turned off it stays on in HA even though source is being reset. My TV is SAMSUNG UE65MU6172. Do You know the problem?

My config:

media_player:
  - platform: samsungtv_custom
    name: "[TV] Salon"
    host: 192.168.1.23
    port: 8002
    mac: !secret samsung_tv_mac
    app_list: '{"Netflix": "11101200001", "YouTube": "111299001912"}'

Is it @ steadi problem? update_method: ping shpuld fix it?

@majkers try it, then you can tell me if it helped or not. :slight_smile:

@jaruba testing from yesterday and for now on it is working but have to do some tests with turning off frm HA. Although some delay noticed…

@majkers There will always be a delay, but that’s not necessarily a bug. Try turning your tv off and on again after just a few seconds, the reason it “starts” so fast is because it was never off in the first place.

All Samsung TVs seem to offer a sort of “grace period” after you turn them off, in which time the TV is not actually off, only the screen is off in this time, so turning it back on from this state is almost instant.

This was probably added for cases in which u turned the TV off by mistake and want to turn it on again fast to not miss scenes from what you were watching…

@majkers Taking into account this (let’s call it) “wait state”, I think that the correct way of using it is to turn off the TV twice. Because the first “turn off” will send the TV to the usual “wait state”, and the second “turn off” command will force it to actually turn off from that state.

Otherwise, when using “turn off” only once, you would need to wait for the “wait state” to time out too, and it will turn off by itself.

@jaruba thanks for response. Taking it into account. Do You know how long is this “grace period” in upadte method ping and default. Maybe I was just impatient? :slight_smile:

@majkers That’s hard to say, but I do think the ping update method may be more accurate. I could be wrong though.

I’m wanting to update the latest version of HA 104 but when I ran the checker I see this error

General Errors: - Platform error media_player.samsungtv_custom - No module named 'websocket'

How do I resolve this or should I ignore it

hi could someone please help, i updated to 104 and i keep getting the following error

2020-01-22 18:42:56 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 279, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 461, 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 "/config/custom_components/samsungtv_custom/media_player.py", line 198, in update
    self.send_key("KEY")
  File "/config/custom_components/samsungtv_custom/media_player.py", line 218, in send_key
    self.get_remote().control(key)
  File "/config/custom_components/samsungtv_custom/media_player.py", line 204, 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 94, in recv
    "Connection is already closed.")
websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.
pip3 install websocket-client

Or use the docker image

im using hassio
i cant do a pip install

I have the same error in the checker and is also using HassIO. Everything works fine though.

ive updated now but it now shows the above error every minute

Not sure, but I think it’s possible to retrieve a list apps and id’s. A while ago I found a script in one of the other libraries that did exactly that … but like always, couldn’t find the exact code anymore …

A quick search gave this:

    async getListOfApps() {
        return this.connectAndSend({
            method: 'ms.channel.emit',
            params: {
                event: 'ed.installedApp.get',
                to: 'host'
            }
        });
    }

    getApps() {
        return this._apps;
    }

Perhaps this helps?

@Tjeerd We’re already using the code you posted to get the app list, it’s used only if app_list is not set by users in the config.

But people asked how THEY can get the app list, not the component. The code you posted uses the WebSocket connection to get the app list, users can’t use the WebSocket API to get this data on their own, and there is no HTTP endpoint to get this same data either.

@jaruba Just wanted to say that this works perfectly! I’ve been wanting to start apps on my TV (Plex, Netflix, Disney+, etc) since forever and this makes it possible. The same for changing back to ‘TV’ which never worked, but with your chaining functionality it works great.

Is there a reason why this is not in core? Probably because it only supports 2016+ TV’s?

Also… why don’t you rename this component and add it to HACS? As you said, your version contains more functionaliteit than the two other repositories it is based upon.

@thmry I could push it to HACS, sure… but as you said, the supported TVs are limited. And this component still has limitations.

I’ve been looking into the idea of making a Samsung TV component based on the SmartThings Cloud API, this has A LOT more potential in terms of features.

That way, it would be possible to get data on what channel is currently watched on TV, even get the current input source (TV, HDMI Device)

There’s a discussion about this here:

1 Like

Unfortunately, after updated the latest hassio version, this component doesn’t work.
Edit: I cleaned Device List on TV and it works again. Thank you

Hi does anyone know if it’s possible to set the volume level via a script

Hit the script and the volume level sets to 8

@phairplay
service: media_player.volume_set
data:

{
  "entity_id": media_player.living_room_tv,
  "volume_level": 0.4
}

Change “entity_id” with your TV’s entity ID, “volume_level” can be anything from 0.0 to 1.0

2 Likes