Samsung Smart TV - No control?

This may be related to the timeout value I’ve got set. The samsung_tv component looks like it’s making periodic calls to ensure my TV is active but this timeout got triggered when I was trying to turn off the TV and I had to wait for the connection to reset.

2018-05-20 23:33:35 WARNING (Thread-23) [pychromecast.socket_client] Heartbeat timeout, resetting connection
2018-05-20 23:33:35 DEBUG (Thread-23) [homeassistant.components.media_player.cast] Cast device availability changed: LOST
2018-05-20 23:34:05 ERROR (Thread-23) [pychromecast.socket_client] Failed to connect, retrying in 5.0s
2018-05-20 23:34:20 DEBUG (Thread-23) [homeassistant.components.media_player.cast] Cast device availability changed: CONNECTED

There’s also a 15 second timer that gets activated during shutdown which prevents you from pressing any other buttons. This should be fine but I was unable to turn my TV off for a few minutes.

2018-05-20 23:35:23 INFO (Thread-12) [homeassistant.components.media_player.samsungtv] TV is powering off, not sending command: KEY_EXIT

2018-05-20 23:38:47 INFO (Thread-2) [homeassistant.components.media_player.samsungtv] TV is powering off, not sending command: KEY_EXIT

In the end, it probably all comes down to the weird behaviour I’m seeing with my TV where I sometimes lose the first input. I’ll spend some time experimenting with samsungctl to see what I can find.

This is great however, I’ve just added the Mac address and it doesn’t seem to be working. Is there anything else I need to do? It turns off and I can control volume etc it just doesn’t turn back on. I have a wired connection.

Ok, it must depend on the model then. I’m sure it didn’t work with both my Samsung TV’s (one with wlan usb stick and the newest one with integrated wifi), only turn off did work. The TV appeared to not be connected to the wifi when the tv was off.

1 Like

Looking at the code indicates that mac address is only picked up from the config file if you also specify the ip address:

    # Is this a manual configuration?
    if config.get(CONF_HOST) is not None:
#...
        mac = config.get(CONF_MAC)

If you’ve already done that you might try enabling debug logging for media_player in configuration.yaml:

logger:
  default: critical
  logs:
    homeassistant.components.media_player: debug

If that still doesn’t help, you could try using wakeonlan directly from the command-line to see if that works.

I’d also suggest trying to find documentation for your TV to make sure it supports wake-on-lan.

Hi,
How do you apply the key codes to a ha script?

Here’s my script to start Netflix. Let me know if this doesn’t answer your question.

netflix:
  alias: Netflix
  sequence:
  - data:
      entity_id: media_player.samsung_tv
      key_code: 'KEY_EXIT'
    service: media_player.send_key
  - delay:
      milliseconds: 100
  - data:
      entity_id: media_player.samsung_tv
      key_code: 'KEY_HOME'
    service: media_player.send_key
  - delay:
      milliseconds: 100
  - data:
      entity_id: media_player.samsung_tv
      key_code: 'KEY_RIGHT'
    service: media_player.send_key
  - delay:
      milliseconds: 100
  - data:
      entity_id: media_player.samsung_tv
      key_code: 'KEY_RIGHT'
    service: media_player.send_key
  - delay:
      milliseconds: 100
  - data:
      entity_id: media_player.samsung_tv
      key_code: 'KEY_RIGHT'
    service: media_player.send_key
  - delay:
      milliseconds: 100
  - data:
      entity_id: media_player.samsung_tv
      key_code: 'KEY_ENTER'
    service: media_player.send_key
1 Like

I start Netflix and other apps over HTTP on my Samsung TV. Yesterday I wrote a blog-post about that so maybe it will work on your TV too. The post is in german but the configuration might be self-explaining: https://www.panbachi.de/samsung-tv-app-starten-ueber-http-132/

3 Likes

That’s awesome!

How did you come across this interface? I’m curious what other stuff might be available.

