Triggering a scene based on a sequence of events

I just got my Vera Lite and have my Elk M1 integrated with it, a couple of switches, and a Schlage lock. One of the things I want to do is to turn on the garage lights when someone enters. However, just opening the service door doesn’t mean someone is entering, it could mean someone is leaving. So, I want to look for a sequence of events that would indicate that someone is entering the garage. Basically, I want it to look something like this:

If (after sunset and before sunrise) { when PIN is entered on Schlage_Lock followed by Service_Door opening within 10 seconds then execute scene "Garage Lights On" }

Will I have to do this through LUA/LUUP? Or is there a pointy/clicky way to do it?

Does anyone have example code to do this? I can modify as needed. I’ve not done more than 5 minutes of LUA in my life, but I have experience with perl/ruby/python/C.

Is there some sort of Vera specific LUA crash course tutorial out there somewhere I can look at?

there’s no direct way to do this in the UI. So you’ll either need LUA code as you suggested, or you can use the excellent Combination Switch plugin by @futzle, which basically triggers if a sequence of events are true: http://forum.micasaverde.com/index.php/topic,10995.0.html

That might enable me to do what I want. However, I’d still like to see some code so I can learn from it. If anyone has code that does something like this, please post it so I can figure it out.

You’d need to express the code in terms of the asynchronous events (in your case, “PIN entered” and “Door opened”). Those two events will have to communicate through a shared variable so you can know if they happen within ten seconds of each other.

Pseudocode for the lock, when PIN entered:

note current timestamp, store it (somewhere)

Pseodocode for the door, when opened:

Get time of last lock PIN entry from (somewhere) if (time difference < 10) { if (currently night time) { invoke scene "Garage Lights on" } }

You can see that this is pretty much the inside-out of the code snippet that you posted.

Still with me? Here’s your homework: Use the Lua manual, the Luup extension function list and forum search to find similar code. Tell us what you find.