Here is what could happen with that Rule as written.
- GF_Bathroom_Motion changes from OFF to ON
- “GF_Bathroom_Motion” Rule triggers
- Send ON command to GF_Bathroom_NightLight
- Set a 10 minute timer
- GF_Bathroom_Motion changed from ON to OFF
- GF_Bathroom_Motion changed from OFF to ON
- “GF_Bathroom_Motion” Rule triggers
- Send ON command to GF_Bathroom_NightLight
- Set a 10 minute timer
- The first 10 minute timer triggers and sends the OFF command to the light
- The second 10 minute timer triggers and sends the OFF command tot he light
The Rule doesn’t take into account that there is already a Timer running so no matter what happens, the light will turn off in 10 minutes after the first time the Rule triggers.
At a minimum you need to check to see if there is already a Timer running and reschedule it.
if(timer_bathroom != null) {
timer_bathroom.reschedule(now.plustMinutes(10))
}
else {
...
}
That will reset the Timer to go off for subsequent motion detections rather than setting a new Timer for every event.
A comprehensive writeup is Design Pattern: Motion Sensor Timer