Automation that checks state first

I’m trying to figure out how to create an automation that would check the state of 2 garage doors and if either one is open it will close only the open doors.

The items involved would be 2 open close sensors:
binary_sensor.3rd_stall_door_sensor
binary_sensor.main_garage_door_sensor

Then if there sensor state for either door is in the open position then it would trigger the appropriate switch below.
switch.3rd_stall_garage_opener_relay
switch.main_garage_opener_relay

Anyone that knows how this could be done willing to help me out. I appreciate any tips.

Well an automation needs triggers, and you haven’t said anything about when the automation should do this. So I can’t suggest a complete automation, but I can at least suggest the action part.

Also, what do you mean by “trigger” the appropriate switch? Switches are either turned on, turned off or toggled. Is it one of those? Or do you mean you want it to turn the switch on for a short time and then back off? Please be explicit.

For now I’ll assume you want to turn the switch on for a short time and then back off.

This could be at least a starting point:

- choose:
  - conditions:
    - condition: state
      entity_id: binary_sensor.3rd_stall_door_sensor
      state: 'on'
    sequence:
    - service: switch.turn_on
      entity_id: switch.3rd_stall_garage_opener_relay
    - delay: 1
    - service: switch.turn_off
      entity_id: switch.3rd_stall_garage_opener_relay
- choose:
  - conditions:
    - condition: state
      entity_id: binary_sensor.main_garage_door_sensor
      state: 'on'
    sequence:
    - service: switch.turn_on
      entity_id: switch.main_garage_door_sensor
    - delay: 1
    - service: switch.turn_off
      entity_id: switch.main_garage_door_sensor

So the switches are actually relay modules using esphome. So these would function as toggles which is why I need the automation to check if it’s open or closed first since if I trigger the relay it doesn’t care what position the door is in, it will just act like someone pressed the garage door opener.

I didn’t get into the trigger portion as I can handle the trigger. It will be a WD200 wall switch that supports multi tap functions to trigger automations. I didn’t add that because that’s a whole other process that I didn’t want to confuse anyone with.

Here is the first part of the automation that will trigger the rest. Again the relays should only be activated if the door sensor for that relay is in open state. Any other status and it should not activate relay.

- id: '1597281653144'
  alias: Close garage doors
  description: ''
  trigger:
  - entity_id: zwave.homeseer_technologies_hs_wd200_wall_dimmer
    platform: state
    to: '7860'

Here is what i tried but I’m missing something because i get configuration errors.

- id: '1597281653144'
  alias: Close main garage door
  description: ''
  trigger:
  - entity_id: zwave.homeseer_technologies_hs_wd200_wall_dimmer
    platform: state
    to: '7860'
- choose:
  - conditions:
    - condition: state
      entity_id: binary_sensor.3rd_stall_door_sensor
      state: 'on'
    sequence:
    - service: switch.toggle
      entity_id: switch.3rd_stall_garage_opener_relay
- choose:
  - conditions:
    - condition: state
      entity_id: binary_sensor.main_garage_door_sensor
      state: 'on'
    sequence:
    - service: switch.toggle
      entity_id: switch.main_garage_opener_relay
  mode: single

Also here is the error that generates

Invalid config for [automation]: required key not provided @ data[‘action’]. Got None. (See /config/configuration.yaml, line 9).
Invalid config for [automation]: [choose] is an invalid option for [automation]. Check: automation->choose. (See /config/configuration.yaml, line 9).
Invalid config for [automation]: [choose] is an invalid option for [automation]. Check: automation->choose. (See /config/configuration.yaml, line 9).

Thanks for the help Phil!

Couple of things :

  1. You need to add action to your automation after the trigger block and before the first choose block
  2. Check your indentation. The choose blocks should be at the same level as entity_id in your trigger block

I followed your suggestions and got less errors but I’m still not doing something correctly. Here what I have now.

- id: '1597281653144'
  alias: Close main garage door
  description: ''
  trigger:
  - entity_id: zwave.homeseer_technologies_hs_wd200_wall_dimmer
    platform: state
    to: '7860'
  action:
  - choose:
  - conditions:
    - condition: state
      entity_id: binary_sensor.3rd_stall_door_sensor
      state: 'on'
    sequence:
    - service: switch.toggle
      entity_id: switch.3rd_stall_garage_opener_relay
  - choose:
  - conditions:
    - condition: state
      entity_id: binary_sensor.main_garage_door_sensor
      state: 'on'
    sequence:
    - service: switch.toggle
      entity_id: switch.main_garage_opener_relay
  mode: single

Invalid config for [automation]: [conditions] is an invalid option for [automation]. Check: automation->action->1->conditions. (See /config/configuration.yaml, line 9).

Thanks for your suggestions.
Bryan

you still have indentation errors…
try this:

- id: '1597281653144'
  alias: Close main garage door
  description: ''
  trigger:
  - entity_id: zwave.homeseer_technologies_hs_wd200_wall_dimmer
    platform: state
    to: '7860'
  action:
  - choose:
    - conditions:
      - condition: state
        entity_id: binary_sensor.3rd_stall_door_sensor
        state: 'on'
      sequence:
      - service: switch.toggle
        entity_id: switch.3rd_stall_garage_opener_relay
  - choose:
    - conditions:
      - condition: state
        entity_id: binary_sensor.main_garage_door_sensor
        state: 'on'
      sequence:
      - service: switch.toggle
        entity_id: switch.main_garage_opener_relay