You want to act on the initial trigger-event and then ignore (lock-out) all subsequent trigger-events received within a given time period. Yes?
I had the same requirement when I created the
DoorBell Sensor module. When a visitor rings the doorbell, I want to log the time and potentially trigger other actions. I don't want to log multiple consecutive rings (i.e. visitor presses doorbell repeatedly). The initial ring initiates a lock-out period during which subsequent rings are ignored.
Download the module and you'll see that it has an adjustable LockOutTime (0-120 seconds, default is 30). Implementing the lock-out period is simple. Here is the code for the
OnChangeState method (i.e. triggers on each ring):
Code:
if sysevent.newVal then
if DateDiff("s", this.LastRing, now) > this.LockOutTime then
this.UpdateCounters
end if
end if
Basically if the elapsed time (in seconds) since the last ring exceeds the LockOutTime then accept the ring and proceed to do something useful else ignore it and do nothing.
In the example above,
UpdateCounters increments the ring counters and records the date and time of the current, accepted ring (this.LastRing).
The Doorbell Sensor module does have a timer but it plays no part in the lock-out period (it resets the ring counters at 12:01 AM).
BTW
You may have already seen this thread "
When you're a hammer, everything looks like a nail" but if not, it discusses how Premise's Logic Diagrams can be used for automation in lieu of scripting. Some problems are easier to solve with diagrams whereas other via scripting. I hate to admit it but, even after writing that post, I'm still a "hammer" guy and rely mostly on scripting.