Philips HUE Motion sensor in OH2?

Hi all,

I got Philips HUE Motion sensor working on my OH 1.8.3 by defining below in my items file.

Switch 	HUE_Motion { http="<[http://hue-ip-address/api/_secret_key/sensors/3:3000:JS(getHueMotionEvent.js)]" }
Switch 	HUE_Skumring	{ http="<[http://hue-ip-address/api/_secret_key/sensors/4:60000:JS(getHueDark.js)]" }
Number	HUE_Temp	{ http="<[http://hue-ip-address/api/_secret_key/sensors/2:300000:JS(getHueTemperature.js)]" }

After upgrading to OH2 (latest SNAPSHOT), I fail to see how I get these (poll) events? Any help on how to configure or workaround this issue will be highly appreciated.

Thanks in advance!

3 Likes

Did you install the http-binding in OH2?

2 Likes

Thanks Alexander,

Why does it have to be so obvious, once you have been pointed in the right direction :blush:

Next up is getting my Z-wave Christmas presents (motion sensors 6 and Z-Stick gen5) up and running.

Happy New Year to All!

you´re welcome, a “like” would be much appreciated :wink:

1 Like

Hi! I tried same things but i get always “null” in my sitemap. Can u pls post every detail (item, js, part of the sitemap) for the motion sensor? THX!

Hi Holger,
Sorry for late reply. Christmas, new Year and all - you know :slight_smile: Did you get it solved already?

My problem was that I had written http and not http1 in my addons.cfg file. That did’nt work. Simultaneously I tried to install the binding via Karaf console. It worked but it didn’t persist. For some reason i experienced the binding to become uninstalled automatically. It was first after putting http1 in the bindings list it worked for me.

My addons.cfg file:

# A comma-separated list of bindings to install (e.g. "sonos,knx,zwave")
binding = zwave,hue,http1,ihc1

My items file:

Switch 	Skur_HUE_Motion	<present>	(gSkur)	{ http="<[http://<_my_hue_bridge_ip>/api/<_my_hue_user_key>/sensors/3:3000:JS(getHueMotionEvent.js)]" }
Number	Skur_HUE_Temp 	"Skur temp [%.2f °C]"	<temperature>	(gSkur)	{ http="<[http://<_my_hue_bridge_ip>/api/<_my_hue_user_key>/sensors/2:300000:JS(getHueTemperature.js)]" }

My getHueMotionEvent.js file

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

My getHueTemperature.js file:

(function(i) {
    var json = JSON.parse(i);
    return ((json['state']['temperature']))/100;
})(input)

My sitemap

Text 	item=Skur_HUE_Temp // Notice that I have the text formatting in my items file. 

It can take a little while before the value is updated, no matter what your poll interval is. I think it is a matter of the bridge responding or something.

I hope this help you.

4 Likes

for cross reference:

Hopefully the motion sensor will be integrated in the hue binding in the future:)

1 Like

I would have two questions here: First, where is the secret key stored in OH2 if not migrated from OH1? Second, where have the java script file to be put? Thx!

You find the key in your things definition. Look out for this section:
Bridge hue:bridge:1 [ ipAddress=“192.168.x.y”, userName=“abcdefghijklmnopqrstuvwxyz” ] {
0210 wz2 [lightId=“1”]
0210 bl [lightId=“2”]
0210 wz1 [lightId=“3”]
0210 wi [lightId=“4”]
}
Simply take the userName as key.

Concerning Java script: put the script in conf/transform. If you hadn’t done it yet, add “javascript” in the transformation section of your addons.cfg.

1 Like

Perfect, thx!

I can’t for the life of me get this to work,

  • I have installed the http binding and javascript transformation

  • I have put the two js files with the exact content in the /etc/openhab2/transformation/ folder

  • I’ve got the username for the item link (Paper UI thinks this is a state secret by the way)

But I can’t get any respons and there issen’t any trace of anythings in the logs either.
What am I missing?

Using log4j.logger.org.openhab.binding.http = DEBUG in the org.ops4j.pax.logging.cfg file gives me this messeage for all motion items.

[DEBUG] [ab.binding.http.internal.HttpBinding] - item 'Mgang' is not a valid URL or is a cache id yet to be initialised (192.168.x.xx/api/username/sensors/12)

I then added the url to the cache in http.cfg

hueCache.url=192.168.x.xx/api/username/sensors
hueCache.updateInterval=3000

And changed the item

Switch Mgang "Gang" <motion> (gM) { http="<[hueCache/12:3000:JS(getHueMotionEvent.js)]" }

And the HTTP binding still wont use the url

[DEBUG] [ab.binding.http.internal.HttpBinding] - item 'Mgang' is not a valid URL or is a cache id yet to be initialised (hueCache/12)

The output of the URL is this

{“state”:{“presence”:false,“lastupdated”:“2017-05-14T18:27:41”},“config”:{“on”:true,“battery”:100,“reachable”:true,“alert”:“none”,“ledindication”:false,“usertest”:false,“sensitivity”:2,“sensitivitymax”:2,“pending”:},“name”:“Gang sensor”,“type”:“ZLLPresence”,“modelid”:“SML001”,“manufacturername”:“Philips”,“swversion”:“6.1.0.18912”,“uniqueid”:“xxxxxxxx”}

And the getHueMotionEvent.js in the transform folder

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

Does anybody see me what i am doing wrong?
I have checked the syntax so many times now i might be going blind :wink:

Are you sure there are no space before your cache items in http.cfg?

Just checked again and there is no space before the cache.

This just seems straight up broken, like openhabs http binding somehow can’t see an address that is visibel to the rest of the network.

I’m using the motion sensor without a problem, but without cache, can you try that, to rule out a problem with your url cache settings?

just add an item:
Switch Mgang "Gang" <motion> (gM) { http="<[192.168.x.xx/api/sensors/12:3000:JS(getHueMotionEvent.js)]" }

Now it works, thanks :joy:

Nevermind that I wasted a good part of last weekend with the exact same items, and now it just works instantly - only a little mad about that.

Can anyone tell me how do i round the temperature output fron the Motion Sensor?
I think i do that in the “getHueTemperature.js”.

(function(i) {
    var json = JSON.parse(i);
    return ((json['state']['temperature']))/100;
})(input)

In the moment the output is: 20,75 C i need to roud this to 20,8 C

Hey Mike,

there are several ways to archieve a solution.

First use Math.round(). Notice: Math.round() returns the nearest integer:

return Math.round((json['state']['temperature']) / 10) / 10;

Second use toFixed():

return ((json['state']['temperature']) / 100).toFixed(1);

Third do not round in the transform script, round the item / display value:

Number demoTemperature "Temperature [%.1f °C]" {
    http="..."
}
3 Likes

great thanks for feedback

You are welcome.