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

I just wanted to thank you for your script !

I'm new to xbmc and linux (coming from MediaPortal on windows..), and i can finally use a similar function which is automate the lights when playing a file (it could be done on MediaPortal with a plugin called Tellstick pause) !!!

But using linux it's even better ! I'll tell you why..

I use a media server for all my files, it runs on windows 7, it can also be a domotic server with a Tellstick attached to it. That's right, my tellstick is not on my XBMC Box (running XBMC Live).

Using xPL protocol and very simple bash scripts i send xpl messages to my server, which control the Tellstick using eventghost (with tellstick and xpl plugin).

Client/Server functionality using 2 OS is great Big Grin

Thanks again !
Reply
#17
Also wanted to thank for the script... never would have figured out how to do that...

By the way: I never receive the Pause and Resume events, anybody getting those?
Reply
#18
I just got a TellStick and I'm trying to get this to work on XBMC 10.0, but without any sucess. Have anyone been able to run this script on the latest version of XBMC? Would really really apreciate some help Smile
Reply
#19
^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
Reply
#20
Hi,

I have used this Thread to create a new (service) Add-on

Check out this link

Thanx for the info that was posted here.
Reply
#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
Reply
#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
Reply
#23
Changed to SwitchKing and EventGhost now, but the guide (http://www.satheesh.net/2012/01/09/xbmc-lights/) also works if you want a simple setup.
Reply
#24
(2015-01-03, 13:21)unknown_inc Wrote: Changed to SwitchKing and EventGhost now, but the guide (http://www.satheesh.net/2012/01/09/xbmc-lights/) also works if you want a simple setup.

I guess that the guide refers to a setup where you have XBMC and Switchking on the same computer, right?
I am looking for a solution where they are on different machines, in the same network. I have tried 5 different options, nothing works.
How do you use Switchking and Eventghost, I am really interested in your solution!!
Reply

Logout Mark Read Team Forum Stats Members Help
Run command (turn lamps on room on/off) on play, pause, stop events?0