As cool as a Hyperion/boblight/ambilight set up is, sometimes you want to disable the LEDs for whatever reason. You could SSH into your Pi and stop the Hyperion service or just flick the power switch on the LED power supply, but if you’re lazy like me, then you’ll probably want an even easier way to perform this task!
How about a single button press on your remote control to toggle the Hyperion service?
It’s actually pretty simple, first create a bash script which checks if the service is running. If it is, it disables it, if not it will enable it.
#!/bin/bash if [ `sudo /sbin/initctl status hyperion | grep running | wc -l` = 1 ] then curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"id":1,"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"Hyperion","message":"Disabled","image":"/home/pi/hyperion.png"}}' http://127.0.0.1:8080/jsonrpc sudo /sbin/initctl stop hyperion else curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"id":1,"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"Hyperion","message":"Enabled","image":"/home/pi/hyperion.png"}}' http://127.0.0.1:8080/jsonrpc sudo /sbin/initctl start hyperion fi
Save the above script as /home/pi/toggleHyperion.sh and make it executable:
chmod +x /home/pi/toggleHyperion.sh
Next you need to modify your remote.xml config:
nano /home/pi/.xbmc/userdata/keymaps/remote.xml
Add this line somewhere between the < global > and < / global > tags:
<blue>XBMC.System.Exec("/home/pi/toggleHyperion.sh")</blue>
In my case I assigned the script to the blue button. You can obviously assign it to whichever button you want.
Finally, copy the Hyperion icon to your home folder (this image is used for the notification within XBMC):
wget http://pibob.nadnerb.co.uk/images/hyperion.png -o /home/pi/hyperion.png
Edit – Just realised you may need to install curl if you don’t have it already – this is what’s used to send the popup notification to XBMC.
sudo apt-get install curl
Then reboot your Pi.
With any luck, pressing the blue button will turn off your LEDs and display a notification in XBMC. Pressing again should switch your LEDs on.
If it’s not working, check your xbmc http server is running on port 8080.
Enjoy 🙂
On my raspberry pi 2, your script didnt work with osmc.
I change for that :
#!/bin/bash
PROCESS_NUM=`pgrep hyperiond | wc -l`
if [ $PROCESS_NUM -eq 1 ]
then
curl -v -H “Accept: application/json” -H “Content-type: application/json” -X POST -d ‘{“id”:1,”jsonrpc”:”2.0″,”method”:”GUI.ShowNotification”,”params”:{“title”:”Hyperion”,”message”:”Disabled”,”image”:”/home/osmc/hyperion.png”}}’ http://127.0.0.1:8080/jsonrpc
sudo service hyperion stop
else
curl -v -H “Accept: application/json” -H “Content-type: application/json” -X POST -d ‘{“id”:1,”jsonrpc”:”2.0″,”method”:”GUI.ShowNotification”,”params”:{“title”:”Hyperion”,”message”:”Enabled”,”image”:”/home/osmc/hyperion.png”}}’ http://127.0.0.1:8080/jsonrpc
sudo service hyperion start
fi
This one works for me… Almost.
I only could get it to go ‘enabled’ But it won’t disable… Any thoughts about this?
I have two instances running. Here’s my Hyperion status log:
osmc@osmc:~$ sudo service hyperion status
● hyperion.service – Hyperion Systemd service
Loaded: loaded (/etc/systemd/system/hyperion.service; enabled)
Active: active (running) since wo 2017-01-25 11:06:50 CET; 10min ago
Main PID: 760 (hyperiond)
CGroup: /system.slice/hyperion.service
├─760 /usr/bin/hyperiond /etc/hyperion/hyperion.config.json /etc/hyperion/hyperion.config2.json
└─762 /usr/bin/hyperiond –parent 760 /etc/hyperion/hyperion.config2.json
jan 25 11:06:53 osmc hyperiond[760]: EFFECTENGINE INFO: 27 effects loaded from directory /usr/share/hyperion/effects
jan 25 11:06:53 osmc hyperiond[760]: EFFECTENGINE INFO: Initializing Python interpreter
jan 25 11:06:53 osmc hyperiond[760]: INFO: Hyperion started and initialised
jan 25 11:06:53 osmc hyperiond[760]: INFO: Json server created and started on port 19446
jan 25 11:06:53 osmc hyperiond[760]: INFO: Proto server created and started on port 19447
jan 25 11:06:53 osmc hyperiond[760]: EFFECTENGINE INFO: effect finished
jan 25 11:06:55 osmc hyperiond[760]: PROTOSERVER INFO: New connection
jan 25 11:06:55 osmc hyperiond[760]: BLACKBORDER INFO: threshold set to 0.01 (3)
jan 25 11:06:55 osmc hyperiond[760]: BLACKBORDER INFO: mode:default
jan 25 11:06:55 osmc hyperiond[760]: PROTOCONNECTION INFO: Connected to Hyperion: 127.0.0.1:19447
jan 25 11:07:06 osmc systemd[1]: Started Hyperion Systemd service.
jan 25 11:08:42 osmc systemd[1]: Started Hyperion Systemd service.
jan 25 11:08:50 osmc systemd[1]: Started Hyperion Systemd service.
jan 25 11:08:56 osmc systemd[1]: Started Hyperion Systemd service.
jan 25 11:14:49 osmc systemd[1]: Started Hyperion Systemd service.
Ok, found out that ‘pgrep hyperiond’ had an output greater than ‘1’.
So I edit the code with just changing the -eq argument to -ge.
So my script looks like this now:
#!/bin/bash
PROCESS_NUM=`pgrep hyperiond | wc -l`
if [ $PROCESS_NUM -ge 1 ]
then
curl -v -H “Accept: application/json” -H “Content-type: application/json” -X POST -d ‘{“id”:1,”jsonrpc”:”2.0″,”method”:”GUI.ShowNotification”,”params”:{“title”:”Hyperion”,”message”:”Disabled”,”image”:”/home/osmc/hyperion.png”}}’ http://127.0.0.1:8080/jsonrpc
sudo service hyperion stop
else
curl -v -H “Accept: application/json” -H “Content-type: application/json” -X POST -d ‘{“id”:1,”jsonrpc”:”2.0″,”method”:”GUI.ShowNotification”,”params”:{“title”:”Hyperion”,”message”:”Enabled”,”image”:”/home/osmc/hyperion.png”}}’ http://127.0.0.1:8080/jsonrpc
sudo service hyperion start
fi
“pgrep hyperiond” is all the time greatest to 1 because it’s a PID. But normaly “pgrep hyperiond | wc -l” is equal to 1. If it’s more than 1 you have another process running. Check with the “top” command.
I have two instances of Hyperion running. One for the backlight and on for the ‘surround’ AtmoOrbs. So, I think that’s the issue I have.
Indeed if you run at the same time hyperion backlight and AtmoOrbs this is normal.
-ge 1 is s more appropriate 🙂
I have a problem with Hyperion (and boblight when I used that) that meant I’d get the odd pixel coming on and changing colour, so I prefer to just set the colour to black (000000) and then unset it again to allow hyperion to display colour as normal during playback. Sadly you can’t check the current colour of hyperion, so I’m stop/starting the daemon with a slightly modified version of the script (it’s on osmc).
My next plan is to stop controlling the WS2801’s directly from the pi using SPI and move it to an arduino, and failing that switch the led power off using a relay. On another note, as I use Yatse as a remote for Kodi I’ve setup a custom command to toggle Hyperion ‘on’ and ‘off’ – it took me a while to figure out that you just use ‘Blue’, it had to be capitalised like that to work.
Thanks for making me make my tv (and room) more colourful 🙂