Set cover to unavailable

Hi.

I have a garage door cover template with two Aqara door sensors to determine if the garage door is open, closed, or in between.
The problem I have presents itself if/when one or both Aqara sensors are unavailable/unknown. The cover always defaults to “open” but I would like to set it to “unavailable” until the door sensors are back online. If it displays as “open”, there’s a chance that I or someone else will try to close it but instead will open it since the door motor is really just a toggle. If it’s closed, it will open and vice versa.

I have played around with it in dev tools and there it works as it should but the same template in the cover does not.

Below is the template and the result after reboot but before z2m is started so the two door sensors are unknown.

      {% if states('binary_sensor.door_garage_closed_contact') in ("unavailable", "unknown") %}
        unavailable
      {% elif is_state("binary_sensor.door_garage_closed_contact","off") -%}
        closed
      {%- elif is_state("binary_sensor.door_garage_closed_contact","on") and is_state("binary_sensor.door_garage_open_contact","on") -%}
        opening
      {% elif  is_state("binary_sensor.door_garage_open_contact","off")  -%}
        open
      {%- else -%}
        unknown
      {% endif %}

Garage door: {{states('cover.garage_door')}}
Garage door 2: {{states('cover.garage_door_2')}}
Open contact: {{states('binary_sensor.door_garage_open_contact')}}
Closed contact: {{states('binary_sensor.door_garage_closed_contact')}}

And the result:

image

As you can see, the door sensors are unknown, the template reports unavailable but the garage door is reported as open.

I can set the cover entity to unavailble in the States dev tool and get the desired result but is it impossible to do that in a template?

How can I get my cover to report “unavailable” when the sensors are offline?

Attribute availability_template

1 Like

Do you know how many times I’ve read that document? Blind as a bat apparently. Many thanks @w35l3y !

1 Like