How to prevent piston to run multiple times in certain time?


#1

1) Give a description of the problem
Kids are pressing (doorbell) button multiple times when only one time is needed… :slight_smile:

2) What is the expected behaviour?
If button is pressed triple or what ever times -> only one message “someones at the back door” is sent. Same for PUSH notification too…

3) What is happening/not happening?
I get multiple notifications… if kid presses doorbell like a maniac…

**4) Post a Green Snapshot of the piston![image|45x37]


#2

You likely want another variable, where you store the time of the last push, then can compare that time to whatever offset you want for not sending additional messages.


#3

I’ll take a stab here… I’d use a wait inside your then(after the send), and then go into the settings/advanced options for your if statement and set the task cancellation policy to “never cancel tasks”. What this should do is force the piston to wait whatever amount of time you specify before it can be triggered again.


#4

That doesnt work:

:frowning:


#5

uuh… feels complex… “wait” was good idea but did not work.


#6

I dont think the task cancellation policy will stop another instance of the piston running.

Set a variable at line 21 e.g bell_pressed = true
set it back to false after the wait
on the if statement, add “and bell_pressed is false”

You will need to set the value to false initially in the IDE, dont set this when you define it, otherwise it will be set to false everytime the piston runs


#7

Ok I got it now! Thanks everybody!