Conditional trigger. How to?

I want to create a scene in my dear Vera that turns on a few lights in my home if the proper code is punched into my deadbolt keypad.

I know how to trigger based on a successful keypad code entry already as I use it to turn off my alarm system.

The thing I’d like to do is add an IF condition that when I trigger upon a code entry AND IF it is past sunset then turn on these lights.

I just am not sure the best way to do this, via LUA code or by this PLG stuff I am seeing.

I’m not a software coder but willing to learn.

Step 1: Install the following plugins (From Apps Store):
Program Logic Event Generator
Program Logic Core
Day or Night Plugin.
After each install Vera will Restart.
When all are loaded … Refresh your browser (usually the Function F5 key)

Step 2:
Make sure you have set the location and timezone of your Vera up properly.
This is in the Setup → Location tab at the top of your Vera. This is so Vera can accurately determine sunrise and sunset for your location.

Step 3:
Setup the Day or Night plugin.
I use 20:00 minutes before sunrise (-20:00) for day and 20:00 after sunset for night.
Save your changes.

Step 4:
If you think about problems as IF Something then do SomethingElse.
In PLEG the Something is called a condition expression. With is a combination of one or more events in Vera. The SomethingElse are called Actions in PLEG.

Lets setup some input triggers for PLEG (Program Logic Event Generator) (Similar to setting up a trigger for a Scene). In PLEG every input has a name.

Create a trigger called NIGHT and base it on the Day or Night Plugin indicating Night.

Create a second trigger called Door and base it on a Key code (of *) on your door.

Now we will create a condition based on the inputs.
We will create a condition with a name of AutoLightOn. It’s expression is:
NIGHT and Door

Simple enough! Now lets add an action for this condition. (Similar to selecting devices for your scene). Select the light to turn on.

Step 4:
Arm your PLEG. Actions only happen when the PLEG is armed.

[hr]
Well we just got started.
Let’s add some extra credit to this example:

Maybe you want the light to go off after 15 minutes. Let’s add another condition called AutoLightOff with an expression of:
AutoLightOn; NOW > 15:00

This is a little more complex expression. It’s called a sequence expression. NOW is a like a 1 minute interval timer trigger. This statement says that when the NOW interval trigger fires … and it’s 15 minutes past the time that AutoLightOn was triggered … that this expression will be true.

Add an appropriate Action to this condition.

[hr]
You will find the Status command to be useful in understanding what is happening in your PLEG logic. Have fun … go out and tackle that next automation project!

Many thanks. I’ll give it a go. I installed Day/night device/app yesterday after reading about it somewhere. That was simple enough. Now onto the PLEG stuff.

I could become dangerous… ;D

Well it turned out to be pretty easy to do this. My first foray into Lua code.

I wanted lights to go on when someone opened the garage door deadbolt by entering the proper keycode. The catch was I only wanted the lights to go on if this occurred at nighttime. No need to turn on lights during the day.

I already have a scene that is triggered by the entry of a proper code in my deadbolt so I was confident the trigger event was sound. The one I have turns off the alarm system through my AD2USB interface. That has been working for many weeks. So once you enter the proper deadbolt code you don’t have to enter another code at the alarm panel.

So I created a new scene and set it up to turn on the few lights I had in mind for a welcome home setup. I set it to use the same trigger as my alarm off scene. All I had to do to add the condition of nighttime only was paste the code below into the code window of LUUP tab for that scene.

if (luup.is_night()) then
return true
else
return false
end

That was it. If the deadbolt PIN code is entered before “Night” a false is returned and the scene is not run. If it is after night then a true is returned and the scene runs through to completion. As I understand it the LUUP code is run prior to the actions defined in the scene. If the bottom of the LUUP code returns false it skips execution, if true it runs the scene.