Can a condition be applied independently to each action, when there are several actions?

I have an automation that is triggered by time (it starts at 9:00). It then calls three actions (three roller shutters are set at 40%). It works fine.

I would like to check, for each roller, that its position is <40% this is to avoid the case someone opens the shutter, and then has it coming down to 40%). Such a condition, however, would need to be tested for each action separately (and not in the conditions block AFAIK).

Is this something that is possible to do in the native automation?

I have fallback solutions (either three separate automations, which I would like to avoid, or calling a service defined in pyscript that would make the decisions - this is OK, though if it doable directly in the native YAML it would be a new experience)

1 Like

All you need to do is read the docs;

Conditions can also be part of an action.

Wish everything was so easy :joy:

1 Like

When reading again the docs, I think that the solution does not apply to me:

Conditions can also be part of an action. You can combine multiple service calls and conditions in a single action, and they will be processed in the order you put them in. If the result of a condition is false, the action will stop there so any service calls after that condition will not be executed.

This means that I need to read the action linearly ind if a condition is not met, then the whole actions section stops.

What I needed is conditions for a specific action, independent of the others. In other words, the conditions should be nested in the action.

To take my example, shutter A is at 20, shutter B is at 100, shutter C is at 20, then the condition (set at 40 if current position is < 40 should apply independently to each action (and shutter A and C would move to 40, and shutter B would stay at 100)

1 Like

:thinking: you’re right. It seems a bit more complicated as I thought. Sorry about that.

Could it be done using choose-actions:

I use this already elsewhere but

The choose action can be used like an “if” statement.

This is rather to choose from several actions depending on a condition. I want all my actions to proceed, but only when a conditions applicable to each of them is met.

But you could (?) write 3 consecutive choose -actions. That way they could act like conditions, but if one condition is not met it wouldn’t cancel the whole automation.

“choose” actions are cumbersome to write, so I’m not even going to try. But, essentially, “condition” actions HALT progress. “choose” works like a condition, but proceeds afterwards regardless.

So, each choose would look at the cover state and then call the service only if needed.

“choose” is a recent addition to Home Assistant. Before that, the solution was to write 3 home assistant scripts, each with a condition action in them, and then call all three scripts from your automation. This is still an option and, in my opinion, much easier to read than “choose” actions.

1 Like