New Roku TV Device Handler

I present for your use, my new Roku TV App and Driver for Hubitat.

Download from GitHub, or install it through the Hubitat Package Manager application and be kept updated on my changes as they are published.

This uses a parent, and child device. The parent device Roku TV is the main device driver that controls the Roku media players, and Roku powered TVs directly as a TV capable device. The child device is a hubitat/Generic Component Switch for launching Roku apps, and tracking state of which app is loaded. Each app can get its own switch. If automatic management is enabled, the switches will be deleted automatically if the app is deleted from the Roku -- there is no need to manage them manually. Still, if you wish to, you may.

I use state to keep track of some helpful data regarding the Roku device, and I no longer require the user to enter the device MAC address. The MAC is auto-discovered using the standard HE tools. If using the Roku Connect app, then the IP address will be automatically updated by the app, as it detects changes. The Roku Connect app uses SSDP to discover all your powered on, and connected Roku players, so there is no need to manually configure them -- though you may do so if you wish.

This driver works best with Roku Enabled TVs, however, it will enable standalone Roku devices. Standalone Roku players that support HDMI-CEC (like the Roku Ultra), when connected to an HDMI-CEC TV can control the TV power (provided that your TV has HDMI-CEC enabled). Note that the standalone Roku Streaming device that I tested did not offer volume control of the TV as of the last time I tested. If Roku adds this ability to the device, this driver will be able to control TV volume as well.

I use this driver myself on two Roku powered TCL TVs, and a Roku Ultra.

[update]: The driver have been updated to greatly improve performance.
[update]: Now you can select any remote button as a key to add as a child device.
[update]: Wake-On-LAN and Wake-On-WLAN will only be called if the device supports it, and the device is already off. Removed the transitioning values turning-on and turning-off to improve compatibility with the rest of HE integrations (apps, alexa, sharptools, etc).
[update]: The driver location on GitHub has been moved. Import driver to will update the repo location.
[update]: The Child Device Driver roku-app-child.groovy is no longer used. All Children devices not use the built-in generic component drivers.
[update]: Fixed a bug that prevented the AV and HDMI child devices from working.
[update]: Child devices no longer support refresh
[update]: Added ability to manually add/remove child apps if auto-management is turned off

[update]: The new Roku Connect integration app is ready for use.
[update]: Added ability to add/remove child switches for each of the remote keys. These keys are momentary switches, as virtual buttons are not very effective for home automation, considering that smart speakers (like Alexa) cannot work with them.

The Roku Connect app is optional, and it does require the Roku TV device driver be installed on your Hubitat device to function. At present, the app will find Roku devices, create child apps for selected devices, and allow you to add/remove Roku apps as child buttons from a central location. The app also allows for renaming the labels of all app managed Roku devices. As I progress on the app, I will integrate centralized management of other settings of the Roku TV devices into the app as well.

NOTE that the any Roku devices added via the app are owned by the app. If the app is deleted, like any other app, the child Roku TV devices will also be deleted.

I have converted my TVs over the to app. With the app, there is no more managing of the IP address -- the app will keep it updated based on the SSDP auto-discovery results.

The Roku TV driver and Roku Connect app are available as a package via Hubitat Package Manager.

Enjoy

3 Likes

The install instructions are confusing. Can you update them to include the actual file names. Which file do you install first?

I'd like it if the apps were represented by auto off switches, instead of buttons, so they can be seen in Alexa.

The instructions are a little unclear but they are both drivers.

I can't get it to work at all though.

The instructions are a little unclear but they are both drivers.

I can't get it to work at all though.

See my response to @photographicnature for slightly more detailed instructions. If after entering the ip address, and issuing a browser refresh, if you do not see the child devices, let me know. Your roku may be different, and my handler may need some additional parsing.

This code may not work on older roku devices, as it is written based on modern API specifications. It is unlikely to be the case though, as this is the same web api that the roku app uses on smart phones.

Good point. I noticed that too today. I will make that change, it is easy enough.

1 Like

I have updated this to a momentary switch + button. To ensure maximum portability, I added the actuator capability, and changed the logic so that a button press will trigger an on/off event. As the documentation is still very limited, I have to rely on information I can find out on the web and in this community. This update should work better. I have confirmed it does export my apps to Alexa correctly now.

Thank you for the feedback. Huge miss on my part.

1 Like

Install the roku-tv.groovy and roku-app.groovy to the drivers code sections. Then in Devices, create a new device, and select Roku TV as the device type. enter anything for the required fields. I use a naming convention which will be apparent in my updated instructions that I will post later today.

