Premise Equivalent of "Pulse" in a script

Motorola Premise

mhilbush

Member
How would one implement the equivalent of the "Pulse" block in a script? I would like to use the functionality of Pulse but I need the flexibility of scripting rather than using a logic diagram.

In other words, there are a series of actions I want to take, but I only want to execute those actions once within a period of N minutes, even though the trigger event (e.g. sensing motion, door opening, etc.) may occur multiple times within the N minutes.

Mark
 
This isn't so easy as I'm sure you found out that the system.AddTimer method will overwrite any existing timer if it has the same name!

I think your event should trigger a vbscript that first adds the timer, but only if the timer doesn't already exist. The timer would contain the code you want to run once over a time period.

I remember (I think) that vbscript does not allow you to check if an object exists directly. However, if you do error catching I think you can solve that problem (try accessing a nonexistent object's property and an error will be thrown).

This idea should also work and may be simpler:
Code:
for each oTimer in modules.Default.Timers.GetObjectsByTypeAndPropertyValue(Schema.Timers.SimpleTimer.Path, "Name", "MyTimer")
bFoundTimer = true
next
Basically, you'd have two methods: CreateTimer and CheckIfTimerExists. CreateTimer would call CheckIfTimerExists and if it doesn't, it would create a timer using System.Addtimer. You can also use the colon operator in vbscript to put all of the lines of code into a single string to pass to Addtimer.

Of course, the code could run again after N minutes, provided another trigger is received, but I think this is what you want.
 
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.
 
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?
Yes, exactly. This solution is simple, efficient, and elegant.

Thanks,
Mark
 
Thanks, Mark.

No worries, etc6849. When I first encountered the problem words like timer, latch, and hysteresis swirled in my head. I gravitated to using a timer because the problem dealt with a time interval. Finally it dawned on me that I just needed to record the time of the desired event and use some arithmetic to discard subsequent events. It was definitely a Doh! moment for me!
 
Back
Top