Garage door configuration in HA

I am currently using GarHAge for controlling two garage doors. Everything is working well from HA and using Google Assistant voice commands.
The only issue is, if the door is open and I ask google to open the door, it sends the command and closes the door. I would like to prevent the door from closing if the open command is issued. Below is the code I currently have setup in the configuration.yaml.
Any help would be greatly appreciated to solve this issue.
Thanks.

 # Garage Doors
cover:
  - platform: mqtt
    name: "Garage Door 1"
    device_class: garage
    state_topic: "garage/door/1/status"
    command_topic: "garage/door/1/action"
    availability_topic: "GarHAge/availability"
    qos: 0
    optimistic: false
    retain: false
    payload_open: "OPEN"
    payload_close: "CLOSE"
    payload_stop: "STATE"
    state_open: "open"
    state_closed: "closed"
    payload_available: "online"
    payload_not_available: "offline"

  - platform: template
    covers:
      garage_door_1:
        value_template: '{{ is_state("cover.garage_door_1", "open") }}'
        open_cover:
          - condition: state
            entity_id: cover.garage_door_1
            state: 'closed'
          - service: cover.open_cover
            entity_id: cover.garage_door_1
        close_cover:
          - condition: state
            entity_id: cover.garage_door_1
            state: 'open'
          - service: cover.close_cover
            entity_id: cover.garage_door_1

  - platform: mqtt
    name: "Garage Door 2"
    device_class: garage
    state_topic: "garage/door/2/status"
    command_topic: "garage/door/2/action"
    availability_topic: "GarHAge/availability"
    qos: 0
    optimistic: false
    retain: false
    payload_open: "OPEN"
    payload_close: "CLOSE"
    payload_stop: "STATE"
    state_open: "open"
    state_closed: "closed"
    payload_available: "online"
    payload_not_available: "offline"

  - platform: template
    covers:
      garage_door_2:
        value_template: '{{ is_state("cover.garage_door_2", "open") }}'
        open_cover:
          - condition: state
            entity_id: cover.garage_door_2
            state: 'closed'
          - service: cover.open_cover
            entity_id: cover.garage_door_2
        close_cover:
          - condition: state
            entity_id: cover.garage_door_2
            state: 'open'
          - service: cover.close_cover
            entity_id: cover.garage_door_2
    
binary_sensor:
  - platform: mqtt
    name: "Garage Door 1"
    state_topic: "garage/door/1/status"
    payload_on: "open"
    payload_off: "closed"
    availability_topic: "GarHAge/availability"
    device_class: opening
    qos: 0

  - platform: mqtt
    name: "Garage Door 2"
    state_topic: "garage/door/2/status"
    payload_on: "open"
    payload_off: "closed"
    availability_topic: "GarHAge/availability"
    device_class: opening
    qos: 0  
    

I think that it’s because you have your MQTT covers exposed to Google (via Nabu Casa I assume?) and so you never go near those templates. I would create some template covers that trigger the doors only under the correct conditions, and hide the MQTT covers from Google / Nabu Casa, while exposing template covers with appropriate names.

This is the part that I am unsure of ,to create separate template cover and properly configure it. I have been looking around and not really finding a solution.

Have a look a template sensors (which you probably have).

Your best bet is to use the first example in that page, and then look at the script page to understand how to test the state of the door and issue actions according to the current state. Your script would only execute the close_cover or open_cover service if appropriate.

1 Like

I have gone through and revised my config and added the script. It still works the same as before and will tell me the state for the door if asked.
When issuing door open or closed commands it still doesn’t taking into account the position of the door determined by location of reed switch. I would like it to prevent the following from happening :
eg. Door open + Door open command = door closing , door closed + door close command = door opening.

I would like google to tell me that the door is already open and not do a thing and vice vera if the door is closed. :no_mouth:

below is my revised config

  # Garage Doors
cover:
  - platform: mqtt
    name: "Garage Door 1"
    state_topic: "garage/door/1/status"
    command_topic: "garage/door/1/action"
    availability_topic: "GarHAge/availability"
    qos: 0
    optimistic: false
    retain: false
    payload_open: "OPEN"
    payload_close: "CLOSE"
    payload_stop: "STATE"
    state_open: "open"
    state_closed: "closed"
    payload_available: "online"
    payload_not_available: "offline"

  - platform: template
    covers:
       garage_door_1:
         value_template: '{{ is_state("binary_sensor.garage_door_1", "closed") }}'
         open_cover:
            service_template: >
             {% if is_state('cover.garage_door_1', 'closed') %}
                script.garage_door_open
              {% else %}
                script.garage_door_do_nothing
              {% endif %}
         close_cover:
            service_template: >
              {% if is_state('cover.garage_door_1', 'open') %}
                script.garage_door_close
              {% else %}
                script.garage_door_do_nothing
              {% endif %}

and the scripts I created

garage_door_open:
  alias: Garage Door Open
  sequence:
  - service: cover.open_cover
    entity_id: cover.garage_door_1
  - condition: state
    entity_id: binary_sensor.garage_door_1
    state: open
  mode: single

garage_door_close:
  alias: Garage Door Close
  sequence:
  - service: cover.close_cover
    entity_id: cover.garage_door_1
  - condition: state
    entity_id: binary_sensor.garage_door_1
    state: closed
  mode: single

garage_door_do_nothing:
  alias: Garage Door Do Nothing
  sequence:
  - condition: state
    entity_id: cover.garage_door_1
    state: 'off'
  mode: single

Binary sensor in config.yaml

binary_sensor:
  - platform: mqtt
    name: "Garage Door 1"
    state_topic: "garage/door/1/status"
    payload_on: "open"
    payload_off: "closed"
    availability_topic: "GarHAge/availability"
    device_class: opening
    qos: 0

You need to rename your MQTT cover to something obscure, also hide it from Google Assistant using “Configuration | Home Assistant | Google Assistant | Manage Entities”. Otherwise when you are trying to close the door or open it with Google it’s just going to use the matching cover i.e. “Hey Google, Close Garage Door 1” will trigger the MQTT cover and not your templates.

Now rename the template covers “Garage Door 1” and “Garage Door 2” and make sure the entities are exposed to Google.

Once you have done that you can start debugging your template and scripts if necessary.

1 Like