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

hue
philips
Tags: #<Tag:0x00007f014607f1b8> #<Tag:0x00007f014607eec0>

(Christoph Weitkamp) #21

Hi Norman,

I think it depends on the way how a Number item stores the value internally. It uses a data type to represent integer and decimals in the same way.


(Norman) #22

Hi Christoph,

Well, thanks for the explanation. I changed my Item declaration to String for the buttonstate and lastupdate (instead of Number and DateTime). I also changed the JS script, so the value given back is a string:

return parseInt(json["state"]["buttonevent"]).toString();

Now it is working as expected again. I am still a total newbie with all this, so it is “learning by doing”. Please tell me if I did something totally wrong or if there’d be another, better solution.


(Norman) #23

Oh, I forgot, the Luminance from the Motion sensor also gives a very large number like 44.9676301176907 - I assume this is because of the conversion from the raw value to lux. Any idea how to round it to a simple Integer which can then be handled in rules? It is not very important for the rule itself but it sizes up the log files and makes it more complex and slower to calculate in rules internally.


(Christoph Weitkamp) #24

You can use the Math.round() method (see my second post for an example) in both cases. I can give you some hints, you have to decide what’s the best way for your purpose.


(Norman) #25

Hi Christoph,

Thanks, I’ll try the math function, must have overlooked it somehow. Have a nice sunday.

Edit:

A brave .toFixed() did the job, values are now as expected (ger.: kurz und knackig)


(Christoph Weitkamp) #26

Sounds good. You’re welcome. Have a nice Sunday too.


(Gerald Stieglbauer) #27

Works great, but why not incorporating bidirectional using the http binding (as for the readings) to monitor as well deactivation of a sensor e.g. by third-party hue apps?


(Christoph Weitkamp) #28

Of course. That should be possible. Feel free to post an updated example.


(Gerald Stieglbauer) #29

I will feel free, if I find some time during the next days ;-). In between, maybe someone could give me a hint, if a HTTP POST will do the job as well, since the HTTP binding seems to support only POSTs but not PUTs.


(Gerald Stieglbauer) #30

Ok, I did half the way:
Defining an Item

Switch BathRoomMotionSensorStatus { http="<hueMotionSensorPresence:3000:JS(getHueMotionStatus.js)]" }

and using the following script for getHueMotionStatus.js

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

does the job for external updates. Did not check so far how to setup PUT outputs with the http binding


(Brian Chan) #31

If I use this with a hue motion sensor to trigger an action would there be a delay?


(Christoph Weitkamp) #32

Yes, there will be a delay with at least the amount of milliseconds specified in the updateInterval of the HTTP cache item (max. 5000ms in my example).


(Brian Chan) #33

So this is essentially polling every 5 seconds? Would it ever be possible to push events from the hue bridge?


(Christoph Weitkamp) #34

That is true. But you can change it to a lower frequency if you like.

Yes, after we found a volunteer to solve it.


(Julio) #35

@cweitkamp When you refer to <id>, do you mean uniqueid? Not sure I know which string I need.

I’m new at this but want to learn…thanks for this helpful post.


(Kurt S) #36

Hi,
it’s the capability ID of the HUE sensor:

"capabilities":{"certified":true}},"X"

Kurt


(Julio) #37

Thank you @KurtS!


(Julio) #38

Not sure I get how to enable/make sure this is “active”.


(Christoph Weitkamp) #39

Hi Julio,

The complete HowTo is based an those cached items. If you will follow it you will use them automatically.

I will add some example responses to my the tutorial. I will keep you posted.


(Julio) #40

Will it be too much to ask if you could post a sample rule using these services/items/transforms? :blush:

I’m so new at this that I am now struggling with how to write the rule that triggers when motion is detected so I can send a Pushover a notification (I’ve already configured the Pushover action).

Thanks!