Improving Samsung TV Control

I’ve recently got into Home Assistant, and couldn’t find a good custom component that would control my Samsung TV (Tizen) very well.

I was using xchwarze/ha-samsungtv-custom, it seemed to be the fastest but had some issues with it:

  • couldn’t find any key values that would change my TV sources
  • only worked to turn on / off TV with the assistant voice commands
  • couldn’t change volume with assistant voice commands

So I made my own fork of this repo that can be found here:
jaruba/ha-samsungtv-custom

How does this fork fix the issues I’ve been having with the other component?

Well, for one, it allows chaining key commands, so instead of source_list: '{"TV": "KEY_TV"}' (which never worked for me), I now do source_list: '{"TV": "KEY_SOURCE+KEY_LEFT+KEY_LEFT+KEY_ENTER"}' to auto-navigate the menu and select the TV source.

My fork also adds extended volume support, so there’s a bar that can be used in Home Assistant now to change the volume to a % value, instead of just volume up / down buttons.

I’ve also added Voice Assistant support (only tested with Google Home) that currently supports:

  • turn on / off
  • volume up / down
  • mute
  • set volume to %
  • change input source to X

For more information, check the README.md from the repository. I’ve managed to get all voice controls I needed for my TV with my fork, I hope it will help others do the same. :slight_smile:

Development for this project relies solely on donations, so if you enjoy this component, please consider donating to ensure it’s continued survival.

17 Likes

Here is what configuration I used for it, as it may help others understand this custom component better:

media_player:
  - platform: samsungtv_custom
    host: XXX
    name: Samsung TV
    mac: XXX
    port: 8002
    source_list: '{"TV":"KEY_SOURCE+KEY_LEFT+KEY_LEFT+KEY_ENTER","Chromecast":"KEY_SOURCE+KEY_LEFT+KEY_LEFT+KEY_RIGHT+KEY_ENTER","Manual":"KEY_SOURCE+KEY_LEFT+KEY_LEFT+KEY_RIGHT+KEY_RIGHT+KEY_ENTER"}'
    app_list: '{"Netflix": "11101200001", "YouTube": "111299001912", "Spotify": "3201606009684"}'

“Manual” in source_list is my PC, because “Manual” is a whitelisted word on Google Assistant while “PC” is not, so voice commands would not work with “PC” but do work with “Manual”. “TV” and “Chromecast” are both whitelisted words too, so those also work with voice commands.

3 Likes

I appreciate what you are trying to do but is it possible at all for these to be integrated into the base repo from roberodin? just so we don’t end up with a multitude of different custom components.

1 Like

You’ll need to do a pull request.

roberodin’s repo was one custom component that I tried, but did not work well at all for my case, the biggest drawback was that it was extremely slow at sending commands compared to xchwarze’s fork. (that I forked out of)

More so the code of these 2 repos seems very different by now, and I merged 2 PRs (1 from roberodin’s repo and 1 from xchwarze’s repo) that seemed to be completely ignored at their respective repos and helped a lot to get this thing working properly.

I always try to push my changes to the repo I fork out of, so I did make a PR to xchwarze’s fork, but after a week of it being ignored (and having other PRs that were much older and still ignored), I choose to go down my own route…

Just remembered the second big drawback with roberodin’s repo: it didn’t save the auth token from the TV, so the TV kept asking me to approve HA at every command. This was also mentioned in various comments there and also seemed ignored.

I appeciate that roberodin’s trying to make a custom component that fits all Samsung TVs, but I believe the clutter of code he has there has led to a very broken and inefficient component, that he doesn’t have the time or desire to truly improve.

While my motivation was to make a perfectly working custom component for the case that I can test easily, not to fix the biggest mess I could find. I did however comment at both the PRs i merged from their repos at an attempt to gain their attention over them, as they are truly relevant and simply ignored.

many thanks for this component, may I ask what model is your Samsung TV?

I have a EU65MU6102K, I forked out of a custom component that said it was exclusively for 2016+ Samsung TVs, it should presumably work with all Tizen based Samsung TVs.

1 Like

did someone had success with Q70 series?

Works great for my Q70 that I got a couple of months ago. It just takes a little bit of time to start working.

hi,
I’m trying to set up a script to switch to HDM1 yet the below doesnt work

