New cover for garage door is not showing proper position

Transitioning away from MyQ to just zwave. Before making this template I had everything optional using a zwave tilt sensor (binary, on/off) and a zwave relay to momentarily press the remote button. All of that works fine, but wanted the more intuitive interface of using the cover template in the app.

Here is the code I added to my configuration.yaml:

cover:
  - platform: template
    covers:
      garage_door:                                                                                                                                         
        device_class: garage                                                                                                                               
        friendly_name: "Garage Door"                                                                                                                       
        position_template: "{{ states('binary_sensor.door_sensor_sensor_state_any') }}"                                                                    
        open_cover:
          - condition: state
            entity_id: binary_sensor.door_sensor_sensor_state_any
            state: "off"
          - service: switch.turn_on
            target:
              entity_id: switch.relay_01_1
        close_cover:
          - condition: state
            entity_id: binary_sensor.door_sensor_sensor_state_any
            state: "on"
          - service: switch.turn_off
            target:
              entity_id: switch.relay_01_1
        stop_cover:
          service: switch.turn_on
          target:
            entity_id: switch.relay_01_1
        icon_template: >-
          {% if states('binary_sensor.door_sensor_sensor_state_any')|float > 0 %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}

After restart I have the cover section in interface, but it enables both open and close buttons and does not show current state.

What am I doing wrong here?

position_template is a number value from 0-100, but you’re giving it a true/false value. How do you expect to give a position value with a binary sensor anyways? You can provide open or closed state via value_template instead. That’s how I do it at least.

- platform: template
  covers:
    left_garage_door:
      unique_id: zen17_garage_door_opener
      device_class: garage
      friendly_name: Left Garage Door Opener
      value_template: |
        {{ is_state("binary_sensor.left_garage_door_is_open", "on") }}
      availability_template: |
        {{ states("binary_sensor.left_garage_door_is_open") not in ("unknown", "unavailable") }}
      open_cover:
        - condition: state
          entity_id: binary_sensor.left_garage_door_is_open
          state: "off"
        - service: switch.turn_on
          target:
            entity_id: switch.left_garage_door_opener_relay_1
      close_cover:
        - condition: state
          entity_id: binary_sensor.left_garage_door_is_open
          state: "on"
        - service: switch.turn_on
          target:
            entity_id: switch.left_garage_door_opener_relay_1

Device class also gives you the icons for free.

1 Like

Thank you for this! That fixed the problem. I made an assumption that HA would sort that out with some logic and their page even implies that a little, but that was my error. Here’s my final code that is working now:

cover:
  - platform: template
    covers:
      garage_door:
        unique_id: zen16_relay01_garage_door_opener
        device_class: garage
        friendly_name: "Garage Door"
        #position_template: "{{ states('binary_sensor.door_sensor_sensor_state_any') }}"
        value_template: |
          {{ is_state("binary_sensor.door_sensor_sensor_state_any", "on") }}
        availability_template: |
          {{ states("binary_sensor.door_sensor_sensor_state_any") not in ("unknown", "unavailable") }}
        open_cover:
          - condition: state
            entity_id: binary_sensor.door_sensor_sensor_state_any
            state: "off"
          - service: switch.turn_on
            target:
              entity_id: switch.relay_01_1
        close_cover:
          - condition: state
            entity_id: binary_sensor.door_sensor_sensor_state_any
            state: "on"
          - service: switch.turn_on
            target:
              entity_id: switch.relay_01_1
        stop_cover:
          service: switch.turn_on
          target:
            entity_id: switch.relay_01_1
        icon_template: >-
          {% if states('binary_sensor.door_sensor_sensor_state_any')|float > 0 %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}
1 Like

Does this go in your config.yaml file?

Also, which card did you put on your dashboard ? I’m a bit confused there as the tilt sensor would determine status of up or down, but I’d want to be able to click the door icon to trigger the call service for the relay to open/close the door.

Appreciate the help