Ignore triggers within a time period

conditions
triggers
piston

#1

1) Give a description of the problem
Piston triggers twice in quick succession instead of just once

2) What is the expected behavior?
Piston only triggers once in a set time period (e.g. once per X minute) and ignore repeated triggers in that period.

3) What is happening/not happening?
Piston triggers twice in quick succession instead of just once

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

**5) Attach any logs

4/10/2019, 8:46:28 AM +40ms
+0ms ╔Received event [Home].execute = x.x.x.x with a delay of 74ms
+9887ms ║RunTime Analysis CS > 29ms > PS > 9817ms > PE > 41ms > CE
+9888ms ║Piston waited at a semaphore for 9772ms
+9890ms ║Runtime (37982 bytes) successfully initialized in 9817ms (v0.3.104.20180323) (9889ms)
+9892ms ║╔Execution stage started
+9898ms ║║Cancelling statement #1's schedules...
+10573ms ║║Executed physical command [Speakers 
Group].playTrack([http://a.a.a.a/someoneisatthedoor.mp3]) (669ms)
+10575ms ║║Executed [Speakers Group].playTrack (671ms)
+10579ms ║║Cancelling statement #3's schedules...
+10599ms ║║Executed virtual command sendSMSNotification (14ms)
+10615ms ║║Executed virtual command sendSMSNotification (8ms)
+10618ms ║╚Execution stage complete. (727ms)
+10619ms ╚Event processed successfully (10620ms)
4/10/2019, 8:46:27 AM +664ms
+2ms ╔Received event [Home].execute = x.x.x.x with a delay of 134ms
+145ms ║RunTime Analysis CS > 35ms > PS > 72ms > PE > 38ms > CE
+148ms ║Runtime (37909 bytes) successfully initialized in 72ms (v0.3.104.20180323) (144ms)
+149ms ║╔Execution stage started
+155ms ║║Cancelling statement #1's schedules...
+842ms ║║Executed physical command [Speakers 
Group].playTrack([http://a.a.a.a/someoneisatthedoor.mp3]) (680ms)
+843ms ║║Executed [Speakers Group].playTrack (682ms)
+847ms ║║Cancelling statement #3's schedules...
+927ms ║║Executed virtual command sendSMSNotification (74ms)
+939ms ║║Executed virtual command sendSMSNotification (5ms)
+942ms ║╚Execution stage complete. (793ms)
+943ms ╚Event processed successfully (943ms)

This piston is incorrectly getting triggered twice by an external Tasker rule. Rather than try and fix the thing causing the trigger, I want to make my Piston robust and resistant to such false triggers by making it ignore any extra triggers within a set time period. Essentially, implement debounce logic.

So if this piston already ran within the last minute, then ignore it.

Is there an easy way to do this?


#2

Set a boolean variable on first run to true, include that variable in logic to see if it’s already true. Set a timer for a minute (set it to never cancel) to reset the boolean to false.


#3

@eibyer Thank you for your suggestion. Would something like this work?


#4

For no more than once per minute, I am a fan of this style:

define
    integer lastRan = (not set)
end define

execute
    IF $minute is different than {lastRan}
    Then
        Set variable {lastRan} = $minute
        Do cool stuff
    END IF
end execute

#5

I like this a lot! Thank you. I tried to make the Piston and I think I got it. See screenshot below


#6

Other than the ASYNC, it looks good to me. :+1: