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