Set state of curtain open/close based on percentage? SOLVED

Is there a way to set the state of a curtain entity based on percentage parameters? I have some MotionBlind curtains that I can not seem to set the open/closed positions on the device and they never close more than 99%.
I use an inverse template to convert this to 1% open however I would like Home assistant to see this as Closed if the value is less than say 5% so that conditional cards and buttons will display a little more accurately (or less accurately depending on how you look at it). Right now they display as open pretty much all the time.

HASS OS Bare Metal V 2024.12.5

My inverse template:

cover:
  - platform: template
    covers:
      rollerblind_inverted:
        friendly_name: Curtain Inverse
        device_class: curtain
        position_template: "{{ 100 - state_attr('cover.rollerblind', 'current_position') | int(default=0) }}"
        set_cover_position:
          service: cover.set_cover_position
          data:
            position: "{{ 100 - position }}"
            entity_id: cover.rollerblind
        open_cover:
          service: cover.open_cover
          data: {}
          target:
            entity_id: cover.rollerblind
        close_cover:
          service: cover.close_cover
          data: {}
          target:
            entity_id: cover.rollerblind
        stop_cover:
          service: cover.stop_cover
          data: {}
          target:
            entity_id: cover.rollerblind

My YAML and Home Assistant skills in general are poor so please forgive me. The above code was copied and adapted from posts on this forum.
Thanks in advance for any help!

I can’t test this but does this work ?

Maybe try this in dev tools > template first:

{% set real_position = 100 - state_attr('cover.rollerblind', 'current_position') | int(0) %}
{% if real_postion < 5 %}
  0
{% else %}
  {{ real_postion }}
{% endif %}
cover:
  - platform: template
    covers:
      rollerblind_inverted:
        friendly_name: Curtain Inverse
        device_class: curtain
        position_template: >-
          {% set real_position = 100 - state_attr('cover.rollerblind', 'current_position') | int(0) %}
          {% if real_position < 5 %}
            0
          {% else %}
             {{ real_position }}
          {% endif %}
        set_cover_position:
          service: cover.set_cover_position
          data:
            position: "{{ 100 - position }}"
            entity_id: cover.rollerblind
        open_cover:
          service: cover.open_cover
          data: {}
          target:
            entity_id: cover.rollerblind
        close_cover:
          service: cover.close_cover
          data: {}
          target:
            entity_id: cover.rollerblind
        stop_cover:
          service: cover.stop_cover
          data: {}
          target:
            entity_id: cover.rollerblind

That got it!
Awesome, thanks so much I have been struggling with this for awhile

Excellent, can you mark the post Solved ?