PLEG Light Automation for Sunset/Sunrise

I have a number of outdoor lights I want to automate timing on using Sunset and Sunrise as the points in time. Obviously Sunset and Sunrise are variable depending on where you live, but I would expect if an application has the option to use these values, they should work. I want a select set of lights to turn on 30 minutes before sunset and all lights to turn off 30 minutes after sunrise. The after sunrise, early turn off for the landscape lights, and Porch coordinated lights work just fine. For some reason the sunset part of this is not working. Any help would be greatly appreciated.

Schedules

Name Type Time Days Random On Delay Off After Type Off Time Off Days Random Off Delay
Sunset Weekly -00:30:00t 1,2,3,4,5,6,7 None None None
Sunrise Weekly +00:30:00r 1,2,3,4,5,6,7 None None None
OffTimeLate Weekly 00:00:00 1,2,3,4,5,6,7 None None None
OffTimeEarly Weekly 22:00:00 1,2,3,4,5,6,7 None None None
Device Properties

Name Device Name Device Variable
BackPorchStatus Back Porch Light Status
Conditions

Name Expression
SunsetLights Sunset
SunriseLights Sunrise
FrontLanscapeNightOff OffTimeEarly
PorchOn BackPorchStatus == 1
PorchOff BackPorchStatus == 0
Actions

Actions for Condition: SunsetLights

Immediate

Device Action Arguments
Front Porch Light SetTarget newTargetValue=1
Frontyard Landscape Lights SetTarget newTargetValue=1
Garage Light SetTarget newTargetValue=1
Actions for Condition: SunriseLights

Immediate

Device Action Arguments
Back Porch Light SetTarget newTargetValue=0
Backyard Landscape Lights SetTarget newTargetValue=0
Front Porch Light SetTarget newTargetValue=0
Frontyard Landscape Lights SetTarget newTargetValue=0
Garage Light SetTarget newTargetValue=0
Actions for Condition: FrontLanscapeNightOff

Immediate

Device Action Arguments
Frontyard Landscape Lights SetTarget newTargetValue=0
Actions for Condition: PorchOn

Immediate

Device Action Arguments
Backyard Landscape Lights SetTarget newTargetValue=1
Actions for Condition: PorchOff

Immediate

Device Action Arguments
Backyard Landscape Lights SetTarget newTargetValue=0

PLEG will work off sunset/sunrise. Vera knows from your address what time they are.

Create one schedule that starts 30min prior to sunset and ends 30min after sunset, every day. Call it

DuskToDawn

Create two conditions:

LightsOnSunset Input DuskToDawn
LightsOffSunrise Input NOT DuskToDawn

Create your LightsOnSunset action and your LightsOffSunrise actions, selecting the devices to switch.

this is all of one schedule. two conditions and two actions.

Or, you could very easily create two scenes.

The problem with your current logic is that, because none of your Schedules have off-events, the Conditions are remaining true so do not fire again.

You can fix this by renaming SunsetLights, SunriseLights and FrontLanscapeNightOff with an underscore prefix: _SunsetLights, _SunriseLights and _FrontLanscapeNightOff. This will allow them to fire each time the Schedule on-event occurs.

Rex, can you explain why you need the underscore? I understand the underscore allows it to be true every time vs just when the initial state changes without the underscore.

However, why would the logic not work without the underscore?

Thanks!

You condition:

SunsetLights Sunset

The SunSet schedule ONLY has an ON time. So the SunsetLights Condition is ALWAYS True. It get’s evaluated every time the input schedule Sunset fires … but it’s already true. So by renaming this condition to _SunsetLights it will fire each time.

I’ve made the change to use the _, but I’m struggling to understand why that is necessary or if it’s some special character that PLEG uses to assist with this type of scenario. The schedules are just times during the day, and on any given day each schedule is only true at one point during that day. So how are the conditions always true? Thanks for the help with getting this working, I really have loved using PLEG to automate things instead of the built in Vera controls.

When you have a schedule with no off-time, it only raises one event: the on-event. If you have used the schedule in a condition, the condition will be evaluated following the on-event at which time the schedule’s value will be true. The lack of an off-time and, therefore, an off-event means that the condition will not be evaluated when the schedule’s value is false. Consequently the condition will remain true even though the schedule’s value is no longer true.

If the condition includes another term which does change, it will be re-evaluated using the then-current value of the schedule. This can give rise to erratic behavior as it masks the underlying problem.

Conditions normally fire their actions when they change from false to true. Prefixing a condition name with an underscore causes special handling so that the action will be fired each time the condition is evaluated as true.

Another solution is to add an off-time to the schedules. I use an interval of ten seconds. This will raise an off-event and re-evaluate the conditions with the schedule’s value being false. With this approach you do not need the underscore prefix.

Have you seen PLEG Basics?

This makes a lot more sense now, thanks. And thank you for the basics doc. As a matter of better programming, would you suggest that I update my schedules with an off time in the schedule instead of using the “_”? Also, just to make sure I understand this correctly, the off time would not actually turn the lights off because there is no action to act upon when the condition is not true.

Personally I prefer to have an off-time for schedules that fire once per day rather than use the underscore prefix. I mostly use a short interval - say ten seconds. I use underscore on conditions that will fire several times during the day - like changes to thermostat setpoints. It is just my preference, though.

Also, just to make sure I understand this correctly, the off time would not actually turn the lights off because there is no action to act upon when the condition is not true.
Exactly. Unless you add a condition that fires on the schedule becoming false, with an associated action, the off-event will just reset your condition.