Motion-triggered lights seem like a simple application for PLEG. The trouble usually comes in trying to handle options like forcing the light to stay on or other refinements.
Starting with a simple example, consider the following. If it is night, the light is off and motion is detected, AutoOn will fire and turn on the light. When this happens or motion is detected while the light is on, KeepOn will fire and start or restart Timer. When Timer ends and the light is on, AutoOff fires and turns off the light.
Timer can be set for any required interval from a few seconds to several hours. This example will only work with motion sensors that have a short on-time (the time that they stay tripped after detecting motion). I set mine to five seconds or however low they will go. None of the Conditions require Repeats to be checked.
Triggers
LightOn Light is turned on
Motion Motion Sensor is tripped
ItsNight DayTime indicates night
Schedules
Timer On: Self-ReTrigger Off: Interval 5:00
Conditions
AutoOn !LightOn and ItsNight and Motion
KeepOn (LightOn and Motion and (LightOn; Motion)) or AutoOn
AutoOff LightOn and !Timer and (LightOn; !Timer)
Actions
AutoOn Turn Light on
KeepOn PLEG StartTimer timerName=Timer
AutoOff Turn Light off
Now what if you want to be able to force the light to stay on even if no motion is detected? This can get tricky. If you can reach the wall-switch without tripping the motion detector you can use this:
AutoOff LightOn and !Timer and (LightOn; !Timer) and (AutoOn; LightOn < 10)
AutoOff can only fire if the light was turned on less than ten seconds after AutoOn fired - and was therefore probably turned on by motion. If you turn the light on manually before motion is detected, it should stay on until you turn it off manually. This will only work with switches that report instant status.
If you cannot reach the wall-switch without tripping the motion detector, you could try this:
AutoOff LightOn and !Timer and (LightOn; !Timer) and (!LightOn; LightOn > 10)
This will prevent AutoOff from firing if the light was turned on less than ten seconds after it was turned off. So if you turn the light off and back on quickly, it should stay on until you turn it off. This will only work with switches that report instant status.
One problem with the last change is that, when you try to turn off the light manually, if you trip the motion sensor it will turn it back on until Timer ends. You can prevent this with the following change:
AutoOn !LightOn and ItsNight and Motion and (!LightOn; Motion > 10)
This prevents AutoOn firing for ten seconds after the light was turned off.
There are many other wrinkles that can be added to the logic. My personal favorite for my outside lights is to use the second switch input of Fibaro FGS211 modules to provide a dedicated hold-on or hold-off function.
Triggers
LightOn Light is turned on
Motion Motion Sensor is tripped
ItsNight DayTime indicates night
HoldSw Hold Switch is turned on
Schedules
Timer On: Self-ReTrigger Off: Interval 5:00
Conditions
AutoOn !LightOn and ItsNight and Motion and !HoldSw
KeepOn (LightOn and Motion and (LightOn; Motion)) or AutoOn
AutoOff LightOn and !Timer and (LightOn; !Timer) and !HoldSw
Actions
AutoOn Turn Light on
KeepOn PLEG StartTimer timerName=Timer
AutoOff Turn Light off
If the Hold switch is turned on while the lights are off, they will not come on when motion is detected. If the Hold switch is turned on while the lights are on, they will not be turned off automatically. Used in conjunction with the primary on/off switch, I can set auto mode, always on or always off.