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 🙂 https://developers.meethue.com/documentation/getting-started
  • setup openhab item in your items folder:

    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:
  • 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):

    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:

    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”