Skip to content

Installation on OSMC

brindosch edited this page Mar 22, 2016 · 11 revisions

Install Hyperion on OSMC

If you use PWM LEDs (WS281X): Just use the install script with the following command

wget -nv -N https://raw.github.com/tvdzwan/hyperion/master/bin/install_hyperion.sh && chmod +x install_hyperion.sh
sudo sh ./install_hyperion.sh WS281X

If you use SPI LEDs (WS2801, APA102, LPDXXXX, ...: Just use the install script with the following command

wget -nv -N https://raw.github.com/tvdzwan/hyperion/master/bin/install_hyperion.sh && chmod +x install_hyperion.sh
sudo sh ./install_hyperion.sh

Exta buttons on remote to control lights / change static colour

**Note - this will done by install script too, note that it is not possible for users with PWM driven leds (need root for access) **

Make OSMC user boot hyperion instead of sudo/root user

Basic explaination:

Hyperion installer doesnt handle OSMC correctly yet so this is a manual must if you want extra button on the remote to control youre ambilight. Now everytime we boot it automaticly boots as sudo/root user, we dont want that otherwise we cannot use our colourswitch and on/off button button. This is cause the privilleges limitation on the default OSMC user when we let it open automaticly as sudo/root.

Now we need killall for some scripts im using

apt-get install psmisc

Next we change the hyperion.service file in /etc/systemd/system (this wil open hyperion as OSMC user every boot) (below the content of hyperion.service)

[Unit]
Description=Hyperion
[Service]
Type=simple
User=osmc
Group=osmc
UMask=007
ExecStart=/opt/hyperion/bin/hyperiond /etc/hyperion.config.json
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
TimeoutStopSec=10
 
[Install]
WantedBy=multi-user.target

Then we need to start the service in ssh, once

/opt/hyperion/bin/hyperiond /etc/hyperion.config.json

Then we create a new symbolic link

sudo systemctl enable hyperion

After that we copy the colourswitch.py, off.py and switch.py to /home/osmc/hyperion

off.py (one button on my Harmony Remote to kill all lights in the house, including the Hyperion deamon)

import subprocess

pid = subprocess.Popen('pidof hyperiond', shell=True, close_fds=True, stdout=subprocess.PIPE)

try:
    if pid.stdout.readlines():
        subprocess.Popen('killall hyperiond', shell=True)
    else:
        subprocess.Popen('killall hyperiond', shell=True)
except Exception, e:
    pass

switch.py (to turn ambilights on/off and off/on with single button

import subprocess

pid = subprocess.Popen('pidof hyperiond', shell=True, close_fds=True, stdout=subprocess.PIPE)

try:
    if pid.stdout.readlines():
        subprocess.Popen('killall hyperiond', shell=True)
    else:
        subprocess.Popen('/opt/hyperion/bin/hyperiond /etc/hyperion.config.json </dev/null >/dev/null 2>&1 &', shell=True)
except Exception, e:
    pass

colourswitch.py (to get different colours while pusing the same button over and over)

Created on Mar 27, 2015

@author: lukas, nobcat
'''

import json
import subprocess

colors = ['purple',
          'blue',
          'yellow',
          ]

defaultData = {"color":"purple",
               "effect":"night rider"
               }

def read_current():
    try:
        with open('/home/osmc/hyperion/current.json', 'r') as f:
            data = json.load(f)
        f.close()
        if data == '':
            return defaultData
        else:
            return data
    except (IOError, ValueError):
        return defaultData
    
def write_current(data):
    try:
        with open('/home/osmc/hyperion/current.json', 'w') as f:
            json.dump(data, f)
        f.close()
    except IOError:
        pass
    
def parse_current_effect():
    pass

def set_current_effect():
    pass

def set_color(color):
    subprocess.Popen('/opt/hyperion/bin/hyperion-remote --priority 100 --color ' + color, shell=True)

def main():
    current_data = read_current()
    for i,color in enumerate(colors):
        if color == current_data['color']:
            if i == len(colors) - 1:
                current_data['color'] = colors[0]
                break
            else:
                current_data['color'] = colors[i + 1]
                break
        
    write_current(current_data)
    set_color(current_data['color'])
    
main()

Last we define the buttons in remote.xml

<yellow>RunScript("/home/osmc/hyperion/colourswitch.py")</yellow>
<blue>RunScript("/home/osmc/hyperion/switch.py")</blue>
<red>RunScript("/home/osmc/hyperion/off.py")</red>

And put remote.xml on /home/osmc/.kodi/userdata/keymaps

Done!