Roku and Now TV network control plugin

Questions and comments specific to a particular plugin should go here.
barnabas1969
Experienced User
Posts: 131
Joined: Sat Feb 04, 2012 1:42 am

Roku and Now TV network control plugin

Post by barnabas1969 » Mon Jan 27, 2014 5:23 am

I wrote a plugin to control a Roku (also known as "Now TV" in the UK) box over Ethernet or WiFi. It is very simple. Please read the README file, and review the __init__.py file too.

Please feel free to add more features. Please post them to this thread. This is my first plugin which I've posted to the EG forums.\

I've tested this using my Roku 3. I think it should work with the older models of Roku devices too. I've also heard that Sky TV in the UK sells a device called "Now TV", which is simply a re-branded Roku box. It should work for Now TV also.

The plugin can send the following commands:

Similar to the remote control, it can send the following buttons...

Home, Back, Left, Right, Up, Down, OK/Select, Rewind, FastForward, Play/Pause, InstantReplay, Option (the asterisk * button), Info (not found on my remote, but it is in the specification), and Search (also not found on my remote, but it is in the specs).

It can also directly launch a Roku "channel". All that is needed is the App ID (you can find this on the Internet, or you can visit the internal webpage on your Roku box by opening a web browser and typing "http://<your_roku_IP_address>:8060/query/apps". This will list all the "channels" that are installed on your Roku box, along with the "id" number. This is the number which is required by my plugin. You can simply update the __init__.py file with a new line to start your desired "channel" with the app id found in your browser! Feel free to submit the most popular choices back to me.

I have included actions which start the Netflix, Hulu Plus, Amazon Instant Video, Crackle, and Pandora channels. You can add your own or post below to request that I add others for you. I'll update my first post as I have time, based on your requests.

The plugin can also send keyboard keys a-z, 0-9, and +, -, /, and *. These can be used as input to a search box, or any box that accepts "keyboard" input (as long as the "channel" has not specifically blocked input from a network application).

So... have fun, and let me know if I can help you or add more features.

I'm planning to use this in conjunction with the libCEC plugin, so that my PC can emulate the Roku box so that my TV "thinks" that the Roku box has HDMI-CEC capabilities.

Thanks.

Zip file is attached.
Attachments
RokuNetworkControl (0.2).zip
Version 0.2
(6.33 KiB) Downloaded 307 times
RokuNetworkControl.zip
Version 0.1
(4.02 KiB) Downloaded 218 times
Last edited by barnabas1969 on Wed Mar 26, 2014 3:36 pm, edited 8 times in total.

barnabas1969
Experienced User
Posts: 131
Joined: Sat Feb 04, 2012 1:42 am

Re: Roku and Now TV network control plugin

Post by barnabas1969 » Tue Mar 18, 2014 4:49 pm

Does anyone have feedback on this plugin?

User avatar
techoguy
Experienced User
Posts: 157
Joined: Mon Mar 18, 2013 1:32 am

Re: Roku and Now TV network control plugin

Post by techoguy » Wed Mar 19, 2014 7:15 pm

I've been meaning to test the plugin but just haven't had time.
I was also going to help if you would like to add an action that would allow you to select any channel that is installed on your roku so the user doesn't have to search for the app id. This would work by first by having the plugin query the apps from Roku, then listing those channels in a drop down that a user can select in the action configuration window.

Hopefully i can test it soon, and i'll get back to you.

Thanks for writing the plugin!
The Latest SONOS Plugin:
Latest version can be found here: http://eventghost.org/forum/viewtopic.p ... 05f#p30309

EventGhost Lets me automate my home the way I want it, I love using it!

barnabas1969
Experienced User
Posts: 131
Joined: Sat Feb 04, 2012 1:42 am

Re: Roku and Now TV network control plugin

Post by barnabas1969 » Fri Mar 21, 2014 2:41 pm

techoguy wrote:add an action that would allow you to select any channel that is installed on your roku so the user doesn't have to search for the app id. This would work by first by having the plugin query the apps from Roku, then listing those channels in a drop down that a user can select in the action configuration window.
That would be awesome! So would automatic discovery of the Roku's on the user's LAN.

User avatar
techoguy
Experienced User
Posts: 157
Joined: Mon Mar 18, 2013 1:32 am

Re: Roku and Now TV network control plugin

Post by techoguy » Fri Mar 21, 2014 7:37 pm

So would automatic discovery of the Roku's on the user's LAN.
I haven't looked into it, do you know how to discover the roku on the network? or how the app does it?
If i know how it does it, it might make it pretty simple to add that feature.
The Latest SONOS Plugin:
Latest version can be found here: http://eventghost.org/forum/viewtopic.p ... 05f#p30309

EventGhost Lets me automate my home the way I want it, I love using it!

User avatar
techoguy
Experienced User
Posts: 157
Joined: Mon Mar 18, 2013 1:32 am

Re: Roku and Now TV network control plugin

Post by techoguy » Fri Mar 21, 2014 8:19 pm

Never Mind.
I ended up looking for it.
http://sdkdocs.roku.com/display/sdkdoc/ ... trol+Guide

It uses SSDP so i can add that feature to.

here's an example of a quick test i performed:

Code: Select all

13:48:30   find roku
13:48:30      Searching for ROKUs ZonePlayers on network...
13:48:33      MSEARCH socket closed
13:48:33      Roku found: 1GS3CJ008141 - 192.168.0.115 - http://192.168.0.115:8060/
13:48:33      getting Roku Channels
13:48:33      http://192.168.0.115:8060/squery/apps
13:48:33      200 OK
13:48:33      <apps>
13:48:33       <app id="12" version="4.0.21">Netflix</app>
13:48:33       <app id="13" version="5.3.1">Amazon Instant Video</app>
13:48:33       <app id="2285" version="2.7.6">Hulu Plus</app>
13:48:33       <app id="837" version="2.0.10">YouTube</app>
13:48:33       <app id="26882" version="1.4.20131209">Redbox Instant</app>
13:48:33       <app id="24356" version="1.0.3700">Target Ticket</app>
13:48:33       <app id="13842" version="1.3.6">VUDU</app>
13:48:33      </apps>
the 1G... value is the SN of the ROKU.

If i do this, I have to make it so that it can find all Rokus (if a home has many of them) then decide if all actions are updated to include a drop down that allows you to select which Roku you want to send the command to or make it where the plugin supports multiple instances and you select the Roku for each instance within the plugin configuration window.
The Latest SONOS Plugin:
Latest version can be found here: http://eventghost.org/forum/viewtopic.p ... 05f#p30309

EventGhost Lets me automate my home the way I want it, I love using it!

User avatar
techoguy
Experienced User
Posts: 157
Joined: Mon Mar 18, 2013 1:32 am

Re: Roku and Now TV network control plugin

Post by techoguy » Sat Mar 22, 2014 10:15 am

Ok,
i've updated the plugin to version 0.2

It now will automatically search the network and look for all Roku's on the network. The actions now have a dropdown list to chose the Roku player you want to send the command to.

Each command is stored based on the Roku's SN so the IP address can be dynamic. If the plugin sends a command and the IP address has changed, the plugin will search for the Roku player and try the command again.

Also, there is a new action for selecting any channel that is installed on your roku device. When you select this action, a configuration window will pop up that allows you to select the Roku Player and the Channel you would like to start (drop down list has all channels installed on your Roku, and if you change Rokus in the first dropdown, the Channels list will automatically update to reflect the installed channels on the new Roku).

Let me know what you think and if you see any issues.
RokuNetworkControl.zip
Version 0.2 3/22/2014 3:14AM PST
(6.33 KiB) Downloaded 217 times
The Latest SONOS Plugin:
Latest version can be found here: http://eventghost.org/forum/viewtopic.p ... 05f#p30309

EventGhost Lets me automate my home the way I want it, I love using it!

Dragon470
Experienced User
Posts: 203
Joined: Thu Feb 10, 2011 2:16 am

Re: Roku and Now TV network control plugin

Post by Dragon470 » Sat Mar 22, 2014 10:02 pm

I tested the first version and it does work. I then tested the next version, it would not find my roku3. Mine is on wireless. I used the roku remote to get the roku out of the screen saver, then it found it. I restarted the plugin again and again at least 10 times and it will not find the roku3 again. I tested on another machine it finds it every time. These machines are nearly identical (same motherboard, nic, and os). I then checked and updated the nic drivers and it finds it fine on both machines. So this search could be an issue with some nics.

I did some searching and noticed that even the android app sataes it will miss wireless connections at times. I don't know if there would be any other way to search for the Rokus.

User avatar
techoguy
Experienced User
Posts: 157
Joined: Mon Mar 18, 2013 1:32 am

Re: Roku and Now TV network control plugin

Post by techoguy » Sun Mar 23, 2014 12:30 am

Hi Dragon470,

Thanks for the detailed feedback.
I'll adjust the timeout when searching to be longer to see if this helps. based on the description that's the only thing that I could think might help.
If i change the timeout would you be able to test it again?

thanks
The Latest SONOS Plugin:
Latest version can be found here: http://eventghost.org/forum/viewtopic.p ... 05f#p30309

EventGhost Lets me automate my home the way I want it, I love using it!

Dragon470
Experienced User
Posts: 203
Joined: Thu Feb 10, 2011 2:16 am

Re: Roku and Now TV network control plugin

Post by Dragon470 » Sun Mar 23, 2014 12:11 pm

unfortunately I updated the drivers to fix my issue. I could try a driver roll back, but I can not say that would produce the same initial results. I would say don't change anything unless someone else experiences the same issue. Then you could test with them.

barnabas1969
Experienced User
Posts: 131
Joined: Sat Feb 04, 2012 1:42 am

Re: Roku and Now TV network control plugin

Post by barnabas1969 » Wed Mar 26, 2014 3:36 pm

@techoguy: Cool... I added your new version to the first post.

Dragon470
Experienced User
Posts: 203
Joined: Thu Feb 10, 2011 2:16 am

Re: Roku and Now TV network control plugin

Post by Dragon470 » Sat May 17, 2014 12:04 am

I don't have to restart my server very often, so I finally did and the it would not find the roku again. This time I know the driver is up-to-date and I have since moved the roku on to wired. I did a new eventghost tree config and the stock version 0.2 works and finds it just fine. But every time I use it in my main tree config it would not find it.

Long story short I increased the timeout to 2 and It finds it no matter if the roku is wired or wireless. I also had to restart the server again and it found it right away.

I guess you might want to make the timeout a drop down list in the plugin config with the note that larger number = longer wait on scan. Might be nice to have that in a separate thread so it does not hold up eventghost. Just my thoughts and observations.

Dragon470
Experienced User
Posts: 203
Joined: Thu Feb 10, 2011 2:16 am

Re: Roku and Now TV network control plugin

Post by Dragon470 » Sun Oct 19, 2014 8:44 pm

I finally got around to solving my issue of finding my Roku. Apparently, a lot of people have this issue with various Roku network based remotes. mine is a network design issue. I have 2 switches in-between my computer, which can cause multicast problems. (one switch is smart and the other is too dumb to handle the multicast properly) So my solution is to scan each ip in the network/subnet. So if anyone has had issues of not finding your Roku device on version 0.2 try this below.

*** This has only been tested on a network with only one device. If anyone has multiple devices to test and confirmation would be nice.
Attachments
__init__.py
beta for long network scan
(21.61 KiB) Downloaded 180 times

bengalih
Posts: 48
Joined: Sat Feb 25, 2012 1:13 am

Re: Roku and Now TV network control plugin

Post by bengalih » Wed Sep 16, 2015 3:22 am

I just wanted to thank you very much for writing this plugin.

I just got a Roku 3 to replace WMC's retiring Netflix app. I use a Harmony One remote and the IR signals were being blocked with my positioning of the Roku.
So, instead of going back to the wifi Roku-mote, I searched for a plug-in and lo and behold here you are!

I'm new to Roku in general, but it appears that the new Roku 3 doesn't have an instant replay button/function anymore, so your plugin which provides that missing feature is also a great addition.

I really have only a couple of small issue/comments/requests as for the most part this is working great.

1) A/B buttons. I see these aren't listed in the sdk... do you know how to access them? They are very handy in Netflix to quickly toggle subtitles and audio tracks.

