How to cancel a timer (invoked using an "every" block)?


#1

1) Give a description of the problem
Is it possible to cancel a timer (invoked using an “every” block of code) once it has started?

I have created a simple piston with only an “every” block inside it, something like “every 15 minutes, do this…”. This is based on the suggestion by @Mike1616 in this post:

No matter what I have tried so far, I just can’t get the timer to cancel its scheduled jobs / tasks once it has started. The timer even laughs in the face of the “Cancel all pending tasks” command (despite the console logs stating that jobs / tasks have been cancelled, the timer’s countdown clock on the Dashboard still continues to count down happily, and the Quick Facts show that there is a next scheduled task).

2) What is the expected behavior?
I want to be able to invoke the timer (using an “every” block) and then be able to kill that timer altogether through whatever means (from another piston, inside the timer piston itself, global variable switching etc.) so that it’s countdown clock completely ceases and desists, until I decide to invoke the timer piston again at a later time.

Ideally, I don’t want to go down the route of pausing / resuming the timer piston just to stop / restart its timer. It also seems like a no-no to nest an “every” timer inside an IF condition (I get a banner warning when attempting to do so).

3) What is happening/not happening?
I am not able to cancel the timer once it has started. It seems invincible.

4) Post a Green Snapshot of the pistonimage
No green snapshot of a piston included, as the timer piston is so simple, and I just want to see whether or not the concept of cancelling an “every” timer is at all possible.

5) Attach any logs (From ST IDE and by turning logging level to Full)
(PASTE YOUR LOGS HERE BETWEEN THE MARKS THEN HIGHLIGHT ALL OF THE LOGS SND CLICK ON THE </> ICON TO FORMAT THEM)


#2

You are correct, the “Every” should not be nested…
But… the opposite is a good solution. For example:

Every 15 minutes
do
    IF conditions are true
    Then
        Do cool stuff
    END IF
END EVERY

#3

The point of an every loop is to execute EVERY whatever. So, if you cancel, it will just pick up again at the specific interval. It might reset the clock but you can’t cancel it. That is why it is an every loop. If you want something you can turn on/off you need different logic like a do while ‘switch is on’ or something like that to give you control.