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

Hi Nils,

Please have a look into the bindings documentation - the required syntax for an item is:

http="<[<url>:<refreshintervalinmilliseconds>:<transformationrule>]"

So the answer is yes, even if it will be ignored for cached URLs. But to be honest, I never tried to leave it away.

How do you set cache option?

The problem with the hue motion sensor is that it does not tell OH when its detected motion, instead you need to call it at LEAST every 1000ms(even this feels slow)

Hi Kim,

The complete HowTo is based an those cached items.

I have been using it this way:

Switch HueMotion “Hue Motion” <present> (Group_Motion, Group_Sensors) { http="<[http://192.168.0.35/api/MyCrazyToken/sensors/3:2000:JS(getHueMotionEvent.js)]" }

But this is not cached then? Or is I missing what you mean with cached Item

in your description.

The main problem is that we need to set an update interval instead of leaving the socket open, and that it closes as soon as it changes status. When you have several of the hue motion sensors it DOES slow down the whole system a lot, when you pull it faster than 2000ms, and 2s is to slow for bathroom, but OK for hallway, garages etc


Correct. That is not a cached item. A cached item looks like this:

services/http.cfg

hueMotionSensorPresence.url=http://<bridge ip address>/api/<username>/sensors/<id>
hueMotionSensorPresence.updateInterval=5000

items/http.items

Switch hueMotionSensorPresence "presence [%s]" <motion> { http="<[hueMotionSensorPresence:5000:JS(getHuePresence.js)]" }

I observed that in my environment too. The more sensors you have, the slower is your system. That is a basic formula. Additionally it does not even make sense to poll the sensors faster because:

  • The presence value is reported every 5 minutes, and when the motion sensor value changes (from motion to no motion or from no motion to motion);

Quoted from: https://developers.meethue.com/content/how-often-does-api-data-motion-detectors-update

It is important to finalize https://github.com/eclipse/smarthome/pull/5996 which not only introduces the feature for the Hue binding but brings performance as well.

OK, but how do we figure out that motion has happened with just a few ms delay, and not possible 5 min after it happened?

I maybe should read the statement more carefully. It tells us, that the present status is reported every 5 minutes AND when the sensor value changes. Which leads to the conclusion that we can detect a possible presence with smaller polling frequency. The difference is that the Hue binding does not poll a single sensor like we now have if we follow my tutorial. it polls all sensors at the same time with one request which minimizes resources.

That’s the reason why i think HUE is not a good motion sensor for openhab. If you want to monitor temperature,humidity and lux then just get the cheaper miflora

Well, if you depend on the polling - probably yes. But if you use it in combination with the native zigbee binding of @chris, the HUE motion sensors work quite well:

Presence is reported immediately.

I know, abandon the HUE bridge and switch to the native zigbee binding suits not everyones use case or requirements. But if it does, it’s worth a try :wink:

Some drawbacks though: Temperature reporting is quite inaccurate (probably the same in @cweitkamp’s solution?) and battery level is not working. AND: the LED is flashing red when movement is detected. This is different to the behaviour when paired with a HUE bridge IIRC.

This requires a different HUB, any recommendations on this. Also I can not find any discussion on the HUE motion sensor in here with native zigbee binding, do you have a link to how to implement it?

Search for Zigbee binding.

Sure:

:wink:

Hi Christoph.
After updating to milestone M5 i get this error every 6-8 hours.

2018-11-04 02:08:31.716 [ERROR] [org.openhab.io.net.http.HttpUtil    ] - Fatal transport error: java.net.SocketException: Too many open files
2018-11-04 02:08:31.717 [ERROR] [ab.binding.http.internal.HttpBinding] - No response received from 'http://192.168.1.118/api/***/s$2Fmp/sensors/11'
2018-11-04 02:08:32.224 [hingStatusInfoChangedEvent] - 'hue:bridge:0017****' changed from ONLINE to OFFLINE: Verbindung zur Hue Bridge unterbrochen.

I have wrote a new topic for this, but now i see that sensor11 is a motion sensor which works with your code. The refresh intervall ist 750. Before updating to M5 all runs okay. Now the system makes a restart. And the cpu load increases up to 6% in the middle from 2% before.

Switch   HueMotion1           "HueMotion1"               {http="<[http://192.168.1.118/api/***/sensors/11:750:JS(getHueMotion.js)]"}

(function(i) {
     var json = JSON.parse(i);
     return ((json['state']['presence'])) == true ? "ON" : "OFF";
             })(input)

Has there something changed to stable 2.3?
Thanks and greetings,
Markus

Hi Markus,

I am pretty sure a lot of stuff has changed since OH2.3 :wink: but I cannot imagine something which is related to the HTTP binding. I do not poll my sensors with such a high frequency. And the HttpUtil uses a default timeout of 5 seconds. Maybe you have to look deeper into that to solve your issue.

Hi @cweitkamp

I saw in github that you are taking over to implement motion sensor support into the hue binding itself. Is the plan to only support motion sensor or is the dimmer switch also in the todo list? One other thing that I saw was the internal scenes of hue api. See this thread. Would a scene selector also be something to implement in the binding?

P.S. Looking forward for your work and to test the new features of the binding

Hi Miika,

Yes, that is true. I already put some code together to make it stable and usable for others. I would love to provide a test version for everyone who is interested. The current solution will support the Hue Motion Sensor - splitted up into three different things (motion sensor, temperature sensor and illumination sensor) - and the Dimmer Switch as well.

I agree with you that scene support will be a great feature too. But first I will focus on the sensor support.

1 Like

I am very interested un testing out your binding,

Wouldn’t it be more logical to implement the physical thing as a thing and that the thing has channels such as motion,time,temperature and lux?

Then it would have multiple “last updated” channels for example. I think separate things are much better. Even every lightbulb is its own thing under hue bridge.

I will prepare a test version later this day and link it here.

Yes and No. See this discussion why we split it up.

1 Like

You can download a test version here. Please play around with the new sensors, discover all features and let me know if some thing went wrong. Have fun.

// EDIT: I changed the link.