Detect 'unavailable' status in binary sensor of garage door

Hola!

I have the following template cover to control my garage door (Shelly relay + magnetic sensor). In the area I don’t have good Wi-Fi coverage and occasionally the Shelly loses connection. I would like to be able to reflect that status in the cover.

Right now if the relay loses the Wi-FI connection the door status is indicated as closed. I would like to receive a status not available. How can I do this?

cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage Door"
        unique_id: "garagedoor"
        value_template: "{{ is_state('binary_sensor.sensor_puerta_garaje_input', 'on') }}"
        open_cover:
          - condition: state
            entity_id: binary_sensor.sensor_puerta_garaje_input
            state: "off"
          - service: switch.turn_on
            target:
              entity_id: switch.puerta_garaje
        close_cover:
          - condition: state
            entity_id: binary_sensor.sensor_puerta_garaje_input
            state: "on"
          - service: switch.turn_on
            target:
              entity_id: switch.puerta_garaje
        stop_cover:
          service: switch.turn_on
          target:
            entity_id: switch.puerta_garaje
        icon_template: >-
          {% if is_state('binary_sensor.sensor_puerta_garaje_input', 'on') %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}

Add an availability template

1 Like

Thank you! Works. I put the updated code in case it is useful to someone.

cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage Door"
        unique_id: "garagedoor"
        availability_template: >-
          {%- if not is_state("binary_sensor.sensor_puerta_garaje_input", "unavailable") %}
            true
          {%- endif %}
        value_template: "{{ is_state('binary_sensor.sensor_puerta_garaje_input', 'on') }}"
        open_cover:
          - condition: state
            entity_id: binary_sensor.sensor_puerta_garaje_input
            state: "off"
          - service: switch.turn_on
            target:
              entity_id: switch.puerta_garaje
        close_cover:
          - condition: state
            entity_id: binary_sensor.sensor_puerta_garaje_input
            state: "on"
          - service: switch.turn_on
            target:
              entity_id: switch.puerta_garaje
        stop_cover:
          service: switch.turn_on
          target:
            entity_id: switch.puerta_garaje
        icon_template: >-
          {% if is_state('binary_sensor.sensor_puerta_garaje_input', 'on') %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}

You can simplify that to

availability_template: "{{ 'binary_sensor.sensor_puerta_garaje_input' | has_value 
 }}"
1 Like