Roku TV Support

Hello there,

The roku component works great for the roku stick, and pretty darn well with the roku tv. It would be great though if there could be more functionality with the roku tv. For example it is possible to turn on/off the tv from a companion app, it would be nice to get that funtionality here as well. I have looked around and it seems that there is already a python/roku with a power function. I tried to integrate it with my own HA instance but lack of time and expertise has stopped me.

Just wanted to bump this thread and mention that these Roku TVs are very popular on Amazon these days, and are often featured deals around holidays or “Prime Day”, so I imagine there are many other users who could benefit from expanded support.

I agree! This would be a great feature to see!

I actually logged into the Forum tonight specifically to see if I could find whether the Roku TV is supported by the component, and if so, if power on/off is a supported function, since obviously that’s not a thing for the set top boxes. It would be great to see that addition here.

I was able to get my TCL to power on and off as follows:

rest_command:
  tv_power:
    url: 'http://<tv ip address>:8060/keypress/Power'
    method: 'post'

This works as long as the TV is in standby mode, but it stops responding to the POST after 15 minutes. You can wake it up using WOL:

switch:
  - platform: wake_on_lan
    mac_address: '<tv mac address>'
    name: tv_wol

I setup an input boolean with automations to track state and tie in my stereo system (which is controlled with a Broadlink Mini):

alias: "TV Switch On"
initial_state: True
hide_entity: True
trigger:
  - platform: state
    entity_id: input_boolean.tv
    from: 'off'
    to: 'on'
action:
  - service: switch.turn_on
    entity_id: switch.tv_wol
  - service: rest_command.tv_power
  - service: switch.turn_on
    entity_id: switch.stereo
alias: "TV Switch Off"
initial_state: True
hide_entity: True
trigger:
  - platform: state
    entity_id: input_boolean.tv
    from: 'on'
    to: 'off'
action:
  - service: rest_command.tv_power
  - service: switch.turn_off
    entity_id: switch.stereo

You can also setup PowerOff and PowerOn as distinct rest_commands if you prefer that to toggling.

