How to run an automation with multiple actions that contains conditions simultaneously

Hi there,
I have an automation where the two final actions both contain some conditions.

So action A basically turns on the light in the morning and then turns it off again once it is not dark anymore.
So the cycle of action A lasts anywhere from 10 minutes to 2 hours depending on the time of year.

My issue is that the next action - action B - does not start until after action A has ended.

So:

  • Can anyone explain to me why action B only runs AFTER the cycle of action A has ended?

Shouldnt these actions just run one by one by and not interfere with each other?

Kind regards
Bo

Screenshot 2024-03-23 21.06.43

Use Run In Parallel. Then, put those two inside there.
ETA screenshot.

Because actions run in order from top to bottom.

1 Like

Or have two automations. :grin:

1 Like

No need for that craziness :grin:

Thx to everyone.
The fact that one action needs to end before the automation moves one was a big eye opener.

In my opinion that behaviour seems a bit strange, but if that is how it is, then thats how it is…

On a side note, when looking at the graphical version of your automation under “traces”, it to me appears that all automations will run one after the other no matter if the previous automation has ended or not…

/Bo

That is not the case. See Run in parallel above.

Actions can be blocking (script or automation waits for completion) or non-blocking (script or automation continues without waiting); it depends on the service or integration being used. And if you call a script, how you call it will determine if it is blocking or non-blocking.

In general it’s best to assume the actions will be blocking but it’s not always the case. As jeffcrum mentioned, use parallel to force non-blocking execution.

However, I would suggest that long delays in an automation are generally bad practice and I would avoid any solution which results in an automation running for an extended period of time.

Instead, add another trigger for whatever you are waiting for. You can do this in a separate automation but I think it is cleaner to keep it all in one, and have your first action be a “choose” action. You can set trigger ID’s in your triggers, then use those trigger ID’s as conditions in your “choose” options so that you know which condition fired the automation.

All running automations will be killed upon HA restart, so this method makes your automations more robust.

1 Like

This is the elephant in the room.
Everything else in this thread doesn’t matter in my opinion.

It’s flawed if you have an automation running for that long.
Automations should be fast and not in a waiting state for many reasons.

1 Like

Yes, i understand that now and am using now “run in parallel” where needed.

In my case i had an automation (running every evening that would measure the temperature in my sons bedroom and send an actionable notification to my mobile phone to turn on the air conditioner in case the room was above 25 degrees.
In case i dismissed the notification without choosing any of the actions available (turn on AC or do nothing), the rest of the automation would never trigger and the following days the automation would not trigger since the initial run had not ended.

Solution was obviously running some of the actions in parallel and changing the mode from “single” to “restart”…

/Bo

Yes, that is correct. Say i wake up at 7 oclock the lights would turn on and then turn off again when the LUX level in the room reach a certain level.

I could of course create a separate automation to turn off the lights, instead of squeezing it all into the same automation.

I agree with you that automations should not have a too long run time, since it probably put some strain on the system.

The question is where the sweet spot is.

I do not have the technical background to answer that myself…

Do you have any input on that? Would be interesting to hear…

So far we have not seen anything that we can help you with.
You have just posted images of the GUI.
Post your automation instead. That is always step 1 when you need help.

Hi there,
i actually received the help i needed immediately after my initial post and i am very grateful for the quick and useful response that i received from the community.

Should you have any input to…

where the “sweet spot between running multiple automations vs a single automation with a longer run time” is…

… then i would appreciate any input…

Kind regards
/Bo

I generally don’t use any form of wait or delay longer than a few seconds, but it’s really personal preference. I don’t resort to multiple automations though; generally a solution can be found by adding triggers to the existing automation.

Having an automation running for hours or days due to a delay isn’t going to hurt HA, but it does make it sensitive to restarts, and I don’t really see any drawback to doing it the “correct” way.

2 Likes

As I said before.
Post the automation instead as yaml and we can help you