1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Control Hyperion through a small web server

Discussion in 'Hyperion General' started by milhouse, 19 May 2018.

  1. milhouse

    milhouse New Member

    Messages:
    8
    Hardware:
    RPi3
    Looked all over for a way to control Hyperion through a web call, primarily so I could control from WebCore in SmartThings. It can't send raw TCP. Could find anything, so rolled my own. Thought I'd share in case in helps anyone else.

    1) Add a couple python modules on your Raspi that runs hyperion.

    pip install bottle
    pip install bottledaemon

    2) The python script that runs the web server and add endpoints for color and effects:

    from bottledaemon import daemon_run
    from bottle import route, run, template
    import subprocess


    @route('/color/<colorid>')
    def index(colorid):
    subprocess.check_output(['/usr/bin/hyperion-remote', '--color', colorid])
    return "done"

    @route('/effect/<effectname>')
    def index(effectname):
    subprocess.check_output(['/usr/bin/hyperion-remote', '--effect', effectname])
    return "done"

    @route('/clearall')
    def index():
    subprocess.check_output(['/usr/bin/hyperion-remote', '--clearall'])
    return "done"

    if __name__ == "__main__":
    daemon_run(host="0.0.0.0", port="8080")

    3) Start the python script using nohup so you can close your connection and it keep running.

    nohup /usr/bin/python /home/pi/Documents/hyperionweb.py start

    4) make a standard http request to control.

    http://192.168.2.71:8080/effect/Cold mood blobs
    http://192.168.2.71:8080/color/ff0000
    http://192.168.2.71:8080/clearall



    Hopefully this is useful to someone. And hopefully I didn't overlook something completely obvious and do it the hard way.

    milhouse
     
  2. milhouse

    milhouse New Member

    Messages:
    8
    Hardware:
    RPi3
    Can I insert a code block so the python code isn't reformatted? It lost all the indents, and python really cares about that.
     
  3. mrl72

    mrl72 New Member

    Messages:
    6
    Hardware:
    RPi3
    Thanks for this was looking for the exact thing when time permits.

    So in webcore I know you can call a URL using post/get or JSON. Is this what you did?
     
  4. milhouse

    milhouse New Member

    Messages:
    8
    Hardware:
    RPi3
    You got it. I use a random expression so it's one of several effects. Make a web request, GET method, type JSON, no header or authorization. Obviously this is all inside my LAN.

    Make a GET request to {"http://192.168.2.71:8080/effect/" + random("Cold%20mood%20blobs","Full%20color%20mood%20blobs","Warm%20mood%20blobs","Rainbow%20swirl")} with type JSON;
     
  5. mrl72

    mrl72 New Member

    Messages:
    6
    Hardware:
    RPi3
    I finally got around to trying this but I'm running OpenElec and looks like you can't install much in this OS. Is there any other solution to making remote requests to Hyperion via URL?