Cover garage door does not show the correct status when the smart relay (Shelly) is offline

Hi there,

I have the following template to control my garage door. It works correctly, except when my Shelly 1 Plus PM goes offline. This case always shows me the last status (open or closed). I would like to see a status “unknown”.

I have tried to change the logic between the “value_template” but it stops showing me the statuses correctly.

How can I adjust it?

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 %}