$Var Event Count within $var number of minutes before $now


1) Give a description of the problem
I am attempting to keep track of prior events on a device at an interval of between 1 minute and 1 hour.
I unfortunately cannot find sufficient documentation to do so without help I super apologize. I cant tell how to use any of the arguments or expressions necessary to get what I want working on a piston.

2) What is the expected behaviour?

         [Device] = [Open/Active] at least [X] times in the last [Y] Minutes

           THEN   Do setVariable  [Bool] = True 

                 [Device] = [Open/Active] less than [X] times in the last [Y] Minutes

                    Do setVariable  [Bool] = False

3) What is happening/not happening?
I honestly cannot wrap my head around enough of the core scripting to get anything resembling what I am looking to do. I can’t tell if I need to create a shifting array (or how to use arrays in core for that matter) Or if there is a piston level system variable that stores old events that I can compare to the $now variable or If I need to store a variable each time the device triggers passing $now on trigger. I would greatly appreciate any guidance and or pistons that can achieve the effect.

Disclaimer I unfortunately am not looking for a “Was inactive” or “wait” I am looking to count the number of activations of a given event in the past [X] timeframe in minutes.

I’ve been searching all day and I can’t even get off the ground with this. Is this even possible?

PS I actually worked for ST in the past and was there during the migration to the new app

Thank you :smiley:


These system variables might be of use to your project



I do something similar with my cameras. If I get so many events on my cameras in 30 minutes when I am home then I disable them. They are battery powered and I don’t want to record a bunch of videos of me riding the lawn mower around the yard. I always forget to disable them on the weekends when I am doing yard work.

I use on Event, This is one my my more complicated pistons, but maybe it will give you some ideas. The comment before the execute is not 100% correct I have lowered the number of events it takes to disable cameras. It also may not be the optimum way to do what I am doing, but it works well.


I believe that I have this somewhat working. It’s not perfect, I’ve taken a shift register approach. In a separate piston when a motion event is triggered, it pushes an update to a global variable passtolistdenmotion which is called by this piston and pushed to a local variable nextvalue. Upon each execution of the piston the new motion event time+7 minutes is stored in a new element iterating up to 5.
At the end of the execution the array/list values are evaluated as to whether or not they are after $now. I had a hell of a time with data types and getting the dates to compare… whoof. If they are all evaluated to have happened within the last 5 minutes then a variable for use in a separate piston that iterates is switched to true.

I’m sure this could be done more easily, but I have no idea how. I’m interested to see if there’s a better way. @Terminal I was unable to decipher what exactly was going on in your piston but then again. I literally started this yesterday so I guess that’s to be expected. Is there a principal difference between what you’ve done and the method I’m using?

I would really appreciate any feedback and or corrections as I’m not sure that I’ve done any of this correctly. Also I used @eibyers piston from another post to get this all running. Without that I wouldn’t have know the syntax or basically anything. I would love any feedback though. I’m certain I’m just a noob.


Sorry first off I didn’t realize you had not done anything in webcore I just assumed you couldn’t come up with a way to count an event. What you have might work if you test it. I really didn’t examine it that close, as the the main problem I see is there is no trigger. So the piston will never fire. There is probably a message in the webcore dashboard when you open that piston warning you of this.

Probably should check out this thread.

Then again I could be missing something.


Thank you for that. The Piston is triggered by an external piston that has an asynchronous timer. Ooooh, that just gave me a thought. I can drive this pistons execution on motion instead of a timer that way the list is updated literally by the motion. THANK YOU haha. that might work better than it does now…but wait if I do that and there is no motion event then the piston will not evaluate the time differential. Ill have to do both. I think thats a better idea. :smile:


That is what my original piston does. The first part The ON event. Triggers on motion, so it counts the event triggers. The second part the On every triggers every so often so that when my time limit is up it clears everything and I get my notifications.