How to automate closing of garage doors

I’m trying to automate the closing of my 2 garage doors by pressing the 3rd button on the door remote. I’ve tried multiple iterations of the below, but cannot find the right combination. Can anyone help?

- alias: 3rd button pushed, lock door and shut Doors
  trigger:
    - platform: state
      entity_id: binary_sensor.garage_door_receiver
      to: 'on'
  action:
    - service: lock.lock
      data:
        entity_id: lock.vision_yale_push_button_deadbolt_yrd210_locked
    - service_template: >
        {% if is_state('binary_sensor.garage_door_inner', 'on') %}
          service: cover.close_cover
        {% endif %}
      entity_id: cover.garage_door_inner        
    - service_template: >
        {% if is_state('binary_sensor.garage_door_outer', 'on') %}
          service: cover.close_cover
        {% endif %}
      entity_id: cover.garage_door_outer

There are a couple of problems with your actions. First, you can’t have a service_template that might result in nothing. It always has to result in some service. Second, you don’t put service: inside service_template. You use either service_template or service, but not both.

Generally how this situation is handled (when you have two services you want to conditionally call), is not to change the service, but to change the entity_id – either to the real entity, or to a “dummy” entity.

So, like this:

- alias: 3rd button pushed, lock door and shut Doors
  trigger:
    - platform: state
      entity_id: binary_sensor.garage_door_receiver
      to: 'on'
  action:
    - service: lock.lock
      entity_id: lock.vision_yale_push_button_deadbolt_yrd210_locked
    - service: cover.close_cover
      data_template:
        entity_id: >
          {% if is_state('binary_sensor.garage_door_inner', 'on') %}
            cover.garage_door_inner        
          {% else %}
            cover.dummy
          {% endif %}
    - service: cover.close_cover
      data_template:
        entity_id: >
          {% if is_state('binary_sensor.garage_door_outer', 'on') %}
            cover.garage_door_outer
          {% else %}
            cover.dummy
          {% endif %}

Basically any entity_id that doesn’t exist is ignored. In fact, since the entity_id parameter can take a comma separated list, then this can be reduced to:

- alias: 3rd button pushed, lock door and shut Doors
  trigger:
    - platform: state
      entity_id: binary_sensor.garage_door_receiver
      to: 'on'
  action:
    - service: lock.lock
      entity_id: lock.vision_yale_push_button_deadbolt_yrd210_locked
    - service: cover.close_cover
      data_template:
        entity_id: >
          cover.dummy
          {% if is_state('binary_sensor.garage_door_inner', 'on') %}
            , cover.garage_door_inner        
          {% endif %}
          {% if is_state('binary_sensor.garage_door_outer', 'on') %}
            , cover.garage_door_outer
          {% endif %}

I don’t use covers myself, but this type of thing generally works.

1 Like

Thank you… that did the trick. I didn’t realize you can’t have a null result.

1 Like