Is there a more efficient way to generate with templates some display text for a markdown card?

I need an overview of all my covers that are opened/closed/partially opened in a way that is splitted in 3 sides of my house and in every part the covers need to be in some order. So this are all my covers splitted in the 3 sides and in the order I want to see them:

image

I’m succeeded to show it in a markdown card (covers that are opened):

image

But it is a lot of the “same” code. So this is it for the covers that are opened:

- **Voorkant**
{%- set voorkant = namespace(entities=[]) -%} 
{%- if state_attr('cover.master_bedroom', 'current_position' ) == 100 -%}
  {% set voorkant.entities = voorkant.entities + ['\t- ' + state_attr('cover.master_bedroom', 'friendly_name')] %}
{%- endif -%}
{%- if state_attr('cover.voorraam_klein', 'current_position' ) == 100 -%}
  {% set voorkant.entities = voorkant.entities + ['\t- ' + state_attr('cover.voorraam_klein', 'friendly_name')] %}
{%- endif -%}
{%- if state_attr('cover.voorraam_groot', 'current_position' ) == 100 -%}
  {% set voorkant.entities = voorkant.entities + ['\t- ' + state_attr('cover.voorraam_groot', 'friendly_name')] %}
{%- endif -%}
{{"\n" + voorkant.entities | join("\n") }}


- **Zijkant**
{%- set zijkant = namespace(entities=[]) -%} 
{%- if state_attr('cover.computer_kamer', 'current_position' ) == 100 -%}
  {% set zijkant.entities = zijkant.entities + ['\t- ' + state_attr('cover.computer_kamer', 'friendly_name')] %}
{%- endif -%}
{%- if state_attr('cover.hal_1e_etage', 'current_position' ) == 100 -%}
  {% set zijkant.entities = zijkant.entities + ['\t- ' + state_attr('cover.hal_1e_etage', 'friendly_name')] %}
{%- endif -%}
{%- if state_attr('cover.zijraam', 'current_position' ) == 100 -%}
  {% set zijkant.entities = zijkant.entities + ['\t- ' + state_attr('cover.zijraam', 'friendly_name')] %}
{%- endif -%}
{{"\n" + zijkant.entities | join("\n") }}


- **Achterkant**
{%- set achterkant = namespace(entities=[]) -%} 
{%- if state_attr('cover.badkamer', 'current_position' ) == 100 -%}
  {% set achterkant.entities = achterkant.entities + ['\t- ' + state_attr('cover.badkamer', 'friendly_name')] %}
{%- endif -%}
{%- if state_attr('cover.logeerkamer', 'current_position' ) == 100 -%}
  {% set achterkant.entities = achterkant.entities + ['\t- ' + state_attr('cover.logeerkamer', 'friendly_name')] %}
{%- endif -%}
{%- if state_attr('cover.achterdeur', 'current_position' ) == 100 -%}
  {% set achterkant.entities = achterkant.entities + ['\t- ' + state_attr('cover.achterdeur', 'friendly_name')] %}
{%- endif -%}
{%- if state_attr('cover.achterraam', 'current_position' ) == 100 -%}
  {% set achterkant.entities = achterkant.entities + ['\t- ' + state_attr('cover.achterraam', 'friendly_name')] %}
{%- endif -%}
{{"\n" + achterkant.entities | join("\n") }}




I have to repeat this for the other views: “closed covers” and “partially opened” covers.

Could this be done more efficient in jinja by filling some ordered list?

You could make a Jinja macro — it’s like a function you can reuse.