MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord
    MagicMirror² v2.25.0 is available! For more information about this release, check out this topic.

    Philips Hue Light Switches based wakeup

    Development
    utility
    3
    3
    3167
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      Tomekkkkk last edited by paviro

      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!

      1 Reply Last reply Reply Quote 1
      • paviro
        paviro Admin last edited by

        Why not use NodeJS for the script?

        We're all stories in the end. Just make it a good one, eh?

        – The Doctor

        1 Reply Last reply Reply Quote 0
        • MichMich
          MichMich Admin last edited by

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

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Enjoying MagicMirror? Please consider a donation!
          MagicMirror created by Michael Teeuw.
          Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
          This forum is using NodeBB as its core | Contributors
          Contact | Privacy Policy