Improving Samsung TV Control

@jaruba
In my custom_component folder once the connexion with the TV is created there is an additional file : token-a.b.c.d.txt where a.b.c.d is the fixed IP address of the TV.
All good.
However, when I restart Home Assistant, the connexion to the TV won’t be reestablished until I delete that file which is then created again.
Is that normal?
Do you have the same behaviour?
Thanks,
GV

@greengolfer I can’t say I’ve experienced this, but I just came back from a 7 day trip, and have made some changes to the component before leaving.

I’ll make some tests in the next few days to see if I can reproduce this behavior.

Thanks for the quick answer.
I don’t yet use the “tizen” version but the one that was available early February.
What is the use of the (empty) token file?
GV

I just use the ESPHome which has IR connected, controls all the TVs :slight_smile: However, for various options, like changing sources, you need to exactly run the IR commands in sequence just like you would be pressing on Remote. But once you have setup, it works beautifully.

I am testing out the new HACS SamsungTV Tizen Component and it’s pretty buggy for me:

  • Source only works for “HDMI” and Apps (Google Assistant works for both of these as well)

  • Google Assistant doesn’t change change volume (up/down/mute) (UI works though)

  • If I configure the api_key and device_id, I get these errors in my log and I assume the SmartThings API inegration is not working then:

2020-02-23 13:58:38 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.samsung_tv_remote 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 "/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_tizen/media_player.py", line 260, in update
    smartthings.device_update(self)
    data = resp.json()
  File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 897, in json
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
2020-02-23 13:58:48 INFO (SyncWorker_11) [root] Sending key KEY
2020-02-23 13:58:48 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.samsung_tv_remote 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 "/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
  File "/config/custom_components/samsungtv_tizen/media_player.py", line 260, in update
    smartthings.device_update(self)
  File "/config/custom_components/samsungtv_tizen/smartthings.py", line 37, in device_update
    data = resp.json()
  File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.7/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python3.7/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
2020-02-23 13:58:59 INFO (SyncWorker_17) [root] Sending key KEY
2020-02-23 13:58:59 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.samsung_tv_remote 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)
2020-02-23 13:59:10 INFO (SyncWorker_10) [root] Sending key KEY
2020-02-23 13:59:10 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.samsung_tv_remote 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 "/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_tizen/media_player.py", line 260, in update
    smartthings.device_update(self)
  File "/config/custom_components/samsungtv_tizen/smartthings.py", line 37, in device_update
    data = resp.json()
  File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.7/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python3.7/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
2020-02-23 13:59:21 INFO (SyncWorker_3) [root] Sending key KEY
2020-02-23 13:59:21 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.samsung_tv_remote 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)
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.7/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python3.7/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Details on my 2016 Samsung TV (Tizen) are below:

{
"id": "<REDACTED>",
"name": "[TV] Living Room TV",
"version": "2.1.0",
"device": {
"type": "Samsung SmartTV",
"duid": "<REDACTED>",
"model": "16_JAZZL_UHD_BASIC",
"modelName": "UN55KU6290",
"description": "Samsung DTV RCR",
"networkType": "wireless",
"ssid": "<REDACTED>",
"ip": "<REDACTED>",
"firmwareVersion": "Unknown",
"name": "[TV] Living Room TV",
"id": "<REDACTED>",
"udn": "<REDACTED>",
"resolution": "3840x2160",
"countryCode": "US",
"msfVersion": "2.1.0",
"smartHubAgreement": "true",
"VoiceSupport": "false",
"GamePadSupport": "true",
"wifiMac": "<REDACTED>",
"developerMode": "1",
"developerIP": "...",
"OS": "Tizen"
},
"type": "Samsung SmartTV",
"uri": "http://<REDACTED>:8001/api/v2/",
"remote": "1.0",
"isSupport": "{\"remote_available\":\"true\",\"remote_fourDirections\":\"true\",\"remote_touchPad\":\"true\",\"remote_voiceControl\":\"false\",\"DMP_available\":\"true\",\"DMP_DRM_PLAYREADY\":\"false\",\"DMP_DRM_WIDEVINE\":\"false\",\"EDEN_available\":\"true\"}"
}

And for the SmartThings API setup, I do in fact have an API key and added my TV to the “Devices” but one things that could be of an issue is that I see it stated as “INACTIVE” and I had to get the device_id from the URI, doesn’t get listed in the device info:

