Ambient tv lighting

I have finally added the ambient lighting behind the tv that I have wanted for ages (at least since removing the manual kind years ago).

I found a script here that I modified to suit my needs;

#!/usr/bin/python
# lights.py

import xbmc
import subprocess,os

class MyPlayer(xbmc.Player) :

def __init__ (self):
xbmc.Player.__init__(self)

def onPlayBackStarted(self):
if xbmc.Player().isPlayingVideo():
os.system("curl --silent 'http://10.16.3.2/home/index.php?sw=23&state=1'")

def onPlayBackEnded(self):
if (VIDEO == 1):
os.system("curl --silent 'http://10.16.3.2/home/index.php?sw=23&state=0'")

def onPlayBackStopped(self):
if (VIDEO == 1):
os.system("curl --silent 'http://10.16.3.2/home/index.php?sw=23&state=0'")

def onPlayBackPaused(self):
if xbmc.Player().isPlayingVideo():
os.system("curl --silent 'http://10.16.3.2/home/index.php?sw=23&state=0'")

def onPlayBackResumed(self):
if xbmc.Player().isPlayingVideo():
os.system("curl --silent 'http://10.16.3.2/home/index.php?sw=23&state=1'")

player=MyPlayer()

while(1):
if xbmc.Player().isPlayingVideo():
VIDEO = 1

else:
VIDEO = 0

xbmc.sleep(3000)
This seems to be a very popular script so I really have no idea where it originally came from. A couple of notes, in openelec the python library xbmcgui is unavailable. The xbmc.sleep function in the end counts milliseconds, not seconds.

After sticking this in /storage/.xbmc/userdata (once again, I run openelec) on the media center I added it to autostart.sh in /storage/.config (many sources says autoexec.py but that is deprecated in favor of autorun.sh in XBMC Eden) and now the lights turn on when video plays and of when paused or stopped.

On the receiving end a script checks if the sun is up and if not turns the light on.
I might extend this more in the future, but for now it integrates just fine as is.

As a side note; except for the for the code parts I wrote this post in the android wp app and it actually works quite well..

Share

2 thoughts on “Ambient tv lighting

  1. Alex Bergsland

    Hello, you say you are running this on OpenElec?
    What else have you done to make it work?
    I used to have a script (from the source you linked to) when I was running XBMC from Ubuntu on my Xtreamer Ultra.
    I think the script was sending commands to TelldusCore or something like that, an application in Ubuntu.
    But XBMC was to slow and I switched to OpenElec wich runs better but I didnt think it was possible to controll Telldus products from it.

    http://10.16.3.2/home/index.php?sw=23&state=0
    Is that your own server running something?

    I am using a Tellstick Net at the moment but I still have my Tellstick.

    What else do I need to do to get this going in OpenElec?

    /Alex (från Strängnäs)

  2. henrik Post author

    @Alex Bergsland
    This is on OpenElec and the IP address in the request is a FreeBSD server here at home that does the work with the Tellstick. It basically just parses the request and runs tdtool on or off for lights, except for the lights behind the tv where it runs another wrapper I’ve made which only turns them on after sunset.
    Since the only thing being done on the OpenElec in my setup is a web request this requires another computer for it to work. I’m not sure if the Tellstick Net can be made to work this way.

    Tog det på engelska eftersom det kompletterade posten så pass mycket. Säg gärna till om du undrar över mer!

Leave a Reply

Your email address will not be published. Required fields are marked *