2) Key repeat delay. This is an issue in several places... Initially I thought the Roku remote was sending the same commands over http that your plugin does, but it must be doing its own thing.
In order to allow a direction key to issue more than once, I needed to add the eventghost "autorepeat current macro" action. But it has issues...
Some examples:
1) The main text search dialog. With the Roku-mote If you hold a direction key it will fluidly move across all letters and stop at the last one. But, using the plugin with autorepeat it continues off the edge of the letters and keeps scrolling to the next menu.
2) In netflix, and other apps - using the Roku-mote to scroll through shows is extremely fluid, there is no stutter as it scrolls. The plugin has a stutter even set to 0.0 delay.
3) Like in #2 when holding down the arrow keys to FF/RW the roku-mote just smoothly continues in the direction you need. The plugin does a ff/stop/ff/stop/ff/stop pattern, extremely quickly. The net result is still a FF, but it is jerky. I saw this very clearly in the FX NOW app.

Most of these are minor annoyances, and the extra "range" I get by controlling everything from the Harmony + EG are worth it.

I'm curious if you have any better solution or can give an explanation as to how the Roku-mote is able to do these things as I assumed it was simply using the same protocols.

Thanks again.

UPDATE:

Ok so I think I mostly answered my own questions in regards to #2 & #3.
I had to edit the plugin to change the timeout to 3 seconds, otherwise my roku was not always found when EG launched.
Personally, I think keeping the timeout defaulting to 3 seconds is more flexible, as I would rather wait a few seconds for a command to work, rather than not work at all.

