Prevent Piston From Running For A Set Period Of Time


#1

I have a piston that works fine and all it does is set a global variable which I use in other pistons, I would just like to modify it to prevent it from running too frequently.

I was thinking about making a simple variable in the piston that was lastrun and just using $time to populate it. Then, I would just some logic in an IF block that was if lastrun is less than last run plus 5 minutes then break or something.

However, I don’t actually know how I can do this. What would the expression be?


#2

It would help to see the current piston, so we know what is currently triggering it.


#3

It’s a presence sensor with a trigger on events from the presence sensor, and then a switch for setting the variables. I just don’t want it changing the variable too frequently. Sometimes my presence sensor freaks out and changes back and forth a couple times, meaning, I’ll arrive home and it changes to present, then not present, then back to present again. This causing my automations to be all weird, so I’m hoping to just catch the initial change which is always correct. I thought about trying to use a time delay such as IF presence sensor stays present for 10 seconds, but I’m not sure how to do that in this piston either.

What I’m trying to achieve is something where the piston still executes because of the trigger, but it just doesn’t change the variable because it hasn’t been long enough yet. I figured if I did on events from presence sensor’s presence, IF current time is greater than last run plus 5 minutes, set variable, else exit.

EDIT: You can see the “lastrun” variable I had been playing with, I forgot to pull that back out. This is my test piston.


#4

Here’s what I’ve tried which I think will work…

__


#5

At a quick glance, that logic looks solid… :+1:
(as long as you want Switch 2 on/off to reset both TJ & SC’s LastRun)


#6

Yes, that’s just a virtual switch I was using for testing the presence sensors and making sure the code executed or did not execute. It seems to have worked this morning, so time will tell. Thanks!