(I got the idea for the WOL from that same python-roku project.

3 Likes

This looks great. I will give it a try and let you know how it works. So if the tv is past the 15 min rest period which mine usually is. I will have to run a WOL command right?

Yeah, I just send it every time I turn on the switch - it’s quick and doesn’t seem to have an impact if the TV is already awake. I don’t even need a delay between the WOL packet and the power command.

One thing to note is that WOL only works on wired connections. If your TV is connected via wifi, I’m pretty sure you’re out of luck once it goes into suspend. You’d need to look at waking it up over IR or RF at that point.

If you are using wifi for the TV, it might be possible to keep it awake by having HA submit a rest command to it every 10 minutes after power off. I have no idea what that would do to your energy bill though.

So does this mean you don’t have to enable the ‘Fast TV Start’ option on the TV (cos the WOL gives it the necessary prod)?

@Valdorama This does work without the “Fast TV Start” but it’s kind of awkward and this could be because I’m definitely not an expert. The WOL switch appears in the interface. If you turn it on while the TV is in deep sleep, the TV will turn on. Turning off the switch however does nothing. I didn’t really like the automation route either.

My though would be to use the RESTful Switch to create a power toggle for the Roku TV.
The problem is that if you use the url: ‘http://tv_ip_address:8060/keypress/Power’ The switch doesn’t get added because it can’t preform a GET on that address. Also the switch could get it’s status from: “http://tv_ip_address:8060/query/device-info” Result will show the tag power-mode as either PowerOn or DisplayOff indicating status.
My guess is that there is probably a way to set this up using template or booleans but again, I’m no expert so any help on getting this up would be appreciated.
Here are the results of device info from command line in case that helps:

> curl -X GET http://roku_ip:8060/query/device-info | grep power-mode
>   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
>                                  Dload  Upload   Total   Spent    Left  Speed
> 100  2077  100  2077    0     0  51993      0 --:--:-- --:--:-- --:--:-- 53256
> 	<power-mode>DisplayOff</power-mode>

and:

curl -X GET http://roku_ip:8060/query/device-info | grep power-mode
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2074  100  2074    0     0  68759      0 --:--:-- --:--:-- --:--:-- 71517
	<power-mode>PowerOn</power-mode>

OK, So after wasting a bunch of time trying to do this as a REST switch it was much simpler to just write a command line switch. Here is the code I used, it doesn’t have the WOL so you should enable fast TV start if you want this to work as is (it should be pretty simple to include this though).
Tested on TCL roku TV, the switch turns the TV on and off and the position is grabbed based on the info grabbed from roku api.

switch:
  platform: command_line
  switches:
    tv_power:
      command_on: 'curl -X POST http://roku_ip:8060/keypress/PowerOn'
      command_off: 'curl -X POST http://roku_ip:8060/keypress/PowerOff'
      command_state: 'curl -s GET http://roku_ip:8060/query/device-info | grep power-mode | sed -e "s:<power-mode>DisplayOff</power-mode>:OFF:" -e "s:<power-mode>PowerOn</power-mode>:ON:"'
      value_template: '{{ value == "ON" }}'
2 Likes

Finally managed to get it working using rest_command in conjunction with WOL, thanks to @natabat’s source. I can successfully turn the TV on (without Fast Start enabled) and then off again.

switch:
  - platform: wake_on_lan
    mac_address: 'TV MAC ID'
    name: roku_tv_wol

rest_command:
  roku_tv_power_toggle:
    url: 'http://<TV IP>:8060/keypress/Power'
    method: 'post'

In my scripts.yaml:

turn_on_roku_tv:
  alias: Turn On Living Room TV
  sequence:
    - service: switch.turn_on
      entity_id: switch.roku_tv_wol
    - service: rest_command.roku_tv_power_toggle

turn_off_roku_tv:
  alias: Turn Off Living Room TV
  sequence:
    - service: rest_command.roku_tv_power_toggle

Few things:

  • I’d prefer to use the distinct PowerOn and PowerOff keypress commands but just can’t seem to be able to define two rest_commands.
  • My TV is connected via ethernet so WOL works.
  • TV has been allocated a fixed IP address so I don’t need to worry about that.
  • Next step is to trigger the on/off from a Google Home (via IFTTT)

@Omri_Asta: Have you noticed your TV turning on by itself? I tried to do the same thing you did, and I found that if HA ran the state check while the TV was suspended but not fully powered down, it would come back on again.

@Valdorama: You should be able to define a second command just like you did the first:

tv_power:
  url: 'http://<IP>:8060/keypress/Power'
  method: 'post'
tv_power_on:
  url: 'http://<IP>:8060/keypress/PowerOn'
  method: 'post'
tv_power_off:
  url: 'http://<IP>:8060/keypress/PowerOff'
  method: 'post'

I also ended up just calling wake_on_lan.send_magic_packet in my on automation, cause the wol switch was also causing the TV to randomly wake up while monitoring its state. I’ll have to try it again if no one else is seeing that behavior… I believe there’s a setting on the TV to skip the suspend state and go straight to a full power down…that would probably fix my problem.

@natabat I have the TV set to “Fast Start” so it doesn’t go into “deep sleep” and no, the “command state” doesn’t turn the TV on for me. The reason I didn’t go with the automations and scripts is I just wanted a simple toggle switch in the UI which I don’t really get with the others unless I trigger an automation…I wanted something similar to a light switch in the UI for the TV.

Does the command state work right or do you need to trim the tab before <power-mode> in your sed command too?

sed -e "s:.*<power-mode>DisplayOff</power-mode>:OFF:" -e "s:.*<power-mode>PowerOn</power-mode>:ON:"

Still not quite sure what I got wrong that caused that odd behavior, but I shifted to using the command line switch from @Omri_Asta (with the fix suggested by @cwhits), and that seems to be working. For anyone who doesn’t want to use the Fast Start setting, here’s the power on command I’m using:

command_on: 'wakeonlan roku_mac; sleep .25; curl -X POST http://roku_ip:8060/keypress/PowerOn'

You also need to sudo apt get install wakeonlan. The sleep is there just to give the TV a little time to wake up before sending the PowerOn command.

Thanks!

So oddly enough my tv, being an earlier Roku TV does not have a Ethernet port nor does it have a fast start option. So I guess I am out of luck.

Where do I place this?

In your switch config.

I just got a Roku TCL tv and for the most part it works in hass.io, but I can’t turn the TV on from hass.io. Has anyone fully figured this out? What’s the easiest solution to make this work? I’m also surprised this hasn’t been fixed in the Roku integration. Thanks!

While not in the Roku integration. I was able to make a switch using whats described in this reddit post.

Hope it helps!