How to use the new Hue Motion Sensors in OH1?

hue
motionsensor
beginner
Tags: #<Tag:0x00007fd30e6e2150> #<Tag:0x00007fd30e6e2010> #<Tag:0x00007fd30e6e1ed0>

(Warren) #1

Hi,

I have one of the brand new Hue Motion Sensors and would like to use it to trigger rules only at certain times of the day (e.g. after the childrens bedtime, but not during). The Hue Motion Sensor also has a light and temperature sensor built in.

As these are brand new (only released about 2 weeks ago) and .: not included in the Hue Binding, how can I create Items to read/monitor their values? Specifically if Motion is detected (true/false, ON/OFF), the light level (perhaps 0-65500ish like the Hue Bulb brightness settings) and temperature value (a number in 1/100ths of a degee C?).

I would expect the Motion Sensor is a Switch, and the Light and Temperature to be Dimmers?

Using the Hue API CLIP debugger I can see the below information from the Motion Sensor …
5 is the Temperature, 6 is the Motion Sensor, 7 is the Light Sensor, not sure what 8 is.

<IPAddress>/api/<SecretID>/sensors

{ 
    "5": {
            "state": {
                "temperature": 1796,
                "lastupdated": "2016-10-15T12:10:46"
            },
            "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": "##:##:##:##:##:##:##:##-##-####"
        },
        "6": {
            "state": {
                "presence": false,
                "lastupdated": "2016-10-15T12:05:35"
            },
            "config": {
                "on": true,
                "battery": 100,
                "reachable": true,
                "alert": "none",
                "ledindication": false,
                "usertest": false,
                "sensitivity": 2,
                "sensitivitymax": 2,
                "pending": []
            },
            "name": "Landing MS",
            "type": "ZLLPresence",
            "modelid": "SML001",
            "manufacturername": "Philips",
            "swversion": "6.1.0.18912",
            "uniqueid": "##:##:##:##:##:##:##:##-##-####"
        },
        "7": {
            "state": {
                "lightlevel": 15351,
                "dark": false,
                "daylight": true,
                "lastupdated": "2016-10-15T12:15:09"
            },
            "config": {
                "on": true,
                "battery": 100,
                "reachable": true,
                "alert": "none",
                "tholddark": 2054,
                "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": "##:##:##:##:##:##:##:##-##-####"
        },
        "8": {
            "state": {
                "status": 0,
                "lastupdated": "2016-10-15T12:05:35"
            },
            "config": {
                "on": true,
                "reachable": true
            },
            "name": "MotionSensor 6.Companion",
            "type": "CLIPGenericStatus",
            "modelid": "PHA_STATE",
            "manufacturername": "Philips",
            "swversion": "1.0",
            "uniqueid": "MotionSensor 6.Companion",
            "recycle": true
        }
    }

Many thanks in advance!


(Heiko Fanieng) #2

Interesting Topic :smiley:

A few days ago i want to ask this for oH2. Are you sure that also a temperature sensor is built in?

It would be very nice to use that functions in OH.

But i don’t think we can use it today, because it’s still not implemented in the Hue-Binding :cry:


(Tommaso) #3

I’d try via http binding, hue API and json tranformation to get the values. I did something similar when I wanted to use the Dimmer Kit.


(Warren) #4

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!


What can be done with HTTP Binding & Philips Hue API
(Tommaso) #5

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


( ) #6

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


(Warren) #7

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.


( ) #8

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

thanks for your help


(Simpson) #9

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.


Philips HUE Motion sensor in OH2?
(Heiko Fanieng) #10

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:


(Simpson) #11

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


(Benedikt) #12

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

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

(Simpson) #13

misunderstanding of Benedikts post


(MikeH) #14

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.


(MikeH) #15

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.


(Simpson) #16

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


(MikeH) #17

Thanks Simpson. That fixed it.


(MikeH) #18

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.


(Simpson) #19

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 / .


(paglia) #20

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