Hello, i have problem with rules. I want make automatic Light when somebody is in Bathroom. If Motion Sensor changed to ON i want to again set timer to 5 minuts.
rule "Auto Lights ON - Bathroom"
when
Item DoorSensor_Status changed to OPEN or Item MotionSensor_Bathroom_MotionStatus changed to ON
then
if (Bathroom_Light.state == OFF)
{
Bathroom_Light.sendCommand(ON)
Motion_Timer = createTimer(now.plusMinutes(5),
[|
Bathroom_Light.sendCommand(OFF)
])
}
else
{
Motion_Timer.reschedule(now.plusMinutes(5))
}
end
Can you explain the main Problem, what is working and what don’t work, like you expect.
How long needs the Motion Sensor to change his state to OFF?
Is the light turning on and don’t turn off after 5 min?
I would add a Motion_Timer = null at the end of the timer code.
Has the bathroom also a manual switch for the light?
rule "Auto Lights ON - Bathroom"
when
Item DoorSensor_Status changed to OPEN or Item MotionSensor_Bathroom_MotionStatus changed to ON
then
if (Bathroom_Light.state == OFF)
{
Bathroom_Light.sendCommand(ON)
}
end
rule "Auto Lights OFF - Bathroom"
when
Item MotionSensor_Bathroom_MotionStatus changed from ON to OFF
then
if (Bathroom_Light.state == ON)
{
createTimer(now.plusSeconds(300), [ |
Bathroom_Light.sendCommand(OFF)
])
}
end
It worked but sometimes when i was in bathroom “Lights OFF”. Now i want to make
When i enter Lights ON
When sensor again changed to ON “Time = Time + 5 min”
After “Time” Lights OFF
I have manual switch SonOff (MQTT). Now rules work but no add 5min after sensor changed to ON again
@kamyrdol32 I didn’t test this so you may need to tweak it a bit.
rule "Auto Lights OFF - Bathroom"
when
Item MotionSensor_Bathroom_MotionStatus received update
then
if (MotionSensor_Bathroom_MotionStatus.state == ON && Bathroom_Light.state == ON)
{
createTimer(now.plusSeconds(300), [ |
return; // do nothing
])
}
else
Bathroom_Light.sendCommand(OFF)
end
Took your smartphone or laptop with you and check the event log if the motionsensor is turning OFF and ON again.
Use update not changed for triggering
and check the status later, like H102
rule "Auto Lights ON - Bathroom"
when
Item DoorSensor_Status changed to OPEN or
Item MotionSensor_Bathroom_MotionStatus received update ON
then
if (Bathroom_Light.state == OFF) {
Bathroom_Light.sendCommand(ON)
Motion_Timer = createTimer(now.plusMinutes(5), [|
Bathroom_Light.sendCommand(OFF)
Motion_Timer = null
])
} else {
Motion_Timer.reschedule(now.plusMinutes(5))
}
end