I analyzed the network traffic to see what happens when the YouTube or Netflix apps on my Android-Smartphone starts the app on TV to continue streaming (I hope you know what I mean). So I found that HTTP-request and tried it for other apps and it works. I think it might work on other brands too and not only on Samsung.

1 Like

Good job! I started trying to analyze network packets from Anymote (https://play.google.com/store/apps/details?id=com.remotefairy4) until I found this thread and discovered what I was doing wasn’t necessary.

Are you using Samsung Smart View (https://play.google.com/store/apps/details?id=com.samsung.smartviewad) on your phone, or something else?

No, I don’t use one of these apps.

Sorry, I misread your original comment. I thought you had a single app on your phone that was used to launch apps on the TV and thought there might be more functionality that we could look at.
I spent some time looking at the Samsung Developer portal (i.e. Convergence | Samsung Developer) to see what kinds of other useful commands could be performed through this interface but didn’t find much of interest.

I can confirm that napsio’s discovery works on my UE49MU6400 for YouTube and Netflix (but not Amazon?).

However, I was particularly interested in launching the Plex and iPlayer apps, so I did a bit of digging and found that the YouTube and Netflix apps require a HTTP POST of ‘/ws/app/YouTube’ and ‘/ws/app/Netflix’ as described. The plex Android app doesn’t have the ability to cast directly to the Samsung TV, but when I launch Plex via the SmartView App, the analyzed HTTP POST was ‘/ws/app/setdmsuuid’, where the uuid is stated as ‘uuid:55076f6e-6b79-1d65-a47b-2c0e3d2f748b’.

I tried forming this into some sort of POST command, but couldn’t get it to work. Unless I’m wrong, it would seem that only apps that you can cast to (from Android) have there own ‘/ws/app/APP NAME’? It would be good if we could launch any app, even if we have to discover it’s uuid in advance.

Hi,
both @Drywcyfyr and @napsio’s solutions do work like a charm. I was wondering though (same as @knaks) if we could launch some further apps using napsio’s solution. I am particularly interested in PLEX. If we can find a way around PLEX then I’ll have my top 3 favorites (Netflix , Youtube , PLEX) and I don’t mind emulating the rest (less used - Spotify , Twitch ) via send_key commands per Drywcyfyr’s solution.

Anyone that had any progress regarding that?

It looks like some folks have been discussing similar things over on the samsungctl forum.
https://github.com/Ape/samsungctl/issues/75

Will give a try

Hey @Drywcyfyr , do you plan to submit your custom component? I think it would be really helpful to a lot of people :wink:

2 Likes

@kaiomatico - I wasn’t planning to submit anything because I haven’t really done anything except to expose existing functionality through a new service.

I’d be happy to see this functionality exposed officially but I can’t think of a way that makes sense within the confines of the media_player component. But now that I’m looking into it a little bit, I’m wondering if it would make sense to create a Samsung remote component.

I’ll investigate to see how much work would be required for official integration.

2 Likes

Hey, with the updated play_media from the new 0.73 Hassio samsungtv component we are now able to change the channel directly at least. Hopefull the check for only accepting integers will be removed soon. Here is a template light which is able to change the channels I just configured. My samsung TV instance is called “tv2”, so I was able to name the template light “tv”. It works fine with the emulated_hue component to tell alexa to set tv to 5% (which changes the channel to channel 5)

media_player:
  - platform: samsungtv
    host: 192.168.178.XX
    port: 8001
    name: "TV2"
    mac: "xx:xx:xx:xx:xx"

light:
  - platform: template
    lights:
      tv:
        friendly_name: "TV"
        turn_on:
          service: media_player.turn_on
          data:
            entity_id: media_player.tv2
        turn_off:
          service: media_player.turn_off
          data:
            entity_id: media_player.tv2
        set_level:
          service: media_player.play_media
          data_template:
            entity_id: media_player.tv2
            media_content_id: "{{ (brightness/255*100)|int+1 }}"
            media_content_type: channel
1 Like

Hey @Drywcyfyr thanks for the component works fine for me only for turning on the tv.

Did you find any solutions as to why your component cannot turn on the t.v. ?

Thanks