Motion detection getting me crazy

Here is what could happen with that Rule as written.

  1. GF_Bathroom_Motion changes from OFF to ON
  2. “GF_Bathroom_Motion” Rule triggers
  3. Send ON command to GF_Bathroom_NightLight
  4. Set a 10 minute timer
  5. GF_Bathroom_Motion changed from ON to OFF
  6. GF_Bathroom_Motion changed from OFF to ON
  7. “GF_Bathroom_Motion” Rule triggers
  8. Send ON command to GF_Bathroom_NightLight
  9. Set a 10 minute timer
  10. The first 10 minute timer triggers and sends the OFF command to the light
  11. 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