HOW-TO Idle detection on XBMC server running squeezecenter - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33) +--- Forum: Tips, tricks, and step by step guides (https://forum.kodi.tv/forumdisplay.php?fid=110) +--- Thread: HOW-TO Idle detection on XBMC server running squeezecenter (/showthread.php?tid=131836) |
HOW-TO Idle detection on XBMC server running squeezecenter - ainsworth - 2012-05-18 Idle detection on XBMC: My server runs a variety of services including XBMC, squeezecenter and a squeezeslave client. I also use it as a file server with my main access being through ssh. I wanted a way to shutdown the server down after being idle for a set time period but couldn't see any easy way of doing this as these services don't talk to each other. After researching many forums I decided to just write my own python script and run it as an upstart service. I'm not a programmer so the code is not pretty, however it does work. I thought it might be useful to others so have posted it here. If anyone has any improvements or suggestions please post below. How it works: I set my xbmc to display a screensaver after 2 minutes of inactivity. The screen saver is a slideshow of fanart in /home/username/Fanart. The script checks if xbmc is playing anything from this folder and hence detects if the screensaver is running. The reason for not using the proper xbmc fanart folder is to avoid false positives during normal use of the menus, though the risk of this happening is small. The script also connects to squeezecenter and checks each player in turn to see if they are paused or stopped. If all players are inactive squeezecenter is considered idle. Note that squeezeboxes being powered on doesn't constitute activity in the below code, however this can easily be changed. Additionally, if the file /home/username/nosleep exists the script won't shutdown the computer. The script then checks to see if any ssh connections are currently open. If there are any established connections then shutdown will be prevented. The script will do the above checks every 30 seconds. Once all systems have been idle for 20 minutes the server will be shutdown. There's no reason that the code couldn't suspend or hibernate instead of shutdown. Those functions simply don't work on my system which is why I call the shutdown command. Installation: Copy the below code into a file called idle.py. Save this in your home directory (if you save it elsewhere you'll need to modify the upstart config file). Code: #!/usr/bin/python The above code requires modification to get it working on your system: Replace all instances of username with your username. Replace MAC addresses as appropriate for your hardware. Modify the paths for logging, fanart location and no_sleep to suit your system. Optional Change the timers to suit. Note these are measured in seconds, not minutes. Next create a the file /etc/init/idle.conf and paste the following into it. Code: # Idle detection This will start the script 60 seconds after boot. You don't want it starting too quickly as the code requires the network to be active. It will exit if it looses the network. Usage: To check if the script is running ok type: Code: sudo service idle status This should return something like Code: idle start/running, process 1896 To monitor what the script is up to the following can be used: Code: tail -f /home/username/idlelog RE: HOW-TO Idle detection on XBMC server running squeezecenter - KeithLM - 2012-05-29 This is very interesting. I just started working with squeezeslave this past week. I'm setting up a second system in my house and will be running XBMC and squeezeslave on it. I was using a squeezebox for music in that room, but for various reasons I want to eliminate that as a source and just use the PC. Today I worked through getting the audio configuration right and getting the auto-start to work correctly for squeezeslave. Now I'm wrestling with the issue of whether or not to leave the PC on all the time or put it to sleep. And here I stumbled across this post while looking around for info on the audio settings I needed. One thing you can try for the startup rather than a sleep command is something like the following: Code: start on (starting lightdm and net-device-up IFACE!=lo) Now with mine I'm only running xbmc and squeezeslave, another system is the server and that is always on. Now I'd have to figure out if I could get this to use sleep or hibernate, and then get wake-on-lan to work. I know how to get IR over USB to wake it up, but I would want the PC to respond if music is started with squeezeserver. |