Cover Template Garage Door

Hi,

I have a Z-wave Tilt Sensor for my garage door to report the state, and a relay with esphome to activate the door.
It’s ok to activate the door with the template cover but I’m not able to read the status with my configuration. The Door is always close…
What I’m missing in my code ?

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

Position template has to return a number between 0 and 100:

Screenshot 2021-08-18 at 10-43-53 Template Cover

As you only have a binary sensor (your tilt sensor states are on or off) use a value template instead (delete the position_template):

Screenshot 2021-08-18 at 10-45-19 Template Cover

value_template: "{{ is_state('binary_sensor.ecolink_tilt_sensor_sensor', 'on') }}"

This assumes your tilt sensor is on when the door is open. Change the state in the template to 'off' if it is the other way around.

1 Like

It’s works ! Thank you.

So I can say close the garage door to Siri, and not Open the garage Door to close him.

cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Porte du garage"
        value_template: "{{ is_state('binary_sensor.ecolink_tilt_sensor_sensor', 'on') }}"
        open_cover:
          - condition: state
            entity_id: binary_sensor.ecolink_tilt_sensor_sensor
            state: "off"
          - service: switch.toggle
            target:
              entity_id: switch.switch_porte_g
        close_cover:
          - condition: state
            entity_id: binary_sensor.ecolink_tilt_sensor_sensor
            state: "on"
          - service: switch.toggle
            target:
              entity_id: switch.switch_porte_g
        stop_cover:
          service: switch.toggle
          target:
            entity_id: switch.switch_porte_g
        icon_template: >-
          {% if states('binary_sensor.ecolink_tilt_sensor_sensor', 'off') %}
            mdi:garage
          {% else %}
            mdi:garage-open
          {% endif %}