Tutorial adding HUE Motion sensor (Lux,Temp and Motion)

Thanks for sharing this. I also run into you on Reddit quite a bit and want to thank you for your posts and help!

2 Likes

For the motionsensor, you probably want to have a scan_interval: 10 or so, the default 30s may be too slow.
I am thinking about even setting it lower, to 5 seconds. Entering a room that is dark and waiting 10-30s before the light turns on is something that will get annoying very quickly. But i’m not sure if the bridge stays happy if you poll it every 5 seconds.

It would be great if the Hue API could call URL’s by itself, that way we could provide it with the URL of a binary sensor in HASS, so that the detection of motion would be put into HASS instantly. But as far as i know, that isn’t possible.

I could also solve it by buying more Hue lights (i now only have one, otherwise i couldn’t continue in the Hue app to add the motion sensors), but the lights i have now are fine :stuck_out_tongue:

Edit: Someone here is reporting that polling his V2 bridge every 2s is working fine, he is doing that for a few months wihtout problems.

A couple of questions if you don’t mind. I’ve got the light and temp working. However the lux reading is way too big. 12000+ Also I’ve got it right beside an Aeotec Multi 6. the temps are within a degree but lux on the muilti6 is 6.0 lux. I’m in dim office lighting now and I know that’s not right either but at least a little closer. Is it best just to use these measurements as a comparative thing? I guess I can use the daylight or dark sensors too?

I’m wondering where to add the scan_interval? To the virtual sensor or HASS sensor?

Thanks for any help.

The formula for the lux calculation seems to be incorrect, maybe you can try this one and compare it with your Aeotec sensor.

I have defined the scan_interval at the binary_sensor, see here. I have left the temperature and lux readings at the default scan interval, to not overload the Hue bridge.

The values are logarithmic. In Philips words:

Light level in 10000 log10 (lux) +1 measured by sensor. Logarithm scale used because the human eye adjusts to light levels and small changes at low lux levels are more noticeable than at high lux levels.

So equivalent values:

Example                                 Lux               MeasuredValue
Overcast moonless night sky              0.0001                  0
Outdoor: Bright moonlight                1                       1
Home: Night light                        2                    3000
Home: Dimmed light                      10                   10000
Home: ‘Cosy’ living room                50                   17000
Home: ‘Normal’ non-task light          150                   22000
Home: Working / reading                350                   25500
Home: Inside daylight                  700                   28500
Home: Maximum to avoid glare          2000                   33000
Outdoor: Clear daylight            > 10000                 > 40000
Outdoor: direct sunlight            120000                   51000
2 Likes

I did figure out that the scan_interval should go in the Rest Sensor config. Not sure if it’s a big deal but you did expose your API Key in that link.

My sensor looks like this:

  - platform: rest
    resource: http://[Hue bridge IP]/api/[API-KEY]/sensors/[Sensor ID]
    value_template: '{{ value_json.state.status }}'
    scan_interval: 2
    name: 'Kitchen Motion'

I also grabbed the daylight and dark binaries. These may be more useful than a Lux reading. Looks like you can adjust the sensitivity of the daylight sensor in the Hue App to match your use/location of sensor.

If I match up using the above values and compare to my Aeotec sensor I’m in the ball park. Philips is a bit higher in lux than the Aeotec but that’s at low light levels. Will be interesting to see how close they are at higher values.

Although I’ve seen varying reports the temp sensor seems to be within about .5 to 1° C of my thermostats.

Thanks for your help. Hope this helps someone too.

Looking closer at the Hue API I think presence is already exposed. You can look for ZLLPresence for the sensor ID and just access that. No need for a virtual sensor. The default scan interval seems to be around 10 seconds so adding a lower value will trigger the REST sensor more quickly. This worked fine for me.

  - platform: rest
    resource: http://[Hue bridge IP]/api/[API-KEY]/sensors/[Sensor ID]
    value_template: '{{ value_json.state.presence }}'
    scan_interval: 2
    name: 'Kitchen Motion Binary'
4 Likes

I know about the API-key. Normally i use the secrets.yaml to hide such stuff. But i don’t know how to use it inside a URL, like you posted ‘[API-KEY]’.

It could be indeed, that the presence is already exposed. But the benefit of having a virtual sensor is that you don’t have to create the logic on the HASS side and just have to poll one sensor (the virtual one).

Ah I see re the API. I don’t know how to do that either. I just redacted that way.

I’m not sure what you’re getting at regarding the presence sensor. I just make the a binary sensor with the code above and it works just like the virtual one. I did that too but thought I’d try scanning the existing sensor. It works like all of my other binary motion sensors. It’s the one at the bottom:

I understand, but i see i forgot to mention one thing: the virtual sensor goes on when the physical sensor goes on, and goes off 4 min. after the physical one has been off. This ‘smoothens’ it out like a sort of ‘hysterese’, otherwise the lights would get turned off too quickly if you sit still for a while. That kind of logic is also possible in HASS, but i think this works easier.

you have all philips hue sensors?

Ah. I see. Yes that is a bit annoying. I also might attach another condition like if the media player (Pioneer amp) is off start timer. If no motion resets timer turn off lights in TV room. Sometimes I’m just turning the lights on when arriving home or waking up so some other condition turns them off. Like we all leave and all motion off. When we are done downstairs for the night I have one switch that when off after 9:30 turns off all the lights on the main floor. If I forget or am not there at midnight start timer if lights on. If no motion resets timer turn off lights.

Thanks for keeping up the discussion it is great to hear how other people are using HA. A bit of a hobby that’s only slightly annoying my wife.

1 Like

No. Most of my binary sensors are from my alarm system. Envisalink attached to DSC panel. I also have an Aeotec Multi Sensor 6 and a GoControl PIR attached to Wink. I really like the Hue Sensor and it’s good bang for buck. Especially because it has light and temperature.

Now that the API for the motion sensor is available. Will someone be updating the component to auto detect and add them like the hue bulbs soon.?

Thanks for sharing. One question: how do I round the temperature value to 1 decimal ?

I tried this:

value_template: '{{ value_json.state.temperature | float / 100 | round(1) }}'

But that didn’t work.

Thanks for the post, this worked for me and I now plan to use the Hue motion sensor by my front door as notification trigger. Perhaps this info should be added directly to the main Philips Hue page in Components?
Cheers
Robin

For me either it doesn’t work, so I round the integer and then convert it to float

value_template: '{{ value_json.state.temperature | round(-1) | float / 100 }}'

I made it all the way to creating the virtual sensor. Afterwards I copied the code to link it to the physical sensor, changed my sensor ids and posted to /api//rules and got this response

[
{
“error”: {
“type”: 607,
“address”: “/rules”,
“description”: “Rule conditions contain errors or operator combination is not allowed”
}
}
]

Total beginner, I have no idea what this means. Thoughts?

Did you do it like this?
http://imageshack.com/i/pla6Eli3p

I had ipaddress/api/APIKEY/rules in the url. I took the ip address out and now I get error 0. I’ve just cut and paste the code directly, then changed the numbers to match my sensors. Is there something else I need to modify before posting?

Cheers