tv_channel_hdmi:
  alias: Samsung HDMI1
  sequence:
  - service: media_player.play_media
    data:
      entity_id: media_player.samsung_tv
      media_content_id: KEY_HOME
      media_content_type: "send_key"

i get this error

2019-12-03 20:35:11 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.1830551088] extra keys not allowed @ data['media_content_type']
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 133, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1214, in async_call
    processed_data = handler.schema(service_data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: extra keys not allowed @ data['media_content_type']

Try this:

tv_channel_hdmi:
  alias: Samsung HDMI1
  sequence:
  - service: media_player.play_media
    data:
      entity_id: media_player.samsung_tv
      media_content_id: "KEY_HOME"
      media_content_type: "send_key"

Notice "KEY_HOME" instead of KEY_HOME as it should be a string, not a predefined variable

ok, for instance I can switch on, it works, switch off doesn’t work. I can see vol up down and mute, but all does not work. I can see and select sources, like Netflix, but doesn’t work. Do I have to modify something else?

EDIT: I’m stupid, just missed the Authorization popup request on TV as I was not in the same room… Thanks.

Here’s my config:

# Samsung TV Q70
  - platform: samsungtv_custom
    host: 192.168.1.140
    port: 8002
    mac: MYMAC
    source_list: '{"TV":"KEY_SOURCE+KEY_LEFT+KEY_LEFT+KEY_ENTER","Chromecast":"KEY_SOURCE+KEY_LEFT+KEY_LEFT+KEY_RIGHT+KEY_ENTER","Manual":"KEY_SOURCE+KEY_LEFT+KEY_LEFT+KEY_RIGHT+KEY_RIGHT+KEY_ENTER"}'
    app_list: '{"Netflix": "11101200001", "YouTube": "111299001912"}'
2 Likes

I’m very glad you got it working too, the authorization pop-up can show up to 4 times (required for various kinds of actions) after first installing this custom component and restarting. But after that it should not show the pop-up again in the future.

2 Likes

Okay I made the change but nothing happens, I dont get any error message either.

Apps all work fine, yet I cant switch to hdmi or send keys

I haven’t forgotten about your issue, I just never had any chance to test anything in this time in order to offer relevant help…

Off the top of my head, without any testing regarding your issue. I’d say that if there is no error at all, then it’s sending the keys to your TV, but the TV doesn’t understand what the component is sending.

Presuming you have a TV that is compatible with this custom component (which means a 2016+ Samsung TV or any Tizen based Samsung TV), then it means that you need to try using the alternative way of sending keys with this component.

Check here on the readme page:

Look at "update_custom_ping_url" in those docs, then try the component with port 8002 or (if it doesn’t work with that port) try it with port 8001. It’s possible that this might fix your issues…

If that still doesn’t work, try also setting "update_method" to ping.

1 Like

Hi I currently using port 8002 with this CC to connect to my tv, I’ve previously tried 8001 with other CC and it didn’t work with my tv.

Everything else works expect sending keys

What does the update method do?

Did someone was success activating PIP trough HA with Q70 Samsung? In fact I would like to see my cam via Samsung TV browser when someone is detected at the house door. But I’m not sure it’s possible with Samsung TV, too bad, I was able to select different sources for PIP with my old 8 years old Sony TV, but I didn’t find this option with Samsung…

1 Like

Even if u can’t find a specific key for PIP that works with ur TV, as long as you can activate PIP through the TV menu, you should be able to do it with this component by chaining keys. (won’t look pretty though, u’ll see it going through the menu)

As for the browser, i saw some projects opening the samsung browser through a WS command, not sure if that command can open a specific page… it might be possible. But you’re asking for something that is very specific, I personally have no need for something like that, I could help u identify the command to open the browser, but you’d need to put in the work of coding it into the component…

ok, thanks, will investigate this in the future…
Just one question, I’m able to switch on the tv in an automation, with this:

- entity_id: media_player.samsung_tv_remote
    service: media_player.turn_on

and to manage the Yamaha amplifier and the lights, ok but what is the code for just selecting the source to Netflix for example?

EDIT: It’s working like this:

- entity_id: media_player.samsung_tv_remote
    service: media_player.select_source
    data:
      entity_id: media_player.samsung_tv_remote
      source: Netflix
2 Likes