Author Topic: Control Roku with http commands  (Read 9042 times)

0 Members and 1 Guest are viewing this topic.

jmpal32

  • $upporter
  • Jr. Member
  • *****
  • Posts: 4
  • Karma: 0
    • View Profile
Control Roku with http commands
« on: May 14, 2015, 09:50:15 AM »
Is there a way to control the roku box just like the roku remote app does using api commands.
Sorry I am new at this

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Control Roku with http commands
« Reply #1 on: May 14, 2015, 10:05:47 AM »
Maybe. If they have a RESTful api or you can find examples online of http get/post requests for the Roku, you can try them using VC's various scrape actions.

If you know your Roku's IP address, you could enter it in the command below where indicated, and try the following command.

e.g. Say one of the following: Go home; go right; go left; go up; go down; go back; Roku select; Roku play

(This is based on a super quick search I did, so it's a giant shot in the dark.)

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.5-->
<command id="775" name="Go {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape.Post</cmdType>
    <params>
      <param>http://YOUR_ROKU_IPADDRESS:8060/keypress/{1}</param>
      <param />
      <param />
      <param />
      <param>text/html</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{1}.</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Go, Roku</phrase>
  <payloadList>Home, Left, Right, Down, Up, Back, Play, Select</payloadList>
</command>
« Last Edit: May 14, 2015, 01:59:52 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

OklahomaGreyBeard

  • Contributor
  • ***
  • Posts: 54
  • Karma: 3
    • View Profile
Re: Control Roku with http commands
« Reply #2 on: May 14, 2015, 11:36:58 AM »
I control my living room Roku with VC. I'm able to say switch the living room roku to plex, pandora, netflix, etc. Then I have a group I can enable by saying enable/disable roku controls, then go up go left, select etc.

This is all done by sending events to EventGhost which has a Roku plugin and letting it handle the actual controlling the Roku.

But to be honest after setting all up I found I only use it for selecting the roku channel. The up down etc is easier to grab the remote. It is nice though when you can't find the remote.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Control Roku with http commands
« Reply #3 on: May 14, 2015, 11:45:32 AM »
Thanks. Since you have a Roku, maybe you can test the command I posted above.

I'm not a big fan of using VC for just basic navigation either, but it's an easy first step to knowing what works or doesn't.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

OklahomaGreyBeard

  • Contributor
  • ***
  • Posts: 54
  • Karma: 3
    • View Profile
Re: Control Roku with http commands
« Reply #4 on: May 14, 2015, 12:54:49 PM »
It doesn't seem to work but then again my Roku is currently playing Game of Thrones and I'm liable to get strung up if it did pause... I'll take a look at it later tonight when I get back home.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Control Roku with http commands
« Reply #5 on: May 14, 2015, 01:19:10 PM »
Just realized I forgot the Content-Type header, so I've edited the command above. Looking at the Eventghost plugin's python, that's really the only difference I can see off-hand.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

OklahomaGreyBeard

  • Contributor
  • ***
  • Posts: 54
  • Karma: 3
    • View Profile
Re: Control Roku with http commands
« Reply #6 on: May 14, 2015, 01:42:28 PM »
Can't compile grammar into cfg is what I get when I try to save and close the editor now.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Control Roku with http commands
« Reply #7 on: May 14, 2015, 01:59:19 PM »
Sorry, my hasty multitasking is making me do stupid things.

When you have time, can you please delete that command, restart VC, then try the fresh version I am about to post above to replace the bad version?
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

OklahomaGreyBeard

  • Contributor
  • ***
  • Posts: 54
  • Karma: 3
    • View Profile
Re: Control Roku with http commands
« Reply #8 on: May 14, 2015, 02:22:30 PM »
Works exactly as it should. Now I really do need to go get something to eat  :bonk

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Control Roku with http commands
« Reply #9 on: May 14, 2015, 03:56:52 PM »
Great. Thanks for your help.

If I have the energy tonight when I'm finished work I'll look into what's possible/more interesting with the Roku.

Maybe it's possible to scan  and play titles directly. Probably that will be difficult to get right without an actual Roku on hand.

If you have a Roku model that has the Roku search function, you can try the following command to search for a particular title. There are 2 actions where the Roku's IP address is required.

If I understand how Roku's search function works, this should pull up the search box and then start typing the title you've asked for. Then you can use the other Go right/Go down/Roku select command to choose the title of interest from the list that appears. However, it may not like how quickly we're passing the letter characters in the command. I can adapt the command based on feedback.

But others should feel free to pitch in too, of course!

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.6-->
<command id="791" name="Search for {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape.Post</cmdType>
    <params>
      <param>http://YOUR_ROKU_IPADDRESS:8060/keypress/search</param>
      <param />
      <param />
      <param />
      <param>text/html</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>VC.Pause</cmdType>
    <params>
      <param>1000</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>(.)</param>
      <param />
      <param>{1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Scrape.Post</cmdType>
    <params>
      <param>http://YOUR_ROKU_IPADDRESS:8060/keypress/Lit_{Match.1.{i}}</param>
      <param />
      <param />
      <param />
      <param>text/html</param>
    </params>
    <cmdRepeat>{#M}</cmdRepeat>
  </action>
  <phrase>Search Roku for</phrase>
  <payloadDictation>payloadDictation: Regular</payloadDictation>
</command>

This command uses payload dictation so it won't work with the SP version of VC.

I've included a 1 second pause between action that should call up the search box and the typing action, because I don't know how slow the Roku is to load pages.

If the command seems to work but you need longer or less time to display the search field, just change the VC.Pause length.

over and out.
« Last Edit: May 14, 2015, 04:02:22 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

PegLegTV

  • $upporter
  • Sr. Member
  • *****
  • Posts: 497
  • Karma: 43
    • View Profile
Re: Control Roku with http commands
« Reply #10 on: May 14, 2015, 06:18:10 PM »
Based off of what nime5ter shared above here are a couple more commands to test out

you will have to add your Roku IP address to each action

the first action should create RokuChannel.xml payload in your payload folder and then you should be able to launch your channels by name

the 2 bottom commands (Scroll direction (experimental), Stop Scrolling (experimental)) are a test to see if that will scroll for you if not we can try and use the loop function to scroll by voice

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.5-->
<commandGroup open="True" name="Roku Control" enabled="False" prefix="" priority="0" requiredProcess="" description="">
  <command id="895" name="create RokuChannel.xml" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Scrape.Get</cmdType>
      <params>
        <param>http://YOUR_ROKU_IPADDRESS:8060/query/apps</param>
        <param />
        <param />
        <param />
        <param>text/html</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegEx</cmdType>
      <params>
        <param>="(.*?)"\W.*?"&gt;(.*?)&lt;/</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.MatchToXML</cmdType>
      <params>
        <param>payloads\RokuChannel.xml</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Roku update Channel Payload</phrase>
  </command>
  <command id="857" name="Launch Roku Channel" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Scrape.Post</cmdType>
      <params>
        <param>http://YOUR_ROKU_IPADDRESS:8060/launch/{1}</param>
        <param />
        <param />
        <param />
        <param>text/html</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Launch Roku Channel</phrase>
    <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\RokuChannel.xml</payloadFromXML>
  </command>
  <command id="777" name="Fast forward, Rewind" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)==(B)</ifType>
      <ifParams>{1}&amp;&amp;Rewind</ifParams>
      <then>
        <action>
          <cmdType>Scrape.Post</cmdType>
          <params>
            <param>http://YOUR_ROKU_IPADDRESS:8060/keypress/Rev</param>
            <param />
            <param />
            <param />
            <param>text/html</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>Scrape.Post</cmdType>
          <params>
            <param>http://YOUR_ROKU_IPADDRESS:8060/keypress/Fwd</param>
            <param />
            <param />
            <param />
            <param>text/html</param>
          </params>
          <cmdRepeat>01</cmdRepeat>
        </action>
      </else>
    </if>
    <phrase>Roku</phrase>
    <payloadList>Fast Forward, Rewind</payloadList>
  </command>
  <command id="784" name="Instant Replay" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Scrape.Post</cmdType>
      <params>
        <param>http://YOUR_ROKU_IPADDRESS:8060/keypress/InstantReplay</param>
        <param />
        <param />
        <param />
        <param>text/html</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Roku Instant Replay</phrase>
  </command>
  <command id="867" name="Scroll direction (experimental)" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Scrape.Post</cmdType>
      <params>
        <param>http://YOUR_ROKU_IPADDRESS:8060/keydown/{1}</param>
        <param />
        <param />
        <param />
        <param>text/html</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>RokuDirection</param>
        <param>{1}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Roku Scroll </phrase>
    <payloadList>Right, Left, Up, Down</payloadList>
  </command>
  <command id="882" name="Stop Scrolling (experimental)" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="{Var.RokuDirection} is a Variable that is set in the &quot;Scroll Direction (experimental)&quot;  command ">
    <action>
      <cmdType>Scrape.Post</cmdType>
      <params>
        <param>http://YOUR_ROKU_IPADDRESS:8060/keyup/{Var.RokuDirection}</param>
        <param />
        <param />
        <param />
        <param>text/html</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Roku Stop Scrolling </phrase>
  </command>
</commandGroup>


I no longer have a Roku so I Can't test the commands either, so you will have to let us know what works and what doesn't

« Last Edit: May 15, 2015, 09:25:13 PM by PegLegTV »

PegLegTV

  • $upporter
  • Sr. Member
  • *****
  • Posts: 497
  • Karma: 43
    • View Profile
Re: Control Roku with http commands
« Reply #11 on: May 14, 2015, 07:27:28 PM »
I noticed a Mistake I Made in the "create RokuChannel.xml" command It should be Scrape.Get not Scrape.Post you can either change that one action to Scrape.Get or use the updated group above

OklahomaGreyBeard

  • Contributor
  • ***
  • Posts: 54
  • Karma: 3
    • View Profile
Re: Control Roku with http commands
« Reply #12 on: May 15, 2015, 12:38:05 AM »
Almost on the scrape channel command. It scraped 13535" type="appl" version="3.1.4 for my plex channel and obviously threw an error. I edited it to just 13535 and it launched fine. This is how I was loading them myself but adding the channel numbers manually. The scrape function would be a great help but I need to spend more time in regex to figure it out myself..

PegLegTV

  • $upporter
  • Sr. Member
  • *****
  • Posts: 497
  • Karma: 43
    • View Profile
Re: Control Roku with http commands
« Reply #13 on: May 15, 2015, 01:10:59 AM »
if you run the command below it will output ROKUappSCRAPE.txt to your VC folder then just copy and paste the text on here and I can see what i can find on the regex, or you can PM it to me as well


you'll need to add your Roku IP like the other commands
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.5-->
<command id="854" name="create ROKUappSCRAPE.txt" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape.Get</cmdType>
    <params>
      <param>http://YOUR_ROKU_IPADDRESS:8060/query/apps</param>
      <param />
      <param />
      <param />
      <param>text/html</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>File.Append</cmdType>
    <params>
      <param>{Path.VC}\ROKUappSCRAPE.txt</param>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Scrape Roku Apps</phrase>
</command>

PegLegTV

  • $upporter
  • Sr. Member
  • *****
  • Posts: 497
  • Karma: 43
    • View Profile
Re: Control Roku with http commands
« Reply #14 on: May 15, 2015, 01:59:52 AM »
if the output text I found online is correct then this one should do the trick

Delete "create RokuChannel.xml" command that you have in your tree and then replace the command with the one below and give it a try

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.5-->
<command id="835" name="create RokuChannel.xml" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape.Get</cmdType>
    <params>
      <param>http://YOUR_ROKU_IPADDRESS:8060/query/apps</param>
      <param />
      <param />
      <param />
      <param>text/html</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>="(.*?)"\W.*?"&gt;(.*?)&lt;/</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.MatchToXML</cmdType>
    <params>
      <param>payloads\RokuChannel.xml</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Roku update Channel Payload</phrase>
</command>

also did the other commands work for you especially the Scroll commands?