I try to switch off my lights, after 5 min when the hue motion detector recognized some motion via the expire binding.
This works as expected, but at the same time, the timer should be reseted to 5 min again if the momtion detector recognize a motion in between. Unfortunately, it switches off the light after 5 min and does not reset the timer.
light.rules
rule "Ankleidezimmer motion"
when
Item OG1_ak_motion received update ON
then
OG1_ak_motion_timer.sendCommand(ON)
end
rule "Ankleidezimmer motion timer"
when
Item OG1_ak_motion_timer changed to OFF
then
if
(OG1_ak_li_decke.state == ON) OG1_ak_li_decke.sendCommand(OFF)
end
Switch OG1_ak_motion "Bewegungsmelder Ankleidezimmer [%s]" <motion> (gOG1_ak) {channel="hue:0107:0017884b70dd:12:presence"}
Switch OG1_ak_li_decke { channel="...,expire="5m,command=OFF" }
rule "Ankleidezimmer motion"
when
Item OG1_ak_motion received update ON
then
OG1_ak_li_decke.sendCommand(ON)
end
Link the expire command (not state) directly to your switch, it will go to OFF after 5 minutes and will be rescheduled after each ON of your motion sensor.
Hi, this is the rule I use for my kitchen counter lights. it looks pretty similar to what youâre trying to do. I hope it helps
var Timer KitchenCounterTimer = null
rule âTurn on lights when motion triggeredâ
when
Item KitchenPIR received update
then
if(KitchenPIR.state == ON) {
if(KitchenCounter.state != ON) KitchenCounter.sendCommand(OnOffType.ON)
logInfo(âKitchenLights.rulesâ, âPIR Actuated KitchenCounter ON Sent and Timer Startedâ)
if (KitchenCounterTimer !== null) KitchenCounterTimer .cancel
KitchenCounterTimer = createTimer(now.plusMinutes(10), [ |
KitchenCounter.sendCommand(OnOffType.OFF)
logInfo(âKitchenLights.rulesâ, âTimer expired KitchenCounter OFF Sentâ)
KitchenCounterTimer = null
] )
}
end
@ Johan_H, Jon_Tree: I study several posts, where it was mention to use the expire binding instead - less code
@sihui: Understood what you mean, but if I study your code proposal correctly, it switches on the light at each movement - something, I donât want to have, as this room have a open connection to our sleeping - and I donât want to have full light at every movement in our bed ;->
Maybe I didnât understand what youâre trying to achieve The rule I use only turns the light on if it is not on already and sets a timer to turn it back off after ten minutes. If another motion is detected within that ten minutes it resets the timer back to ten minutes to start again so the light will turn off after no motion is detected for ten minutes.