Create reusable template for inverting cover status (100% = closed instead of open)

Good evening,

I am pretty new to Configuration. My challenge is to invert cover status as I would like to have it in line with my KNX integration (means 100% = closed). I managed with the help of the forum to create one working template. But as I have about 15 covers just coping the code is not good practice. I tried to set a variable “entitaet” with the entity of the physical cover, so that I then can create somehow an anchor that is just using the variable entitaet instead of the physical name. However I am not successful till date. BTW, I was not able to invert the status of the cover, it always shows “closed” when it is open now, as the position_template is evaluated to get the status information…

Does anyone have an idea where I miss the necessary link. This is my current code that works for one cover.

cover:
# Fernsehzimmer
  - platform: template
    covers:
      rollladen_fernsehzimmer_r: 
        friendly_name: "Rollladen Fernsehzimmer reversed"
        device_class: shutter
        position_template: |
          {% set entitaet='cover.rollladen_fernsehzimmer' %}
          {{100-state_attr(entitaet, 'current_position') | int(100) }}
        value_template:  >
          {% set entitaet='cover.rollladen_fernsehzimmer' %}
          {% if is_state(entitaet, 'open') %}
            closed
          {% elif is_state(entitaet, 'closed') %}
            open
          {% elif is_state(entitaet, 'opening') %}
            opening
          {% elif is_state(entitaet, 'closing') %}
            closing
          {% else %}
            undefined
          {% endif %}
        open_cover:
          service: cover.close_cover
          data: {}
          target:
            entity_id: >
              {% set entitaet='cover.rollladen_fernsehzimmer' %}
              {{entitaet}}
        close_cover:
          service: cover.open_cover
          data: {}
          target:
            entity_id: >
              {% set entitaet='cover.rollladen_fernsehzimmer' %}
              {{entitaet}}
        stop_cover:
          service: cover.stop_cover
          data: {}
          target:
            entity_id: >
              {% set entitaet='cover.rollladen_fernsehzimmer' %}
              {{entitaet}}
        set_cover_position: 
          service: cover.set_cover_position
          data:
            position: "{{100-position}}"
          target:
            entity_id: >
              {% set entitaet='cover.rollladen_fernsehzimmer' %}
              {{entitaet}}
        icon_template: >
          {% if is_state(this.entity_id, 'opening') %}
            mdi:arrow-up-bold
          {% elif is_state(this.entity_id, 'closing') %}
            mdi:arrow-down-bold
          {% elif state_attr(this.entity_id, 'current_position')  > 90 %}
            mdi:window-shutter
          {% elif state_attr(this.entity_id, 'current_position') <= 90 %}
            mdi:window-shutter-open
          {% else %}
            mdi:alert-circle
          {% endif %}

KNX has attributes that allow you to invert everything

I’d just go that route

No, that doesn’t really work. Integrations that send absolute positions for open/close (eg. HomeKit) would always work inverted then.

When using position_invert: true:
Open from HK → cover.set_cover_position(100) → 100 is sent to Knx (since it is inverted by default to match HA standard) which is close.

1 Like

Thanks a lot … I do not understand why I have not seen those attributes when I was checking the configuration… thanks agsin

Maybe have a look here, iirc there is a workaround somewhere in there. WHY THE HECK can't we freely configure a Cover to interpret its percentage value as "percentage open" or "percentage closed"?

Need to try tomorrow, sound like an everyday problem with no simple fix…:slight_smile:

Btw, does anyone have an idea to avoid duplicating my code that at least works for positioning as per my initial question (but not status)?

Thanks again

There isn’t an easy way to duplicate the code. In reality, we just need a new integration that inverts entities.

Hi,

thank yout, this is also what I did, I need a solution mainly for voice and percentages.

cheeers