Cover template doesn't consider value_template

I have a configured cover which provides both position_template and value_template. My understanding from the documentation is that the value_template should be used to reflect the state (open, closed) and the position for more fine grained information.
But it seems that the value information is not respected as the cover shows open when the shutter is partially closed. So for example it says: 50% open. But I want to report it as closed unless it is fully open - which I thought can be done via the value_template.

cover:
  - platform: template
    covers:
      living_room_shutter_south:
        device_class: shutter
        friendly_name: "Esszimmer Rolladen Süden"
        unique_id: living_room_shutter_south
        value_template: >-
          {% if is_state('cover.shellyswitch25_3494546b8a2c','opening') %}
            opening
          {% elif is_state('cover.shellyswitch25_3494546b8a2c','closing') %}
            closing
          {% elif states('input_number.esszimmer_rolladen_suden_position') == 100 %}
            open
          {% else %}
            closed
          {% endif %}
        open_cover:
          service: cover.open_cover
          data:
            entity_id: cover.shellyswitch25_3494546b8a2c
        close_cover:
          service: cover.close_cover
          data:
            entity_id: cover.shellyswitch25_3494546b8a2c
        stop_cover:
          service: cover.stop_cover
          data:
            entity_id: cover.shellyswitch25_3494546b8a2c
        position_template: "{{ states('input_number.esszimmer_rolladen_suden_position') }}"

You are comparing a string to an integer, so the open at 50% can’t be coming from whatever is returned by value_template. You can add the int filter so that you are actually comparing similar data types…

{% elif states('input_number.esszimmer_rolladen_suden_position')|int(0) == 100 %}
            open

… but the bigger issue is:


https://www.home-assistant.io/integrations/template/#cover

If you want state/value_template to control the the open and closed values you can’t use position/position_template.

Interesting. I found the reference information from the mqtt integration and there it is actually different. That doesn’t sound very logical to me. But thanks for the hint.

Which example in the reference information?

  • The states() function gets an entity’s state value which is always a string. Even if it appears to be a number (a “numeric string”), it must first be converted to a number (int or float) before attempting to perform any arithmetic operations (like a comparison).

  • The state_attr() function gets the value of an entity’s attribute which can be string, number, list, dictionary, etc. If the value is a number, it doesn’t need conversion to a number in order to perform an arithmetic operation. Most of the examples in the MQTT Cover documentation use state_attr().

Is there an example in the documentation that gets a value using states() and then performs an arithmetic comparison with it (without conversion to a number)? Because that would be a mistake.

Looks like I worked with an outdated version. My interpretation was that the value template is used to define the state and then the position is the more granular information based upon this.
In my automation I don’t care if the cover is 20% or 50% closed, for me it is closed. HA currently sees this as 50% open which is just a different way of intepreting it. So I will update my logic to adjust.