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

I just noticed: when starting OH the last Dimmer and Tap events are fired again, just like the button was pressed.

:10.356 [INFO ] [el.script.HUErule.DimmerSwitch.Event] - HUE Dimmer switch event hue:0820:xxxxxxxxxxxx:dim_hall:dimmer_switch_event triggered 4003.0
:10.356 [INFO ] [el.script.HUErule.DimmerSwitch.Event] - HUE Dimmer switch event hue:0820:xxxxxxxxxxxx:dim_bedright:dimmer_switch_event triggered 4002.0
:10.357 [INFO ] [el.script.HUErule.DimmerSwitch.Event] - Dimmer Button 4 short released
:10.357 [INFO ] [el.script.HUErule.DimmerSwitch.Event] - Dimmer Button 4 long released
:10.357 [INFO ] [el.script.HUErule.DimmerSwitch.Event] - Dimmer Button 4 short released
:10.358 [INFO ] [model.script.HUErule.TapSwitch.Event] - HUE Tap Remote switch event hue:0830:xxxxxxxxxxxx:tap_kitchen:tap_switch_event triggered 17.0
:10.359 [INFO ] [model.script.HUErule.TapSwitch.Event] - Tap Button 2 triggered
:10.359 [INFO ] [el.script.HUErule.DimmerSwitch.Event] - HUE Dimmer switch event hue:0820:xxxxxxxxxxxx:dim_toilet:dimmer_switch_event triggered 4002.0
:10.360 [INFO ] [el.script.HUErule.DimmerSwitch.Event] - Dimmer Button 4 short released
:10.360 [INFO ] [el.script.HUErule.DimmerSwitch.Event] - HUE Dimmer switch event hue:0820:xxxxxxxxxxxx:dim_outdoor:dimmer_switch_event triggered 4003.0
:10.363 [INFO ] [el.script.HUErule.DimmerSwitch.Event] - Dimmer Button 4 long released
:10.359 [INFO ] [el.script.HUErule.DimmerSwitch.Event] - HUE Dimmer switch event hue:0820:xxxxxxxxxxxx:dim_bedleft:dimmer_switch_event triggered 4002.0
:10.365 [INFO ] [el.script.HUErule.DimmerSwitch.Event] - Dimmer Button 4 short released
:10.364 [INFO ] [model.script.HUErule.TapSwitch.Event] - HUE Tap Remote switch event hue:0830:xxxxxxxxxxxx:tap_dining:tap_switch_event triggered 34.0
:10.370 [INFO ] [model.script.HUErule.TapSwitch.Event] - Tap Button 1 triggered

This could lead to unexpected behaviour, for instance when a button was pressed last night and another event/trigger changed the lights in the mean time.

My dimmer switch items are type number and not string…

I see. Nice catch. That happened because the Hue API does not forget. During restart of OH2 the item’s values are NULL and after the first polling of the API they change to last known state.

Question is what can we do? I have a possible solution in my mind. As we are aware of the polling interval we can check against the last_updated timestamp and dispatch the event only if the difference is lower than the polling interval (or twice the polling interval). Wdyt?

I currently have no Items defined for the Tap and Dimmer switches, only rules that trigger when a button press/release event fires. I’m still in testing phase… :grin:

The messages shown are generated in the rule with a logInfo function call based on a switch statement.

IMHO a check against twice (or even three times to be very very safe) the polling interval should do the trick. This is a special case and (re)starting OH or loading the binding does not happen in such a short timeframe.

Hey,
thank you for the dimmer switch and motions sensor feature in the Hue Binding.

I’m trying to use the Hue motion sensor in a room to turn on the lights. This is my rule (thank’s to rlkoshak):

var Timer timer = null

rule "Flur Bewegungsmelder"
when
    Item Flur_MotionSensorPresence received update
then
    if(timer === null || timer.hasTerminated) {
        FlurSchalter.sendCommand(ON)
        logInfo("Motion Flur", "Bewegung erkannt -> Licht an")
        timer = createTimer(now.plusSeconds(30), [ |
            timer = null
            FlurSchalter.sendCommand(OFF)
            logInfo("Motion Flur", "Seit 30 Sekunden keine Bewegung mehr erkannt -> Licht aus")
            ])
    }
    else {
        logInfo("Motion Flur", "Bewegung erneut erkannt -> Timer verlängert ")
        timer.reschedule(now.plusSeconds(30))
    }
end 

This is a part of my openhab log file:

2019-01-19 19:56:51.906 [vent.ItemStateChangedEvent] - Flur_MotionSensorPresence changed from OFF to ON
2019-01-19 19:56:51.908 [INFO ] [e.smarthome.model.script.Motion Flur] - Bewegung erkannt -> Licht an
2019-01-19 19:56:51.908 [ome.event.ItemCommandEvent] - Item 'FlurSchalter' received command ON
2019-01-19 19:57:21.910 [INFO ] [e.smarthome.model.script.Motion Flur] - Seit 30 Sekunden keine Bewegung mehr erkannt -> Licht aus
2019-01-19 19:57:21.911 [ome.event.ItemCommandEvent] - Item 'FlurSchalter' received command OFF
2019-01-19 19:57:31.184 [vent.ItemStateChangedEvent] - Flur_MotionSensorPresence changed from ON to OFF
2019-01-19 19:57:31.184 [INFO ] [e.smarthome.model.script.Motion Flur] - Bewegung erkannt -> Licht an
2019-01-19 19:57:31.185 [vent.ItemStateChangedEvent] - Flur_MotionSensorLastUpdate changed from 2019-01-19T19:56:51.000+0100 to 2019-01-19T19:57:31.000+0100
2019-01-19 19:57:31.186 [ome.event.ItemCommandEvent] - Item 'FlurSchalter' received command ON
2019-01-19 19:58:01.187 [INFO ] [e.smarthome.model.script.Motion Flur] - Seit 30 Sekunden keine Bewegung mehr erkannt -> Licht aus

