Strange cover template behaviour

Here is the problem :
I built a template for a cover according to an open/close sensor


cover:
  - platform: template
    covers:
      portillon:
        device_class: gate
        friendly_name: "Portillon"
        value_template: "{% if states('binary_sensor.openclose_portillon') == 'unavailable' %}unavailable
{% elif states('binary_sensor.openclose_portillon') == 'off' %}closed
{% elif states('binary_sensor.openclose_portillon') == 'on' %}open
{% else %}unknown{% endif %}"
        open_cover:
          service: switch.toggle
          data:
            entity_id: switch.portillon
        close_cover:
          service: switch.toggle
          data:
            entity_id: switch.portillon
        stop_cover:
          service: switch.toggle
          data:
            entity_id: switch.portillon
        icon_template: >-
          {% if is_state("cover.portillon", "open") %}
            mdi:door-open
          {% else %}
            mdi:door
          {% endif %}

It works great for closed and open states but when it comes to unavailable the fake cover never gets unavailable (or any other word for the unavailable state).

I verified my model in dev tools :

So it is supposed to work as it works in dev tools nevertheless…

Can someone explain this ?

Thanks for your help

Regards
V.

Has you “portillon” binary_sensor changed state since you last restarted HA?

The template will be implicitly triggered by a portillon state change. If there are none, the cover won’t change state, and I’m not sure the initial state of the binary_sensor will trigger it.

Oh yes ! I have month of experience about this, after HomeAssistant restarts, after host retsarts… Many many cases, the cover has never came to unavailable.