Author Topic: Send http commands to Roku  (Read 2598 times)

Offline homeuser

  • Jr. Member
  • **
  • Posts: 61
  • Karma: +2/-0
Send http commands to Roku
« on: March 14, 2016, 10:46:30 pm »
I am running a scene at 8pm that tells my toddler it is time to take a bath via imperihome and dims the lighting around the house automatically. I would also like the scene to launch the pandora app on my Roku stick that is connected to my home theater system (to play calming lullabies). I think it can be done by sending an http post command but I don't know how to do that in Vera and couldn't find anything in the forums.

Any ideas how I should go about doing that?


https://sdkdocs.roku.com/plugins/servlet/mobile#content/view/1611563

http://forums.roku.com/viewtopic.php?p=222116&sid=7e46a77eccf73274c49191335eac4403

Offline integlikewhoa

  • Master Member
  • *******
  • Posts: 5593
  • Karma: +154/-372
Re: Send http commands to Roku
« Reply #1 on: March 14, 2016, 11:00:59 pm »
I am running a scene at 8pm that tells my toddler it is time to take a bath via imperihome and dims the lighting around the house automatically. I would also like the scene to launch the pandora app on my Roku stick that is connected to my home theater system (to play calming lullabies). I think it can be done by sending an http post command but I don't know how to do that in Vera and couldn't find anything in the forums.

Any ideas how I should go about doing that?


https://sdkdocs.roku.com/plugins/servlet/mobile#content/view/1611563

http://forums.roku.com/viewtopic.php?p=222116&sid=7e46a77eccf73274c49191335eac4403

Sending Http in vera is easy, but what the Http to send to roku to have it do what you want I don't know without reading.

To send http in Vera use a scene and advanced and send lua.

In the lua box use the following.
luup.inet.wget("XXXXXXXX")

Replace only the X's with your ip address of the roku and rest of the http command. Leave the "" and the rest.

Offline homeuser

  • Jr. Member
  • **
  • Posts: 61
  • Karma: +2/-0
Re: Send http commands to Roku
« Reply #2 on: March 15, 2016, 09:29:23 pm »
Thanks for the tip. I created a manually triggered scene to test the code. Vera dashboard says success but nothing happens on the Roku.


This is from the Roku sdk site:
Quote
The following command simulates a user hitting the "Home" button

$ curl -d '' http://192.168.1.134:8060/keypress/home



This is what I have in my luup code

luup.inet.wget("http://xxx.xxx.x.xx:8060/launch/28")



This is an example on the sdk of how to get the icon for the app and when I run it in my browser with my ip and app it returns the Pandora channel icon so I know I have the correct ip and app I'd number.

Quote
7. This following command will return the icon for the channel with id 12 (Netflix). The response will be raw binary picture data after http headers including one with the MIME type of the picture data.

$ curl 'http://192.168.1.134:8060/query/icon/12' > img.png

Edit: The following code works from terminal - $ curl -d '' http://xxx.xxx.x.xx:8060/launch/28
When I use
Code: [Select]
luup.inet.wget(" curl -d '' http://xxx.xxx.x.xx:8060/launch/28") in Vera, I get a success message but nothing happens on the Roku
« Last Edit: March 15, 2016, 09:38:45 pm by homeuser »

Offline SteveZ

  • Sr. Member
  • ****
  • Posts: 328
  • Karma: +4/-1
Re: Send http commands to Roku
« Reply #3 on: March 15, 2016, 10:02:35 pm »
here try this, it works for me

Code: [Select]
local http = require "socket.http"
local ltn12 = require "ltn12"
local util = require "util"
    http.timeout = 5
    local  body, code, headers, status = http.request {
        method = "POST",
        url = "http://192.168.1.64:8060/launch/12",
        source = ltn12.source.string(reqbody),
        headers =
                {
                        ["Connection"] = "Close",
                        ["Content-Type"] = "application/x-www-form-urlencoded",
a                },
        sink = ltn12.sink.table(respbody)

    }


Offline homeuser

  • Jr. Member
  • **
  • Posts: 61
  • Karma: +2/-0
Re: Send http commands to Roku
« Reply #4 on: March 15, 2016, 11:17:12 pm »
Thank you for the code.


I was searching around before I saw your reply and found the os.execute command on a thread about sending commands to Foscams and thought I'd give it a shot and it seems to be working.

Quote
os.execute(" curl -d '' http://xxx.xxx.x.xx:8060/launch/28?contentID=3071195633120312883")

the contentID=x allows you to launch specific stations. I just copied the number on the end of the pandora url in a desktop browser. For my dinner scene it can automatically launch a dinner music station and my bath time scene can launch a sleepy music station. I could see this also being beneficial for launching different Pandora stations with one button with the imperihome app.

Thanks SteveZ for taking the time to share your code. If I run into trouble with the above code I will try yours.


Offline homeuser

  • Jr. Member
  • **
  • Posts: 61
  • Karma: +2/-0
Re: Send http commands to Roku
« Reply #5 on: June 26, 2017, 09:23:46 pm »
The latest update to the Pandora app on Roku seems to have broken the ability to launnch specific stations. Vera still launches Pandora on Roku but only plays the last station played.