My problem is, at 19:56:51 I moved at the room and the light turned on. Im moved around a bit for 20 seconds to update the timer. Then I left the room, but ten seconds (19:57:21) later the light turned off. After this I didn’t went back to the room.

I’m a little bit confused…

1 Like

Hi Sebastian,

What happens if you stay longer than 30 seconds in the room? Will the light remain on? From my personal feeling you somehow should consider the current state of the Flur_MotionSensorPresence item because a rule triggered by received updated will be invoked for every update independently if it is ON or OFF or whatever.

1 Like

Hi Christoph,
Thank’s for your help. . When I stay longer in the room, the light will turn off after the first 30 seconds.

But I think if I want to use ON as trigger (“changed to ON”) it won’t work, because when I move around in the room the item won’t change to OFF and then ON…

Is that the goal you want to reach? I guess not. Please correct me if I am wrong but I would wrap up your user-story like this: “When someone enters the room (motion detected) → turn the lights on, after everyone leaves the room (no motion detected) → wait 30s, then turn the lights off.”?

Thus I propose to check for the current states of Flur_MotionSensorPresence. When it changed to ON send ON to your lights, When it changed to OFF start timer, and so on.

1 Like

Thank you. This is exactly what I want to do.

I’ll try it and post the result here.

// Update:

This are my new rules:

var Timer timer = null
rule "Flur Motion Sensor ON" 
when 
    Item Flur_MotionSensorPresence changed from OFF to ON
then
    if(timer === null || timer.hasTerminated) {
        timer = null
        FlurSchalter.sendCommand(ON)
        logInfo("Motion Flur", "Bewegung erkannt -> Licht an")
    }
    else {
        timer = null
    }
end

rule "Flur Motion Sensor OFF"
when
    Item Flur_MotionSensorPresence changed from ON to OFF
then
    logInfo("Motion Flur", "Keine Bewegung mehr erkannt -> Timer gestellt")
    timer = createTimer(now.plusSeconds(10), [ |
        timer = null
        FlurSchalter.sendCommand(OFF)
        logInfo("Motion Flur", "Timer abgelaufen -> Licht aus")
    ])
end

I hope it will work :wink:

By the way: is it possible to implement Hue scenes in a future version?

Looks nice. I would add an timer.cancel in the rule for OFF to ON.

Definitely , Yes. But my priority is to start working on the group support first.

1 Like

Where exactly? :thinking:

Right at the beginning. It should be cancelled every time we will go back into the room. But do not forget to check for null in advance.

Like this?

var Timer timer = null

rule "Flur Motion Sensor ON" 
when 
    Item Flur_MotionSensorPresence changed from OFF to ON
then
    if(timer === null || timer.hasTerminated) {
        timer.cancel
        timer = null
        FlurSchalter.sendCommand(ON)
        logInfo("Motion Flur", "Bewegung erkannt -> Licht an")
    }
    else {
        timer.cancel
        timer = null
        logInfo("Motion Flur", "Bewegung erkannt -> Timer gelöscht")
    }
end

rule "Flur Motion Sensor OFF"
when
    Item Flur_MotionSensorPresence changed from ON to OFF
then
    logInfo("Motion Flur", "Keine Bewegung mehr erkannt -> Timer gestartet")
    timer = createTimer(now.plusSeconds(10), [ |
        timer.cancel
        timer = null
        FlurSchalter.sendCommand(OFF)
        logInfo("Motion Flur", "Timer abgelaufen -> Licht aus")
    ])
end

Maybe it is sufficient to cancel the timer only in the else branch.

1 Like

Yes, it make sense.

Another question, what is the advantage of using Hue groups? (now I’m using groups openHAB)

Short version:

  • We need them to support the new luminaires. They combine more than one controllable light in one device.
  • The number of commands are restricted to 10 per seconds. If you have more than 10 lights in a group you will see artifacts when you try to control them.

Have a look here or here for detailed examples.

2 Likes

in openhab i have added 10 hue motion sensors . so now i have all my hue motion sensors with the right name but for the temperature sensors i cant tell which temperature sensor belong to hue sensor . they are all in the Hue temperature sensor 1 or Hue temperature sensor 2 until Hue temperature sensor 1 10.
how to tell which temperature sensor belong to a room motion sensor?

thanks

@uddup1976 Can you check the output of the API if you navigate to http://<bridge ip address>/api/<username>/sensors in your browser? Maybe we can find a property which will relate the different sensors.

Otherwise keep in mind that every Philips Hue Motion sensor owns three different IDs - one for each sensor part - and they are - most of the time - increased by one during creation. Meaning if the ID of your ZLLTemperature is 10, the IDs of
the related ZLLPresence and ZLLLightLevel are 11 and 12.

Hey,
just another question.
Working with the Hue motion sensors is very nice. But now I tried to use the illuminance sensor. I added the following if-condition after the “then” in my rule above:

rule "Flur Motion Sensor ON" 
when 
    Item Flur_MotionSensorPresence changed from OFF to ON
then
    if (Flur_Illuminance.state > 30 && FlurSchalter.state == OFF) {
        return false
    }
    if(timerFlur === null || timerFlur.hasTerminated) {
        timerFlur = null
        FlurSchalter.sendCommand(ON)
        logInfo("Motion Flur", "Bewegung erkannt -> Licht an")
    }
    else {
        timerFlur.cancel
        timerFlur = null
        logInfo("Motion Flur", "Bewegung erkannt -> Timer gelöscht")
    }
end

This is working, if I walk into the room. But when I leave the room and come back after the lights turned off, the lights won’t turn on again.

Any idea how I can solve this?