How can I get attributes of a sensor in a loop template?

Hi,

I try to get the freindly_name of a sensor out of a group:

{% for item in states.group.fenster_und_tueren.attributes.entity_id if states(item) == 'open' %}
{{ item }} ist offen!
{{ states.sensor.badezimmer_fenster_state.attributes.friendly_name }} ist offen!
{{ states.item.attributes.friendly_name }} ist offen!
{% endfor %}

the ouput is

sensor.badezimmer_fenster_state ist offen!
Badezimmer Fenster STATE ist offen!
 ist offen!

Is it possible to get the attributes of the “item” here?

Thanks!

You need to split your for and if statements.
You’re also missing a closure for your if statement…

{%- for item in states.group.fenster_und_tueren.attributes.entity_id -%}
{%- if states(item) == "open" -%}
{{ item }} = {{ states(item) }}
{% endif %}
{%- endfor -%}

thanks, but with that I still dont get the friendly_name of the entity which is open :frowning:

and sorry: I am new to programming templates :wink:

I’m not sure you can achieve this, but provided you named your entities in a consistent manner, you could always do this:

{%- for item in states.group.fenster_und_tueren.attributes.entity_id -%}
{%- if states(item) == "open" -%}
{{ (item) | replace ("binary_sensor.","") | replace ("_"," ") | capitalize() }} = {{ states(item) }}
{% endif %}
{%- endfor -%}