Install Hyperion on OSMC
First we need to install some packages
sudo apt-get update && apt-get dist-upgrade && apt-get install git libqtcore4 libqtgui4 libqt4-network libusb-1.0-0 libprotobuf9 ca-certificates
Download Hyperion:
wget -N https://raw.github.com/tvdzwan/hyperion/master/bin/install_hyperion.sh
This may fail when your systemtime is not correct! check time with:
date
Now install hyperion
sh ./install_hyperion.sh
Put hyperion.config.json in /etc
Enable GPIO’s:
vi /boot/config.txt
add the next line
dtparam=spi=on
This should work, now if you want extra button continue reading.
\
\
Exta buttons on remote to control lights / change static colour
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
We remove the hyperion symoblic link at
/etc/init.d
Next we create hyperion.service file and put that 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