At my home, I use a Mi Casa Verde Vera 3 home automation controller to control lights in my house, and I wanted a way to have XBMC automatically control lights for me. By adding a couple Python scripts to XBMC, whenever I start playing a video the lights in my living room turn off, if I pause the video the lights in my living room, kitchen, hallway, and bathroom go to 25% brightness, and when video stops playing, the lights in the living room turn on to full brightness. It also turns on and off my deck lights – no need to waste power when I’m inside watching something. You could modify the script to do the same thing with X10 or INSTEON, pause or resume your torrent or SABnzbd downloads, set a status on your Twitter or Facebook that you’re watching something, set your Google Voice account to Do Not Disturb, or anything else you can think of.
All of the below scripts go in the
~/.xbmc/scripts directory. If you don’t have that directory, create it. If you’re on Windows XP, that directory is under
C:\Documents and Settings\[user]\Application Data\XBMC\scripts and on Windows Vista or 7,
The first script watches XBMC for the state of the video player and launches actions when it changes. It doesn’t do anything if you’re playing music or watching a slide show. Feel free to modify it to cover both Videos and Music by removing
Save it as playeraction.py in the scripts folder mentioned above. You might be asking why I’m using
os.system("wget")? I wanted to test the commands on my shell to make sure they were the right URLs, and I didn’t want to clutter up the script with using urllib2 and implementing error handling if someone was going to use the script with local shell commands.
The next script launches actions when XBMC is idle for more than 15 minutes. I have it set to turn off my TV and Receiver to save power – it immediately powers them back on if I touch any button on the remote.
IDLE_TIME_MIN if you want more or less idle time. Save this script as idletime.py in the scripts directory.
Finally, the scripts will need to be launched by XBMC by including them in
autoexec.py which is under
~/.xbmc/userdata on Mac or Linux, Windows XP is
C:\Documents and Settings\[user]\Application Data\XBMC\userdata and on Windows Vista or 7,
C:\Users\[user]\AppData\Roaming\XBMC\userdata. You probably already have an
autoexec.py but if you don’t, create one.
What this does is launch the two scripts from the default home directory of your master profile. If you’re using multiple profiles you’ll have to modify the
special:// directory to match the other profile.
If you find the above scripts useful, leave a comment with how you’re using them, it might inspire someone!