Run command (turn lamps on room on/off) on play, pause, stop events?

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
eldo Offline
Junior Member
Posts: 5
Joined: Jul 2011
Reputation: 0
Post: #21
I finally have my Telldus light automation working as I want:

Turn lights to 100% when xbmc is started

When video is playing, turn light to 0%
When video is paused, turn lights to 50%
When video is stopped, turn lights to 100%
(Lights are not dimmed when playing music)

When xbmc is idle for 15 mins, turn lights to 0%
When xbmc is no longer idle, turn lights to 100% - except if video is playing then don't do anything



I use three scripts:

/home/username/.xbmc/userdata/autoexec.py

Code:
import os, xbmc

os.system("tdtool -v 255 -d 1")
xbmc.sleep(1000)
xbmc.executescript('special://home/scripts/playeractions.py')
xbmc.sleep(1000)
xbmc.executescript('special://home/scripts/idletime.py')


/home/username/.xbmc/scripts/playeractions.py

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()

VIDEO = 0

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

      else:
        VIDEO = 0

    xbmc.sleep(1000)


/home/username/.xbmc/scripts/idletime.py

Code:
import xbmc,xbmcgui
import subprocess,os

    
ILT = 0
IDLE_TIME_MIN = 15
s = 0

while(1):
  it = xbmc.getGlobalIdleTime()
  s = ((IDLE_TIME_MIN * 60) - it )
  if (s > 0):
    if (ILT == 1):
      if xbmc.Player().isPlayingVideo():
        pass
      else:
        os.system("tdtool -v 255 -d 1")
        ILT = 0

  elif (s < 0):
    if (ILT == 0):
      os.system("tdtool -v 0 -d 1")
      ILT = 1
xbmc.sleep(1000)


These scripts solve all the problems that I mentioned in my previous post above. The main one was that the VIDEO variable used to be constantly checked and so if the video was paused then stopped, the lights would not come back to 100%. This was solved by only setting VIDEO when something is actually playing.


The hardware I use is the Telldus Tellstick and the COCO AFR-100 (also sold as the KlikAanKlikUit AFR-100). The scripts assume that you have the Tellstick installed correctly, with the AFR-100 having the device ID of 1.

You could also extend the scripts by adding a second lamp (as I intend to do) by simply adding the dimming actions for the second device into the script.

Thanks to many posts on this forum which allowed me to hack together these scripts, while being a complete novice to scripting and Python.
I spent many months wanting this setup and almost getting there, so I hope others who want XBMC light automation can use these scripts to create their setups.

Cheers
eldo
(This post was last modified: 2011-11-13 09:41 by eldo.)
find quote
unknown_inc Offline
Junior Member
Posts: 28
Joined: Oct 2010
Reputation: 0
Post: #22
I finally found a guide that works like a charm using my TellStick (even in Eden). Look here:

http://www.satheesh.net/2012/01/09/xbmc-lights/

Wink
find quote
Post Reply