^You first need to be able to control your lights with the command line before the script will work. Using Ubuntu it would be "tdtool -n 1" if your light was configured as device 1.
Once you can control the lights in this way, you need to insert the contents of the script into the autoexec.py script. On Ubuntu this is located in /home/
user/.xbmc/userdata/autoexec.py
You will need to modify the commands that run when certain actions occur. I can try to help if you need.
Instead of running other scripts from autoexec.py, I just run the commands directly from there. I have a dimming switch, configured as device 1, so my script looks like this:
Code:
import xbmc,xbmcgui
import subprocess,os
class MyPlayer(xbmc.Player) :
def __init__ (self):
xbmc.Player.__init__(self)
def onPlayBackStarted(self):
if xbmc.Player().isPlayingVideo():
os.system("tdtool -v 0 -d 1")
def onPlayBackEnded(self):
if (VIDEO == 1):
os.system("tdtool -v 255 -d 1")
def onPlayBackStopped(self):
if (VIDEO == 1):
os.system("tdtool -v 255 -d 1")
def onPlayBackPaused(self):
if xbmc.Player().isPlayingVideo():
os.system("tdtool -v 100 -d 1")
def onPlayBackResumed(self):
if xbmc.Player().isPlayingVideo():
os.system("tdtool -v 0 -d 1")
player=MyPlayer()
while(1):
if xbmc.Player().isPlayingVideo():
VIDEO = 1
else:
VIDEO = 0
xbmc.sleep(1000)
Hope that helps.
Now I have a question of my own. As you can see in my script above, the lights dim to about 1/2 brightness when paused, then turn off when playback is resumed. This is great, except that if you pause a video, then press stop while paused, the lights do not come back on to full brightness. Is there a way around this?
Also, I'd like to make the lights turn off completely when the screensaver is activated, then when the screensaver is deactivated, to turn back on to whatever level they were at pre-screensaver (if that makes sense!)
I've looked at the python API and I think that this should find out whether the screensaver is on:
xbmc.getCondVisibility('Window.IsActive(12900)')
If that returns true, then the screensaver is active.
EDIT: Could we also use StringCompare(System.CurrentWindow,screensaver)
Not sure if needing to use the window Name (screensaver), window Definition (WINDOW_SCREENSAVER), Window ID (12900) or Delta Window ID (2900) ...?
I'm not a script writer but I imagine the script would go something like this:
Code:
Pre-screensaver dim value=x
Screensaver on now= true/false
Screensaver on last time we checked = true/false
Every 1 second, check if screensaver is on now -
TRUE
~and Screensaver on last time we checked = TRUE - do nothing
~and Screensaver on last time we checked = FALSE - store current dim value in Pre-screensaver dim value, dim lights to 0, change value of 'Screensaver on last time we checked' to True
FALSE
~and Screensaver on last time we checked = FALSE - do nothing
~and Screensaver on last time we checked = TRUE - return lights to Pre-screensaver dim value, change value of 'Screensaver on last time we checked' to False
Could someone please help me translate that into Python? Am I even on the right track with the API call and the script layout?
Many thanks