So the SmartThings API issue was due to the API key, something must have changed over time to not allow me to use my existing key so I added a new one and I no longer have these errors.

However, plenty of issues still with this component, wish Google Assistant worked 100% with all of the functionality in the HA UI, still can’t get any of the audio commands working via Google Assistant and I also discovered that the source cannot be changed back to HDMI once in an app, it can only jump from app to app.

@greengolfer

I don’t yet use the “tizen” version but the one that was available early February.

I do not offer support for old versions of my component. Please update to the latest version if you wish to be assisted.

@manju-rn

I just use the ESPHome which has IR connected, controls all the TVs

I fail to see how this is in any way relevant to this discussion… IR blasters are a one way street, this component offers 1000x more features then just sending IR codes to a TV…

@nmajin

Source only works for “HDMI” and Apps (Google Assistant works for both of these as well)

You said you fixed the SmartThings API feature (which was due to an invalid token), so use the SmartThing Key Codes: ST_TV , ST_HDMI1 , ST_HDMI2 , ST_HDMI3 , etc.

Google Assistant doesn’t change change volume (up/down/mute) (UI works though)

Try saying “ok google, sync my devices”, then try the voice commands again. Do this 2-3 times to ensure it’s not a HA / Google Home sync issue that is causing this. I sometimes need to sync them a few times to get all TV features working for some reason.

Hi @jaruba,

I have installed your custom component to try to control HW-Q80R Soundbar. It’s running Tizen 4.1.10 and has support for Smartthings. After defining an empty app_list (app_list: '{}') it has finally appeared in HA, but I am not able to control it. All I can do is see current volume (but not control it) and turn soundbar off.

Are there any chances for a wider support?

@3_14

This is a component for Samsung TVs that use Tizen, it uses the WS API, UPnP and SmartThings. It sounds like the only thing that your Soundbar supports from this stack is SmartThings.

The SmartThings integration is not used everywhere, as in many scenarios the local APIs will be much faster then the cloud API.

Also, the SmartThings API integration of this component is based off of the work of a contributor of this component, you can find his own component that is fully SmartThings linked in this comment:

It should work better for ur case.

I was hoping that it will be possible locally. Thank you for your suggestion, I will check it out

@jaruba

Thanks for the respons. So I did find that the ST_TV, ST_HDMI1/2/3 does in fact do the trick, which is awesome.

However, for the audio control via Google Assistant, I cannot get this working at all. I’ve tried syncing my devices multiple times and I know the sync works since I update my devices constantly with testing and adding new devices to Google Home. See my note about Volume Down and the exception I get for that, something doesn’t seem right with the audio controls:

I have checked repo suggested by @jaruba, it was not fully working with a soundbar, as it expected some TV-oriented values, so I have created a fork where I have removed incompatible stuff:

1 Like

Great work, thanks for the effort! :slight_smile: works perfectly on my Q8FN!

I’ve released a new version that should fix a few common issues that users have had with the new SmartThings features.

Can you please explain the difference between the two? Technically they’re the same?

broadcast_address:
host:

@msmits2011 they are not the same, the “broadcast_address” is for specifying the subnet for the wakeonlan feature, it is only useful if the TV is on a different subnet then HA is, you can read more about that in this ticket:

1 Like

I am using this component instead of the built in one, which doesn’t appear to support my tv. However it seems to be very slow to detect the TV has been turned off. I have tried all three settings and they are all the same.
The TV is hard wired in to the network rather than wireless.
The current record is over an hour between the tv being turned off and HA being updated and therefore triggering other automations. 30 minutes or more is most common.
Any suggestions?

@scriven33 That seems highly irregular, have u updated this component to the latest release? with the default “ping” method, I always get the turn off state in 15 seconds. Have you also tried update_method: "websockets"? Although “ping” should be better… if all else fails u can even try the “smartthings” method, but I really hate this update method the most…

Yes, it is on the latest build. It was on a manual install, but I switched it across to HACS last night to see whether it improved matters - which updated the build to the latest. Been through all of the different settings, the last being the Smartthings method (which is the one that generated the hour between actual switch off and HA update).

@scriven33 I think your best bet is by removing update_method from your config completely and just trusting the default “ping” method.