Anyway, I see the following comments in your code:

'This plugin currently only sends "keypress" # and "launch" commands to the Roku device. It does not make use of the keydown and keyup commands'

So this is probably the difference I see - multiple keypress vs a keydown event.

I'm trying to think of a way to get this to work, but can't determine how it could.
I could set a longpress of a direction button to jump to another action which sends a keydown instead of a keypress...that could initiate it.
But nothing can call the keyup can it? I guess the roku remote is smart enough to know when you lift your finger off the key, but most remotes do not recognize that action and send another command.

Any ideas on how this could be implemented? Or did you not implement it because you couldn't see a way?

thanks.

bengalih
Posts: 48
Joined: Sat Feb 25, 2012 1:13 am

Re: Roku and Now TV network control plugin

Post by bengalih » Thu Sep 17, 2015 9:04 pm

Ok - I've found a way to get the keydown/keyup events working.

There are two parts to this:

1) Change to the plugin. I needed to add Keydown and Keyup actions to each of the 4 directional buttons and add some logic to the msg handler. I cloned the main send_key function to make a send_keydown and send_keyup to facilitate these. Adding the capability to the script wasn't rocket science, but I'm not very familiar with python so there was probably a more graceful way then cloning the functions. I've attached my update script here (v.0.2.1).
__init__.py
Updated RokuNet plugin (0.2.1)
(20.32 KiB) Downloaded 127 times
2) With some guidance from here I was able to figure out a way to emulate the keyup events that the native Roku remote recognizes.

