Improving Samsung TV Control

I advise you try them both to see which one works best with your TV model.

Hey all,

First of all thanks to @jaruba and other contributors for an excellent custom component that can do what apparently Samsung with their Smartthings can’t!

I was disappointed it did not do all I wanted though. Therefore, I forked to make some changes:

  • Set the magic_packet to send a series of messages instead of a single message which drastically improves TV turn on behaviour (for me it’s now working perfectly), see below for my investigations
  • Implement a ‘channel_list’ in the configuration which allows changing the TV channel via Lovelace input selection and more importantly by voice command (tested with Google Home).
  • Improved the ‘play_media’ service call when calling for a channel content type to change to TV input first if not already on TV mode. Works best with smartthings integration, without smartthings it is not able to distinguish TV from HDMI input.
  • Improved the ‘play_media’ service call when calling for a channel to not switch to a channel if it is already on the right channel (prevents the tv to go from digital to antenna) – only works with smartthings integration.

Further explanations and reasoning below. Changes are found here - created a pull request to merge into the original component if @jaruba approves:
https://github.com/Screwdgeh/ha-samsungtv-tizen

Magic packet/WOL via WiFi investigations:
Had a lot trouble with consistency of this component. I have quite a crowded Wifi mainly due to many shelly components in my smart home all running off the wifi. I noticed there was no consistency/reliability at all in turning on the tv. First thing I did was to ditch the shellies on their own wifi instead on their own AP. Afterwards I noticed it still did not work perfectly, but while using a standard Android WOL app it did work reliably. I then noticed the magic packet was only sent once, while standard apps do 3 or 5 tries instead. So I bumped up the retries for the magic packet and now was able to get it working 100% of the time.

Using Google Assistant/Lovelace to change the TV channel
Did quite a bit of investigation here into both media_player component support as well as the google_assistant component. It seems both lack a proper implementation of changing channels on the TV. The google assistant component does not implement the tv channel trait (https://developers.google.com/assistant/smarthome/traits/channel), the media player does support a channel change via play_media service call, but it expects the TV is in TV mode already and furthermore there is no standard UI to actually change the channel - so would have to be a custom Lovelace implementation to get this action to occur.

Instead of implementing all of these lacking features in the multiple components where they are missing, I thought it made sense to append the input source list with TV channels, just like a list of Apps can be created. It would be then appended to the total input source list and can be selected from the UI to change to the specific channel. The service call can still be used to change channels via fancy buttons/scripting if desired since the service call is also updated. I further improved this by changing to TV input first if required (i.e. if TV is in HDMI or app input mode).

The beauty is that Google Home does understand the input sources, so a command like “Change the TV input to ” works for any of the names defined in the input source list - so with the update including any TV channels. I did not run into any naming restrictions for myself here.

1 Like

I just released v1.5.0 which includes a lot of changes:

  • support for Frame TVs to turn off correctly (by setting is_frame_tv: true in the config)
  • support for channel lists
  • improved TV turn on behaviour
  • changing channel with prev / next buttons from the UI (when the source is TV)
  • new SmartThings keys added: ST_MUTE, ST_VOLUP, ST_VOLDOWN, ST_VOL20, …
  • fix for authentication pop-up loop
  • fixes some “I/O inside loop” issues
  • added possibility to hold down keys, ex: KEY_VOLUP,3000 to hold down the volume up key for 3 seconds
    (and other more minor changes)

I’ve been noticing the last couple of days that my TV automations do not work anymore. It does turn on when using the component, but it will turn off (the state in Home Assistant only) after a couple seconds. The TV itself will actually still be on, but can’t be controlled from Home Assistant anymore as Home Assistant thinks it is off.

I am on the latest version (1.5.0) as well as the latest Home Assistant version (0.114.4).

Going to test with a previous version and see if that still works.

I’ve been testing quite a bit. Different versions of HA and this integration. After a while I found out my TV got a different IP, even though it has a reserved IP in the DHCP. Maybe I should just set a static one on my TV itself since it is reserved anyway.

Anyway, false alarm, sorry about that. Everything works again, stupid router.

This is not clear to me: to change the channel you can just use play_media with media_content_type: channel.

Absolutely and it uses this in the background. All this channel_list does is add a list of predefined tv channels that can be changed to via media player input ui and via voice command at least from google assistant using the channel name. E.g. ‘change tv to eurosport’.

I’m having trouble getting cast to work. I get “media ID must be URL” or “media format not supported” no matter what I try. I can use browser to cast online videos but, I can’t get local to work.

{
  "entity_id": "media_player.samsung_tv",
  "media_content_type": "url",
  "media_content_id": "file:///C:/photo.jpg"
}

I’ve tried putting it on the virtual machine //HOMEASSISTANT/share/photo.jpg
I can’t figure it out. I’m sure it’s probably the way I’m inputting it.

Update: reinstalled now it says extra keys not allowed

@Warmachine The TV doesn’t support file and SAMBA for URLs, you need to give it a HTTP(s) URL.

OMG - Thank you so much. I’ve been pulling my hair out trying to get this sorted.
I deleted the whole device list on my TV, restart HA. Accepted the popup on the TV and now HA controling the TV working.
There was nothing wrong with HA it was all the TV.

1 Like

What’s an example of an http path for windows? I can’t get anything to work. I can cast any photo or file from any windows computer on the network just by hitting cast so, I know it is possible. I would really like to have this in my automations.

Maybe someone can help me out.
I have a Samsung Q8FN TV.
I’ve installed the the SamsungTV Tizen HA Integration (via HACS)
The TV shows up as media_player.samsung_q8fn.
So far so good.
When I use the example in call the service

service: media_player.media_player
{
“entity_id”: “media_player.samsung_q8fn”,
“media_content_type”: “send_key”,
“media_content_id”: “KEY_CHDOWN”,
}

I get an error about "extra keys not allowed @ data[‘media_content_type’] "
I tried with quotes, without quotes , etc.
if I leave out the type and id the service gets called and the TV show a message ‘not available’ so it appears it is talking to my TV some what.
I have gotten the pop-up from the TV to allow and have press the allow
yet I can’t seem to get the service working
I’m probably missing something simple here.
Thanks for any help

@gregmb it’s “media_player.play_media”, not “media_player.media_player”

Arrrgh! I knew it was something simple! Forehead to table, and repeat.

Now the TV is receiving the key codes. channel up and down work.
I tried KEY_POWERON and KEY_POWER but it did not turn on the TV.
I know that the TV can be turned on by wake on LAN (bit pattern sent to the MAC address)
which I did set in the configuration file.

Any Ideas what the issue might be?

@gregmb use the media_player.turn_on and media_player.turn_off services

If I upload a picture to an http web address and use web browser instead of url “media_content_type”: “url”. It will push the browser window and open the webpage on the TV.
I want to do the same thing with pic and vid files from a hard drive directly to the TV like casting from windows 10 or the phone works. Does anyone know how to do this?

@Warmachine you will most probably need to run a http server locally to expose the images and videos to ur network, search for an app that does that.

I can’t get the URL command to work with anything. I think it needs some work. The web browser command works to cast anything I want to the TV just not FULL SCREEN. Hopefully in the future they incorporate casting like you can with win10 or a phone.

@TheStigh You can open the browser with a specific URL with this component, here is an example:

i tried the example but it doesn’t work, do you have an other example?

i get:
Failed to call service media_player/media_play. extra keys not allowed @ data[‘media_content_type’]

Ideas?

Thanks for the help

@Dingin think this is also a case of calling wrong service: try media_player/play_media instead.