How to use the new Hue Motion Sensors in OH1?

Thank you!
I can now read the values from the sensor!

Based on your example I now have the following in my Items file …

String HueMotionEvent "Hue Motion Detected [%s]" <present> (Motion, Sensors) { http="<[http://_HueHubIP_/api/_SecretID_/sensors/6:5000:JS(getHueMotionEvent.js)]" }
DateTime HueMotionEventDate "Hue Motion Detected at [%1$tR]" (Motion, Sensors) { http="<[http://_HueHubIP_/api/_SecretID_/sensors/6:5000:JS(getHueMotionEventDate.js)]" }
Number HueTemp "Hue Temperature [%.0f]ºC" (Temp, Sensors) { http="<[http://_HueHubIP_/api/_SecretID_/sensors/5:60000:JS(getHueTemp.js)]" }
String HueLight "Hue Light Level [%s]" (LightLevel, Sensors) { http="<[http://_HueHubIP_/api/_SecretID_/sensors/7:60000:JS(getHueLight.js)]" }
String HueDark "Hue Dark [%s]" (LightLevel, Sensors) { http="<[http://_HueHubIP_/api/_SecretID_/sensors/7:600000:JS(getHueDark.js)]" }
String HueDay "Hue Daytime [%s]" (LightLevel, Sensors) { http="<[http://_HueHubIP_/api/_SecretID_/sensors/7:600000:JS(getHueDay.js)]" }

With a JavaScript file for each of the Items in the ‘transform’ folder.

Now all I need to do is create the necessary rules!
That and figure out how to deal with the Time being in UTC but, for me, that is only a problem for half of the year!
And strangely the Temperature shows in the SiteMap as ‘18]*C’ with the extra ].

Many thanks, once again!

Great!
thank you for the code sharing.
Have fun.

Thanks for sharing @iWPL

Used it for my hue motion sensors.
Now I would like to tweak the HueTemp.js to transform the JSON temp-value to the right format (standard is a 4 digiti value of the degree without the dot).

My first try was to slice the JSON-value in 2 and simply make a dot between these values… but sadly it seems to be not that easy (plus I´m a total newbie to js).

(function(i) {
		var json = JSON.parse(i);
		var	n = json['state']['temperature'];
		var	a = (""+n).slice(0,2);
		var	b = (""+n).slice(-2);
	return a + '.' + b;
})(input)

I only get the first part of the value (var a) as output. Maybe someone of you coul help?!

thanks in advance
Simson

Hi @simson,

Here is my getHueTemp.js …

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

This produces an output of (currently) 17.96]*C (when the Item is formatted as [%.2f] ).
Still not sure why the ] is in there!

Hope that helps.

so easy… arghs - It works. In OpenHAB2 theres no ]-error.

thanks for your help

Thanks to iWPL and mortommy I also use the hue motion with openhab 2, but I have a little difference in the Hue API CLIP debugger:

{"1":{
"state":{
    "daylight":null,
    "lastupdated":"none"},
"config":{
    "on":true,
    "configured":false,
    "sunriseoffset":30,
    "sunsetoffset":-30},
    "name":"Daylight",
    "type":"Daylight",
    "modelid":"PHDL00",
    "manufacturername":"Philips",
    "swversion":"1.0"},

"2":{
"state":{
    "temperature":2101,
    "lastupdated":"2016-11-04T16:18:18"},
"config":{
    "on":true,
    "battery":100,
    "reachable":true,
    "alert":"none",
    "ledindication":false,
    "usertest":false,
    "pending":[]},
    "name":"Hue temperature sensor 1",
    "type":"ZLLTemperature",
    "modelid":"SML001",
    "manufacturername":"Philips",
    "swversion":"6.1.0.18912",
    "uniqueid":"##:##:##:##:##:##:##:##-##-####"},

"3":{
"state":{
    "presence":false,
    "lastupdated":"2016-11-04T16:05:19"},
"config":{
    "on":true,
    "battery":100,
    "reachable":true,
    "alert":"none",
    "ledindication":false,
    "usertest":false,
    "sensitivity":2,
    "sensitivitymax":2,
    "pending":[]},
    "name":"Wohnzimmer Sensor",
    "type":"ZLLPresence",
    "modelid":"SML001",
    "manufacturername":"Philips",
    "swversion":"6.1.0.18912",
    "uniqueid":"##:##:##:##:##:##:##:##-##-####"},

"4":{
"state":{
    "lightlevel":5864,
    "dark":true,
    "daylight":false,
    "lastupdated":"2016-11-04T16:19:15"},
"config":{
    "on":true,
    "battery":100,
    "reachable":true,
    "alert":"none",
    "tholddark":65534,
    "tholdoffset":7000,
    "ledindication":false,
    "usertest":false,
    "pending":[]},
    "name":"Hue ambient light sensor 1",
    "type":"ZLLLightLevel",
    "modelid":"SML001",
    "manufacturername":"Philips",
    "swversion":"6.1.0.18912",
    "uniqueid":"##:##:##:##:##:##:##:##-##-####"},

"5":{
"state":{
    "status":0,
    "lastupdated":"2016-11-04T16:08:04"},
"config":{
    "on":true,
    "reachable":true},
    "name":"MotionSensor 3.Companion",
    "type":"CLIPGenericStatus",
    "modelid":"PHA_STATE",
    "manufacturername":"Philips",
    "swversion":"1.0",
    "uniqueid":"MotionSensor 3.Companion",
    "recycle":true}}

so my .items file would be:

