Openhab hue motion sensor

I got the question how to use your hue motionsensor with openhab, so here are the steps you need to do:

  • get hue user (api key)
    You need a hue username key for the requests to the hub, philips has a great tutorial for that 🙂
  • setup openhab item in your items folder:
    Switch Motion_Sensor "Motion sensor" <present> (gSkur) { http="<[192.168.x.xx/apiuserkey/sensors/12:3000:JS(getHueMotionEvent.js)]" }

    Note that the id of my motionsensor is 12, and it will poll the status every 3 seconds (3000ms), you need to change the id to the id of your motion sensor, and don’t forget to replace 192.168.x.x with the ip address of your hue hub.
    If you don’t know the ID of your motionsensor check http://IP_HUE_HUB/USERKEY/sensors to find the id

  • add transform script
    The transformscript needs to be added in the transform directory:

    (function(i) {
    var json = JSON.parse(i);
    return ((json['state']['presence'])) == true ? "ON" : "OFF";
  • setup openhab rules
    It might be nice to have something happen when the state changes (turn on / off light for instance), the make this happen you need to add a file to your rules folder (e.g. motion.rules):

    var Timer delay= null
    rule "Motion_Sensor"
        	Item Motion_Sensor changed
          if(Motion_Sensor.state == ON){
             //Turn off the light after 60 seconds
             delay = createTimer(now.plusSeconds(60)) [|

    If you use openhab cloud connector, you can even send a push notification to your phone!, just add this to your rule inside your if statement:

    sendBroadcastNotification("Motion detected")

    I have created a switch in openhab, which I can switch on when I’m out of the house, if the switch is set to on, and motion is detected I will receive the push notification.
    You can create a switch in your items file by just adding “Switch OutOfHouse”  to your items file, and then you are able to check the state of the switch if motion is detected “if(OutOfHouse.state == ON)… and so on”

Leave a Reply

Your email address will not be published.