[Release] Roku Connect integration App and 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 Premier+.

Driver Capabilities
The following standard capabilities are supported. Some features are not fully implemented due to the nature of the Roku API, such as setVolume. And most attribute for TV are not yet reported, but the commands are implemented at this time.

  • TV
    • Channel up/down
    • volume up/down
  • AudioVolume
    • (un)mute
    • volume up/down
    • setVolume (not supported)
  • Switch
    • on/off
  • Refresh
    • query device info
    • query media input source
    • query media transport state
    • query installed applications
  • MediaTransport
    • play / pause / stop
  • MediaInputSource
    • Home
    • InputTuner
    • InputAV
    • InputHDMI(1,2,3,4)
    • any installed application by name

Driver Features
The Roku TV Driver has the following features:

  • Can send any remote control command to Roku device
  • Easy access to Home button as a Custom Action
  • Easy access to KeyPress for any remote key as a Custom Action
  • Auto-discovery of installed Apps
  • Configurable Auto-Management of installed apps as child devices
  • Configurable child device for TV inputs
  • Implements custom "Application" attribute to report the current application (legacy attribute)
  • Implements standard "mediaInputSource" attribute to report official input source names as supported by Roku.
  • Support supportedInputs for deshboard controls by services that support the media input source capability, to provide a list of all supported inputs of the Roku device
  • Child apps may be turned on or off, and only one child app may be on at any time.
  • Ability to turn on Roku media player connected TVs if:
    • TV must support HDMI-CEC
    • TV must be connected with compliant HDMI 1.3 cable
    • Roku Player must support HDMI-CEC features (some Roku Sticks do not)
    • Roku Player / Roku TV must be powered on (fast-start enabled on Roku TVs)
  • Ability to search for content on Roku, and auto-play content if results are confident enough
  • Ability to create Child Switch Devices for any Remote Key
  • A value for iconPath defined under Data section for all installed apps and inputs.

Roku Connect App

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 and Install Roku devices
  • Create or Remove Roku "Channels" (aka apps) as Child Switches of the Roku Device
  • Create or Remove Roku Input device as Child Switches of the Roku Device, if the Roku is a TV device.
  • Renaming of Roku child switch labels of all Roku Connect 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: 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.
Note 2: Any Roku devices created manually (without the app) cannot be managed by the Roku Connect app.

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

Performance
I have been working hard to improve the performance and minimize the load on the hub by using this driver. At this time, the Roku devices do not support web-hooks, or any other notification method. Additionally, the Roku device only support the heavy and CPU intensive XML format. JSON data reduce processing loads considerably, and cut network traffic in half (on average). Roku does not support JSON, they only support XML. I have worked hard to rework logic to optimize XML parsing as much as possible. As a result, I have cut the parsing times in half for the heavy portion of the refresh process (queryDeviceInfo), and reduced the number of refresh operations performed so refresh operations only occur when they can provide meaningful results.

That being said, there are still many things I am working on to try and further reduce the load of the driver on the system. The number one most important thing to reduce system load, is to set reasonable refresh times. If you don't need a certain refresh operation, set the time to zero (0) to disable that refresh operation.

I am open to input from everyone on recommendations on how to further improve performance

Refresh Logic Explained

Query Device Info - This query is used to determine the on/off power state of the TV (if the Roku device is a TV). As of v1.2.14 on non-TV media players, this query will only run once to configure the device, or if the configure command is performed, regardless of the refresh interval setting. This query is the most CPU intensive because the TV returns a large amount of XML data to be parsed.

* This query is only active when the TV is off, or the Roku is on the home screen.

Query Active App - This query is used to determine what the current application is. This query is very light weight, and only runs at all times. If the TV is Off, and the value of application is not Roku (or mediaInputSource is not Home) then the device assumes the TV has been turned on. When the TV is off, the value of application will always report Roku (mediaInputSource will return Home). If your integrations do not require any logic to be tied to the TV being turned on, then this query can be used to confirm on/off state and the device info query can be set to a rather conservative value and this one can be more aggressive.

* This query may be disabled automatically while an application is loaded on the Roku, if the Query Media Player refresh is active (the bugs are still being worked out for this logic).

Query Media Player - This query is used to determine the transportStatus value (playing, paused, stopped). This query is a bit heavier than the active app query, but still very light weight in comparison to the device info query. This query will only run if an application is active, so it's state is dependent on the state of the active application query.

* This query is only active with an application is active on the Roku

Query Installed Apps - This query is used to obtain the list of all the installed applications. The query is not needed once the list has been polled from the Roku device, except when applications are installed or removed. Because of this, you can disable the query, and manually call the Reload Apps command to wipe and load the applications list, or call the Query Installed Apps command to only detect changes, and update the system accordingly. The complete list of installed applications found from this query are published through the supportedInputs attribute, so that dashboard that support the MediaInputSource capability can be used to switch inputs and applications on the roku -- I am not aware of any dashboards at this time that support the capability.

* I do not recommend setting this to an aggressive refresh interval. I set mine to 240 minutes (every 4 hours).

Enjoy

11 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.

2 Likes

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.

1 Like

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!!!

2 Likes