HowTo: Use Philips Hue sensors (Motion Sensor / Dimmer Switch)

Here you are. I will add it above.


(function(i) {
    var json = JSON.parse(i);
    return Math.pow(10, (parseInt(json["state"]["lightlevel"]) - 1) / 10000);

could you maby do a write up on how to do this thanks for this guide it helped me alot

Hi Aaron,

The complete HowTo is based an those cached items.

Oh maby I already set that up then I assumed it was something else I had too do aswell thanks for your help

do you know of a way that OH can enable and disable these sensors or is it limited to only reading from them?

Yes, I do. You can send a command in a rule or use a Switch item for it.


Switch hueMotionSensorStatus


rule "Switch Hue Motion Sensor ON / OFF"
    Item hueMotionSensorStatus changed
    val url = "http://<bridge ip address>/api/<username>/sensors/<id>/config"
    var String body = ""
    if( hueMotionSensorStatus.state != ON ) {
        body = '{"on":false}'
    } else {
        body = '{"on":true}'
    logInfo("demo", "Send command '{}' to {}", body, url)
    sendHttpPutRequest(url, "application/json", body)

I’ve made a german tutorial on Youtube. Hope I’m going to finde some time to make also an english one. Stay tuned. :smiley:


Interesting Tutorial in my native language.

As mentioned before this JS-Script transforms the value of the Hue Sensor to Lux:

(function(i) {
    var json = JSON.parse(i);
    return Math.pow(10, (parseInt(json["state"]["lightlevel"]) - 1) / 10000);

Awesome, thanks for the hint. :smiley:

Nice Tutorial but you missed a round bracket at the start of getHueButton.js, getHuePresence.js and getHueBattery.js.

Should be (function(i) { instead of function(i) {.

Thanks for the hint. I changed it in my first post. :+1:

I guess the item names get pulled from items/http.items

And a single hue motion detector gets an item called presence - but I would like to call that thing - kitchen_presence and what about the next motion detector, how do I know which is which?

NICE tutorial

Hi mbechc,

You can use any name you like for the items. The names above are only an example. E.g. you can replace hueMotionSensor with hueKitchenMotionSensor and the code will work as good as before. The JavaScript files for the transformation are reusable and you need them only once in your setup.

Sorry I wasn’t clear enough. How do I get personalized names fx KitchenPresence and BedroomPresence If I have 2 sensors - all items names discovered are readonly - at least through Paper UI

My tutorial is a completely text based configuration. It is not possible to change anything using an UI (e.g. PaperUI).

Please read my above post again. You can create a copy of all items for your kitchen and another copy of all items for your bedroom. Just change the names of those copies to whatever name you like. But you have to identify the correct ids for each of your motion sensor device first.


Thanks for the in-depth information - it kinda saved my sanity :wink:

Anyway, the button function does not work here - instead of “1002” or “1004” I get “1002.0” or “1004.0” - any idea why I get those strange numbers?

Hi Norman,

I think it depends on the way how a Number item stores the value internally. It uses a data type to represent integer and decimals in the same way.

Hi Christoph,

Well, thanks for the explanation. I changed my Item declaration to String for the buttonstate and lastupdate (instead of Number and DateTime). I also changed the JS script, so the value given back is a string:

return parseInt(json["state"]["buttonevent"]).toString();

Now it is working as expected again. I am still a total newbie with all this, so it is “learning by doing”. Please tell me if I did something totally wrong or if there’d be another, better solution.

Oh, I forgot, the Luminance from the Motion sensor also gives a very large number like 44.9676301176907 - I assume this is because of the conversion from the raw value to lux. Any idea how to round it to a simple Integer which can then be handled in rules? It is not very important for the rule itself but it sizes up the log files and makes it more complex and slower to calculate in rules internally.

You can use the Math.round() method (see my second post for an example) in both cases. I can give you some hints, you have to decide what’s the best way for your purpose.