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 %}