Hi rigpapa
A few years ago, I was battling how to tell if a light has been turned on automatically by movement or manually at the switch. I solved it using a PLEG and it has served all my lighting requirements for a long time.
When I came across your thread, I thought WoW this is exactly what I need to get rid of a lot of complicated PLEG expressions and make my VERA run a little bit more smoothly (hopefully). So I bypassed my Internal Light PLEG (and External Light PLEG) and replaced them with your DelayLight Plugin. I have been running like this for a few weeks, but have reluctantly now gone back to my PLEG solution.
I have been “fighting” my lights. i.e. I turn my kitchen light off and your plugin immediately turns it back on or vice-versa. I never had this problem with my PLEG solution.
I am the first to admit my logic is basic, but the following was built on practical evaluation. Somewhere there is a key difference between what you are doing and what I am doing in PLEG. It makes me sad to go back to PLEG and would much rather use your solution. If you would comment so I can use your Plugin without any problems, I would be very happy.
I have four conditions in a PLEG;-
- cLightOn = VERA turns the light on automatically by movement at night
- cManualOn = The light has been turned ON manually by a person
- cLightOff = VERA turns the light off automatically
- cManualOff = The light has been turned OFF manually by a person
After much experimenting, I used the following expressions for each of the above;-
- cLightOn = (cManualOff ; tMotion > 10:00) AND !tLightOn AND tNight AND tMotion AND (!tLightOn ; tMotion)
- cManualOn = tLightOn AND !(cLightOn ; tLightOn < 10 )
- cLightOff = tLightOn AND !tMotion AND (!tMotion ; NOW > 3.00) AND (!cManualOn OR (tLightOn ; NOW > 29:00))
- cManualOff = !tLightOn AND !(cLightOff ; !tLightOn < 10 )
To look more closely at each;-
- cLightOn = (cManualOff ; tMotion > 10:00) AND !tLightOn AND tNight AND tMotion AND (!tLightOn ; tMotion)
This means automatically turn the light ON, when ALL the following are TRUE;-
• (cManualOff ; tMotion > 10:00) = It is at least 10 minutes since the Light has been turned off at the switch
• !tLightOn = NOT LightOn i.e The Light is currently OFF
• tNight = it is dark (defined elsewhere)
• tMotion = The room is occupied
• (!tLightOn ; tMotion) = Motion AFTER the time that the light went OFF (!=NOT)
This last condition was necessary to prevent the Light being immediately turned back on after I turn it off manually. My light switch is within range of the motion sensor, so tMotion will be True, but its time stamp will be BEFORE the time the light was turned off. This prevents the light being turned back on until new motion AFTER the light has been turned off)
-
cManualOn = tLightOn AND !(cLightOn ; tLightOn < 10 )
The expression in brackets is true if the light turns on less than 10 seconds after a command to turn the light on automatically. It is then likely to be an automatic On. The “!” negates that, so the Light is ON but it was turned on manually. -
cLightOff = tLightOn AND !tMotion AND (!tMotion ; NOW > 3.00) AND (!cManualOn OR (tLightOn ; NOW > 29:00))
This will turn OFF the light, when ALL the following are TRUE;-
• tLightOn = The Light is ON
• !tMotion AND (!tMotion ; NOW > 3.00) = there is NO motion NOW and the last motion was more than 3 minutes ago
• (!cManualOn OR (tLightOn ; NOW > 29:00)) = Turn light OFF when AUOMATICALLY turned on, 3 minutes after last motion
OR after 29 mins if turned on MANUALLY (plus more time if motion continues).
- cManualOff = !tLightOn AND !(cLightOff ; !tLightOn < 10 )
This works out if the Light has been turned OFF manually in a similar to the Manual On above
To summarise:-
A Light turned OFF manually will not come back on for at least 10 minutes
A Light turned ON manually will stay on for at least 29 minutes, and will stay on while motion continues; only turning off 3 minutes after motion ceases, and I get no “fighting” problems.