Once the Roku TV app is added as a virtual device, enter the IP Address, and press the save button. If your roku is using wifi, the mac address should be detected automatically. Now, wait about 5 seconds, and refresh the browser page. Your new page will produce details about your roku under the state section, and it should show the current currentApp and switch values. That should be all there is to it.

If at anytime you want to reset your child devices, press the Refresh Apps button, and it will delete and re-add all your child devices.
The regular "Refresh" button will find any missing app, and add them as well as remove any app that are no longer installed on the TV. This means you do not have to manually maintain your child apps.

Nice I have it installed. I am not seeing my TV talking to my router right now so it must be sleeping. I will check it out when I get to the house and see if I can get things to talk. My Roku TV is a Sharp.

The power on action will attempt to wake up the roku device, if the device supports wake-on-lan or wake-on-wifi. If you can send me the XML result from the following call, I can see how to interpret the output.

From a web browser, navigate to "http://ip_address:8060/query/device-info"

The ip_address will be your TV's IP Address. Additionally, you may need to check that the TV allows access to it from the network. I will add more details to the github project as I collect those details from my TV.

FYI - the driver generates an error when saving preferences which prevents the current app polling from working. Should be runEvery1Minute (no "s" at the end):

dev:1052019-03-18 03:47:40.110 am errorgroovy.lang.MissingMethodException: No signature of method: user_driver_apwelsh_Roku_TV_321.runEvery1Minutes() is applicable for argument types: (java.lang.String) values: [queryCurrentApp] on line 49 (updated)

Also:

  1. is polling installed apps every 5 minutes really necessary? I haven't thought my way through it, so maybe it is. Just seems excessive. I would have thought hourly or once a day would be enough.

  2. I didn't try it, but do the child devices get uninstalled if you uninstall the parent device?

  3. Lastly - thank you! I happen to have 3 Roku TVs, and it is working great on all 3. I did have to turn on 'fast TV start' so that the TV would be reachable when 'off', but that was somewhat expected.

The app and driver seemed to work good.

However, the connection is broken once the TV sleeps. The TV’s MAC disappears from the arp table along with its IP lease that was associated with it.

Does the wake on LAN use the layer 2 or layer 3 address?

I am thinking if I just do a static MAC/IP association in my router. Wake on LAN might work.

@photographicnature On your TV do you have this option in the settings menu? And if you do, is it on?

SYSTEM --> POWER --> FAST TV START

I had one TV that had this setting OFF, and I saw the same thing - no communication once TV was off. Turning it ON fixed it.

1 Like

Oops. I fixed it on my install but forgot to do so on github. I cannot fix it from my phone so I will get it fixed later today when I can SSH into my server. Thanks.

Update: this has been corrected on github

I do not know how the wake in lan works, or if it actually does anything. This came from the parent code. I will look into it though. DHCP reservation does not affect ARP table cache expiration it is there to ensure that the device is always assigned the same address. The wake on lan feature of networks is a mac based feature and requires the target network card is listening even if the computing device is off. Not all devices support it. TCL does, but to know if sharp does, I would need the device info report from the TV.

@JasonJoelOld I did find that option and enable it. I will see how that works out.

1 Like

Just FYI.

My needs were a lot simpler than the full featured, and excellent, driver Armand made.

So I made a "Lite" version of this driver, will full credits to Armand included in the driver of course, that only does the parent app side of the functionality - and does not add the child apps at all.

I also added in debug logging, auto-debug logging turnoff, and set the device status to refresh every minute.

https://raw.githubusercontent.com/Botched1/Hubitat/master/Drivers/Roku%20TV%20Lite/Roku%20TV%20Lite.groovy

3 Likes

I will be looking into making this an app, so that the drivers will be created with the features desired. I think we can do that now. If we can, and IF I can figure out how to create the apps, it will offer auto-discovery (I have worked that out now), and once the device is selected, it will enable the installed apps. Then each supported action of the TV can be added as a part of the main remote, or as a stand-alone button.

I think the real draw back of the current solution is that even though this driver is for a TV, Alexa still sees it as a light. Alexa can work with TVs intelligently, so it would be nice if there was a way to make TVs in Hubitat appear as such in Alexa.

1 Like

I was actually thinking the same thing / a similar thing, but have zero time to work on it.

I also really want to rewrite the Sony TV driver to be a lot more like your Roku driver code, as the Sony TV driver code is a MESS, but it does work so no time for that right now either.

By the way, I've gotten a LOT of use out of your driver and use it for a number of things in my home automation. Thank you very much for making it!!!

1 Like