Philips Hue Light Switches based wakeup



  • Hi,

    i need some help with an Python Script which should wake up the Mirror by pressing the button. I got some Philips Hue Light Switches but have trouble to curl the right data. I think the switch is pretty good for this, because no installation is needed. alt text

    The Script should wake up the Mirror with libcec over HDMI, also turn the LCD off in Standby by pressing the button.

    In the Philips Hue Bridge i have whitelisted the Pi and with curl i can read the last Buttonevents of the right switch over the existing API (http://192.168.X.XXX/api/WBLuUNIQUEUSERIDbdQ0-iEetTe5/sensors/5)

    This Site gave me the following JSON Data:

    {„state": {"buttonevent":1002,"lastupdated":"2016-05-04T15:00:51"},"config":{"on":true,"battery":100,"reachable":true},"name":"Hue dimmer switch 1","type":"ZLLSwitch","modelid":"RWL021","manufacturername":"Philips","swversion":"5.45.1.16265","uniqueid":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}
    

    buttonevent 1002 is for turn on and 4002 is for turn off

    So i worked on a script which will should check all 10 seconds the Buttonstatus and regarding this Wake Up the LCD.

    import urllib2
    import time
       def SensorState( SensorName ):
        s = "buttonevent\":"
      a = urllib2.urlopen("http://192.168.X.XXX/api/monitor/sensors/" + SensorName    ).read()
      b =  a.find(s) + len(s)
      e = a.find(",",b)
       return a[b:e];
      while 1 == 1:
       lastState = SensorState("2")
     while (SensorState ("2") == lastState):
       time.sleep(0.5)
       print "State Changed!" + SensorState("2")
    

    For LIBCEC the action for Turn on is echo "on 0" | sudo cec-client -s -d 1 and echo "standby 0" | sudo cec-client -s -d 1 to turn it off.

    Over SSH all commands will work good on its own, but i need a script…
    It is my first time with Phyton, the Script should be easy for someone with more experience in this. Maybe someone could help mit with this?

    Thank you for your help!


  • Admin

    Why not use NodeJS for the script?


  • MagicMirror Creator

    Go for node. Adding a python solution would make no sense.


Log in to reply
 

Looks like your connection to MagicMirror Forum was lost, please wait while we try to reconnect.