Multiple timers

timer

#1

1) Give a description of the problem
Multiple timers in one piston firing at same time.

I did some searching and from what I have seen on the forums it seems like multiple timers cannot fire synchronously in one piston. Is that the consensus? To be clear, multiple wait timers counting down to turn off multiple lights. It seems like first timer in wins when activated.

2) What is the expected behavior?
Multiple timers in one piston counting down synchronously

3) What is happening/not happening?
Async set but first timer in wins

4) Post a Green Snapshot of the pistonimage
(UPLOAD YOUR IMAGE HERE)

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)

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

Async is on or off? If it is on, that defeats the entire purpose of having wait statements. Async means that all the blocks within an async group happen simultaneously instead of consecutively.

When you say run “synchronously” do you mean async if off? Then yes, you can have multiple timers because it will run consecutively from beginning to end. Async is where the blocks run simultaneously. You are very confusing because you seem to be using synchronously and asynchronously as the same thing but they are infect diametrically opposed to each other. Sync and Async are different settings. If you want the timers in SEQUENCE, then don’t turn on ASYNC. :slight_smile:


#3

I think he meant having separate timers in multiple async events, and wanting the timers to run concurrently, such as below.

async with $device
wait 5 minutes
turn on
end with
async with $anotherdevice
wait 10 minutes
turn on
end with

But the message is a bit muddled and I haven’t had my first cup of coffee yet, so maybe I’m wrong. :thinking: :slightly_smiling_face:


#4

Then you’re not really running async then. Either you’re running the timers synchronously or asynchronously. If asynchronously, they run concurrently so the longest one wins.


#5

That’s my point. A wait timer inside multiple async events nullifies the async. I think you have confirmed my thinking. The wait timers cannot run all at the same time. Like another process thread would.


#6

Yes, basically.

async (this kicks off and runs)
if statement
wait (while this wait is occurring, the below async is triggered and both timers are running)
end

async
if statement
wait
end

I know this may not work which is why I’m asking. Just trying to find the boundaries with wait timers.


#7

I am just thinking outside the box here, but if all these devices are triggered by the same event, why not drop the async, and just code top to bottom accordingly.

Using the above example, something like this:

If statement
Do stuff
If statement
Do stuff
Wait 5 minutes
Do more stuff
Wait 5 more minutes
Do more stuff
etc

In other words, you can refer back to a particular light in numerous blocks throughout your code. This means, for example, you don’t have to keep all the commands for your Porch lights in the same block.


#8

The short answer to your question is that, yes, multiple waits in separate asynchronous tasks can work as in the piston below. The first light will turn off after 10 seconds, the second one ten seconds after that.

index

The next question has to do with best practice, and I can only tell you that I’ve always preferred the structure that @WCmore suggests, and for much the same reasons. The format above may seem simpler at first, but I personally find it harder to track and adjust the flow of the piston as you add to it over time.


#9

There’s is no reason to have the async here though. You only have one action so it can’t do multiple actions concurrently when there’s only one.