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.
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…
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.
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.
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.
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.
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?
@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.