Script to turn on/off hyperion gives error
#1
Hello,

I used to use raspbmc with hyperion and the following script to enable/disable hyperion with my usb remote:

Code:
import subprocess

hyperionStatus = subprocess.Popen(["/sbin/initctl", "status", "hyperion"], stdout=subprocess.PIPE).communicate()[0]
print "Current status: ", hyperionStatus

if ('running' in hyperionStatus):
        hyperionStatus = subprocess.Popen(["/sbin/initctl", "stop", "hyperion"], stdout=subprocess.PIPE).communicate()[0]
else:
        hyperionStatus = subprocess.Popen(["/sbin/initctl", "start", "hyperion"], stdout=subprocess.PIPE).communicate()[0]
print "New status: ", hyperionStatus

Now im using Openelec and installed hyperion, which works, but the script gives me back an error. I checked the log and this is what it shows:

Code:
20:44:08 T:2732581984   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.OSError'>
                                            Error Contents: [Errno 2] No such file or directory
                                            Traceback (most recent call last):
                                              File "/storage/startstophyperion.py", line 3, in <module>
                                                hyperionStatus = subprocess.Popen(["/sbin/initctl", "status", "hyperion"], stdout=subprocess.PIPE).communicate()[0]
                                              File "./Lib/subprocess.py", line 679, in __init__
                                              File "./Lib/subprocess.py", line 1249, in _execute_child
                                            OSError: [Errno 2] No such file or directory
                                            -->End of Python script error report<--

Now it seems that it can find a file and from the script is probably initctl and i have searched for that file/directory so i could change the path on the script but i can't find it =/

Anyone knows how to fix this error or what change can i try to make on the script to make this work?

Thank you![/quote]
Reply
#2
OpenELEC doesn't use /sbin/initctl (it uses systemd).

Also, because of the read-only file system used by OpenELEC, hyperion has to install it's own startup script in /storage/hyperion/bin/hyperiond.sh which is (normally) called from /storage/.config/autostart.sh.

Not sure if you've followed this procedure, but it appears that in OpenELEC there is no concept of stopping/starting Hyperion - it's always started from the very outset. Maybe you can implement you're own method of stopping/starting Hyperion, that looks straight forward enough.
Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
Reply
#3
Thank you for the reply and explanation! Smile
I followed the instructions on the hyperion github page and it was basicly just a command that does all the work.
I will look into having a way to start-stop hyperion, and also to control the lights because the app doesn't seem to be working with openelec =/ I dont really know about code/scripts ( unfortunately), but if i end up finding a solution i will share it here to anyone that might need it also Smile
Reply
#4
# Milhouse
Hallo, thx for all your support and help in this forum !

I am trying to get the guide to work in order to turn on/off Hyperion on Openelec:
how-to-enabledisable-hyperion-on-openelec-with-remote

Maybe you can help looking/debug this guide ?

I am currently using the latest build #0427 : RPI2

I have followed the guide and have also changed the path from:
<blue>XBMC.System.Exec("/storage/hyperion/hyperionswitch.sh")/blue> to
<blue>XBMC.System.Exec("/storage/hyperion/hyperionswitch.sh")</blue>
but it does not work for me

do you have any suggestions ?
I am trying to upload the log file but i have a problem with the file. I will upload asap.


I am so happy for using your builds of Openelec hence it would be great if we could use this feature

All regards
F
Reply
#5
I know this thread is months old, but since I was looking for this solution and then rolled my own, I figured I'd post it here in case others searched and ended up here as I did.
On OpenELEC, place the following python script (which I'll call 'hyperion_switch.py' below) somewhere that Kodi can access it:
Code:
#!/usr/bin/python
#

import os
import sys
import subprocess
import xbmc

PARAMETER = str(sys.argv[1]).lower()
# xbmc.log('### hyperion_switcher arg=|%s|' % PARAMETER)

if PARAMETER == 'on':
    try:
        op = subprocess.check_output(['/storage/hyperion/bin/hyperiond.sh /storage/.config/hyperion.config.json </dev/null >/dev/null 2>&1 &'], shell=True)
    except subprocess.CalledProcessError as e:
        xbmc.log('### Hyperion ON Exception: %s' % e.output)
    except Exception as e:
        xbmc.log('### Hyperion ON Exception: %s' % e.message)
    else:
        xbmc.log('### Hyperion ON: %s'% op)
elif PARAMETER == 'off':
    try:
        op = subprocess.check_output(['killall hyperiond'], shell=True)
    except subprocess.CalledProcessError as e:
        xbmc.log('### Hyperion OFF Exception: %s' % e.output)
    except Exception as e:
        xbmc.log('### Hyperion OFF Exception: %s' % e.message)
    else:
        xbmc.log('### Hyperion OFF: %s' % op)

Then place the following or something similar in a file called keyboard.xml in /storage/.kodi/userdata/keymaps (replace $PATH_TO_SCRIPT with the path that you placed the .py file in above):
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<keymap>
  <global>
    <keyboard>
        <a mod="alt,ctrl"> XBMC.RunScript (/storage/.kodi/addons/$PATH_TO_SCRIPT/hyperion_switch.py, ON) </a>
        <b mod="alt,ctrl"> XBMC.RunScript (/storage/.kodi/addons/$PATH_TO_SCRIPT/hyperion_switch.py, OFF) </b>
    </keyboard>
  </global>
</keymap>

Here, I am using alt-ctrl-a and alt-ctrl-b but you can use whatever keypresses you want (refer to the wiki: Keymap (wiki))
Reply
#6
I guess this way is more simple ...


Code:
#!/bin/bash

if [ `ps -a hyperion | grep hyperiond | wc -l` = 3 ]
then
    killall hyperiond
else
    /storage/hyperion/bin/hyperiond.sh /storage/.config/hyperion.config.json
fi
Reply

Logout Mark Read Team Forum Stats Members Help
Script to turn on/off hyperion gives error0