I would like to share this example with everyone because I persevered through the learning process on my own to make this work, and it is my first working ‘complex’ PLEG. I am a PLEG novice, and this took me a long time to script correctly.
This was created to achieve the following:
-Turn on my eave lighting when it becomes dark
-Ensure that my lights do not turn back on if they are turned off from the wall switch after the scene has run.
-Turn off my eave lighting at a specified time
The first requirement was fulfilled by creating a schedule called sDark which specified that dark would be satisfied 30 min after sunset until 30 min before sunrise. It also required the status of 2 different lights, My Bedroom Eave Dimmer which is captured by the Trigger tBdrmEaveOff; and my Livingroom Eave Dimmer, which was captured by the Trigger tFrontEaveOff. There’s no point turning the lights on if they are already on, so these Triggers allowed me to check their status before turning them on as well as allow me to use them in the requirement below.
The second requirement was achieved by using a sequence expression in the condition. What it said was that the scene would only run if it became dark AFTER either light was turned off. Therefore, if either light was turned off locally after the scene fired, it would not fire again.
The Condtition is named cEveningLightsOn and is written:
(tBdrmEaveOff or tFrontEaveOff) and sDark and (tBdrmEaveOff; sDark) and (tFrontEaveOff; sDark)
It checks first to see if either light is off, and it is dark, and if they were turned off before it became dark.
The actions attached to this code are that the 2 lights mentioned above are turned on.
It is also worth mentioning that this only works effectively if your lights support instant status.
The third requirement was fulfilled by creating a schedule called sGoodNight that specified that the lights would turn off at 11:30 PM. I chose this time because here in the summer the sun will not set until 10:25pm on the longest day, so I did not have to create an additional conditional argument checking to see if it was actually dark before running the condition.
This condition was very simple compared to turning the lights on and is called cLightsOutNight:
(!tBdrmEaveOff or !tFrontEaveOff) and sGoodNight
It checks to see if either light is on, and it is 11:30PM, and if true, turns out the lights.