Action(s) by condition in automations

Hello all,

Could you tell me if this is possible to do action based on specific actions? I mean, do an action based on specific conditions and not all conditions without need t create a new automation scenario?

Example with my current scenario:

- id: '1572631476783'
  alias: Fermeture volets automatique
  description: Fermer les volets durant la nuit
  trigger:
  - below: '100'
    entity_id: sensor.illumination_xxxxxxxxxx
    for: '1200'
    platform: numeric_state
  condition:
  - after: '16:00:00'
    condition: time
  - condition: and
    conditions:
    - condition: or
      conditions:
      - condition: state
        entity_id: cover.volets_rdc
        state: open
      - condition: state
        entity_id: cover.volets_etage
        state: open
  action:
  - data:
      entity_id:
      - cover.volets_rdc
      - cover.volets_etage
    service: cover.close_cover

My goal is to close volets_rdc only if this group is open and close volets_etage only this one is open (without close the other group if this one is already closed)

I see that we can use condition in action but according to the documentation, if one condition is not true, all followed actions are stopped so we cannot use parallel conditions :frowning:

Thank you very much for your answers

Yeah, you have to repeat the conditions in the service template of the action section

1 Like

First, this:

 condition:
  - after: '16:00:00'
    condition: time
  - condition: and
    conditions:
    - condition: or
      conditions:
      - condition: state
        entity_id: cover.volets_rdc
        state: open
      - condition: state
        entity_id: cover.volets_etage
        state: open

can be simplified to this:

 condition:
  - after: '16:00:00'
    condition: time
  - condition: or
    conditions:
    - condition: state
      entity_id: cover.volets_rdc
      state: open
    - condition: state
      entity_id: cover.volets_etage
      state: open

Next, is it really a problem to close a cover that is not open? I don’t use cover entities, so I’m not sure. What happens (that you don’t want to happen) if you just have the automaton close both covers regardless of their current state? E.g.:

- id: '1572631476783'
  alias: Fermeture volets automatique
  description: Fermer les volets durant la nuit
  trigger:
  - below: '100'
    entity_id: sensor.illumination_xxxxxxxxxx
    for: '1200'
    platform: numeric_state
  condition:
  - after: '16:00:00'
    condition: time
  action:
  - data:
      entity_id:
      - cover.volets_rdc
      - cover.volets_etage
    service: cover.close_cover

If you really need to only close the cover or covers that are currently open, then probably the easiest way to do that is to have one automation per cover:

- alias: Fermeture volets automatique rdc
  description: Fermer les volets durant la nuit
  trigger:
  - below: '100'
    entity_id: sensor.illumination_xxxxxxxxxx
    for: '1200'
    platform: numeric_state
  condition:
  - after: '16:00:00'
    condition: time
  - condition: state
    entity_id: cover.volets_rdc
    state: open
  action:
  - data:
      entity_id:
      - cover.volets_rdc
    service: cover.close_cover

and

- alias: Fermeture volets automatique etage
  description: Fermer les volets durant la nuit
  trigger:
  - below: '100'
    entity_id: sensor.illumination_xxxxxxxxxx
    for: '1200'
    platform: numeric_state
  condition:
  - after: '16:00:00'
    condition: time
  - condition: state
    entity_id: cover.volets_etage
    state: open
  action:
  - data:
      entity_id:
      - cover.volets_etage
    service: cover.close_cover

Hi,

@pnbruckner: I want to avoid to enable switch when the cover is already close (or open)…

@Mutt do you have an example to do this? The documentation is not clear… I want to avoid to use one automation by cover (if I do it, I need more 16 automations only to manage cover)

What switch? I guess maybe you’ve only describe a piece of what you’re ultimately trying to do. It’s a little hard to make useful suggestions when you only explain part of the scenario.

In any case, ignoring your ultimate goal, if you want to have a conditional step in the action part of an automation (or in a script, which is basically the same thing), you can’t. HA’s script implementation does not have such a feature. However, you could put each conditional step into its own script, and then call them all from the automation.

automation:
  - ...
    action:
      - service: script.script1
      - service: script.script2
      - service: script.script3
script:
  script1:
    sequence:
      - condition: ...
      - service: ...
  script2:
    sequence:
      - condition: ...
      - service: ...
  script3:
    sequence:
      - condition: ...
      - service: ...
1 Like

@pnbruckner the switch of the cover.

Another example:

  • We have 2 switch: one for bedroom, one for kitchen (opened for both)
  • I close manually a cover
  • New status: cover bedroom is open, cover kitchen is closed
  • The automation detect now a low luminosity & close these 2 covers: currently the 2 switchs are enabled (I want only close the cover currently open and no action on the cover closed). (unless create 6 automations (1 for manually (via aquara switch), 1 for close auto (luminosity), 1 for open manually (via aquara switch) for only 2 switchs). It’s pitty that we cannot simply add a condition in the action sequence.

Thanks for the script idea, seems good. I will check.