The basic idea is that we use a jump on long keypress of a direction to a macro that issues the keydown event on the same direction.
This then jumps to another (shared) macro which begins a timer that continues to reset/abort itself as long as the button remains held.
As soon as you release the button, the timer completes and sends a finish even in the form of EVENT_up.
This event then triggers the corresponding keyup event to be sent.

The end result is a nice fluid scroll just like the roku remote - with one exception: The roku interprets the keydown even as just that, a keydown, not a keypress and then keydown.
Because we use the standard keydown and then long keypress there will be a small stutter as it begins it's keydown. This is barely noticeable however.
There may be a clever way around this with using ONLY keyup/down events and EG logic, but I haven't figured it yet.
(Update note: When I transferred this to my production system and coded my remote commands in place of the keyboard presses, there appears to be a slight lag when letting up on the button, such that it takes about one second to STOP the scrolling. I'm going to tweak the values here to see if I can make it more responsive. If anyone has ideas let me know...).

I've included a sample xml that uses the directional arrows as commands - though replacing with you remote commands will probably be necessary.
rokutest.xml
Samhttp://www.eventghost.net/forum/posting.php?mode=reply&f=9&sid=52c00d478da6e2c2104c44ab2d5b02a1&t=5995#tabsple EG file for emulating keydown/up events with Roku plugin
(4.73 KiB) Downloaded 130 times
You'll have to modify the following in the XML to get it to work directly:
1) Modify the serial # of the roku. I set it to "444444444444" so just do a search and replace in the XML.
2) In each of the 4 "RokuNet: DIRECTION" macros you will want to replace the Keyboard.DIRECTION event with the trigger event that your remote generates.
3) In each of the 4 "RokuNet: KeyupDIRECTION" macros you will need to replace the trigger event that the timer responds with from the event your remote generates. It *should* be the same as #2 in the format Timer.EVENT_up.
#3 is a bit convoluted because I use a shared timer. You could create a timer for each one individually in which case you can control the event that gets created explicitly, but then you'd need to manage 4 timers.

I hope that the python code (or equivalent) can be committed to the main plugin. Even if you don't want to use it, it doesn't hurt having it there and allows those who want to get fancy with the EG code like in my sample XML the ability to do so.
Last edited by bengalih on Thu Sep 17, 2015 11:46 pm, edited 1 time in total.

Post Reply