String HueMotionEvent "Hue Motion Detected [%s]" <present> (Motion, Sensors) { http="<[http://_HueHubIP_/api/_SecretID_/sensors/3:5000:JS(getHueMotionEvent.js)]" }
DateTime HueMotionEventDate "Hue Motion Detected at [%1$tR]" (Motion, Sensors) { http="<[http://_HueHubIP_/api/_SecretID_/sensors/3:5000:JS(getHueMotionEventDate.js)]" }
Number HueTemp "Hue Temperature [%.1f °C]" (Temp, Sensors) { http="<[http://_HueHubIP_/api/_SecretID_/sensors/2:60000:JS(getHueTemp.js)]" }
DateTime HueTempDate "Hue Temp Date [%1$td.%1$tm.%1$tY %1$tR]" (Motion, Sensors) { http="<[http://_HueHubIP_/api/_SecretID_/sensors/2:5000:JS(getHueTempDate.js)]" }
String HueLight "Hue Light Level [%s]" (LightLevel, Sensors) { http="<[http://_HueHubIP_/api/_SecretID_/sensors/4:60000:JS(getHueLight.js)]" }
String HueDark "Hue Dark [%s]" (LightLevel, Sensors) { http="<[http://_HueHubIP_/api/_SecretID_/sensors/4:5000:JS(getHueDark.js)]" }
String HueDay "Hue Daytime [%s]" (LightLevel, Sensors) { http="<[http://_HueHubIP_/api/_SecretID_/sensors/4:5000:JS(getHueDay.js)]" }

For understanding how the transform for other variables is done I attach my getHueLight.js which is in the transform folder:

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

Some things I had problems with where the following:

Have fun, maybe this helps people with the same issues.

I didn’t tried this by my self because i used the Hue-API, with OH2 you can use the REST-API for getting the things configuration:

I think the User-Name than can be found in the “response-body”:

{
  "statusInfo": {
    "status": "ONLINE",
    "statusDetail": "NONE"
  },
  "label": "Philips hue (192.xxxx.xxx.xx)",
  "configuration": {
    "ipAddress": "xxxx.xxxx.xxxxx.xxxx",
    "pollingInterval": 10,
    "serialNumber": "00178823ace3",
    "userName": "xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxx"
  },
  "properties": {
    "vendor": "Philips",
    "firmwareVersion": "123456790",
    "serialNumber": "xx:xx:xxx:xxx:xxx:xx"
  },
  "UID": "hue:bridge:xxxxxxxace3",
  "thingTypeUID": "hue:bridge",
  "channels": [],
  "location": "Location"
}

Username contains the secret ID, i’ll tried out with a http-request to the hue-API :slight_smile:

1 Like

Ok, that’s much easier. I wasn’t aware of this :flushed:

On OH1 I got the wrong temperature format fixed with this item config:

Number HueTemp "Hue Temperature [%.0f °C]"

misunderstanding of Benedikts post

Warren,
I just bought one of the hue sensors. Could you show me your java scripts for each of your items. Thanks!

Update: I ended up figuring it out by going over your examples. Thanks for sharing.

Is there a way to have the temperature be shown in Fahrenheit? I tried changing the C to an F, but it didn’t work.

Hi MikeH,

please try the following java as getHueTemp.js:

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

Homer

Thanks Simpson. That fixed it.

Is there a way to format the date when Motion event is detected. This is how it shows up now:
2016-11-16T15:42:57.000-0500
Possibly, put it on a 12 hour clock and spaced out correctly.

Formating the date e.g. in the .items:

DateTime HueMotionEventDate "Hue Motion Detected at [%1$tR]" (Motion, Sensors) { http="<[http://_HueHubIP_/api/_SecretID_/sensors/3:5000:JS(getHueMotionEventDate.js)]" }
DateTime HueTempDate "Hue Temp Date [%1$td.%1$tm.%1$tY %1$tR]" (Motion, Sensors) { http="<[http://_HueHubIP_/api/_SecretID_/sensors/2:5000:JS(getHueTempDate.js)]" }

%1$td: day
%1$tm: month
%1$tY: year
%1$tR: time without seconds

put in between what you like space / .

Get the username - i went almost crazy this weekend :slight_smile: Look here: openHAB not authorized to access Hue bridge (SOLVED)

1 Like

hi @homer , how quick does it detect motion? I want my lights to turn on immediately:)

String HueMotionEvent "Hue Motion Detected [%s]" <present> (Motion, Sensors) { http="<[http://_HueHubIP_/api/_SecretID_/sensors/3:5000:JS(getHueMotionEvent.js)]" }

Second the HUE does not have humidity sensor or? At least not in the API…

And mainly is that I can not get any values from the motion sensor, I defined my sitemap like this :

Frame label="Motion" {
	Text label="Motion" icon="groundfloor"{
		Text item= HueMotionEvent
		Text item= HueMotionEventDate
		Text item= HueLight
		Text item= HueDark
		Text item= HueDay
		Text item= HueTemp icon="temperature"
		
	}
} 

I added the http binding in paper UI, and the json transform, the hue bridge does appear in the hue binding, what am I missing?

The light switches immediately.
The hue has no humidity sensor.
Just to be sure… You have the .map in the transform folder and the transformations javascript / json / map installed?
Sometimes also restarting helps.

Homer

The light switches immediately.

I just saw that you set refresh rate to 5000, so thats why I was confused

The hue has no humidity sensor

I thought maybe it was dht22, and that hue currently in software did not display it.

You have the .map

What should be in the.map file?

javascript / json / map

Yes

Sometimes also restarting helps.

Will do as soon as my GF is gone to bed…