@MvB wrote:
Hi,
I’m stuck on creating a for loop that retrieves multiple names from the attributes of a sensor.
If I do the following:
{% for faces in state_attr('image_processing.microsoftface_ip_webcam','faces') %} {%- if loop.first %} {% elif loop.last %} and {% else %}, {% endif -%} {{ states.image_processing.microsoftface_ip_webcam.attributes.faces }} {% endfor %}
I get:
[{'name': 'Carmen', 'confidence': 58.236}, {'name': 'Michiel', 'confidence': 54.443}] and [{'name': 'Carmen', 'confidence': 58.236}, {'name': 'Michiel', 'confidence': 54.443}]
Which makes sense. But since I want the name I add the
.name
to the end:{% for faces in state_attr('image_processing.microsoftface_ip_webcam','faces') %} {%- if loop.first %} {% elif loop.last %} and {% else %}, {% endif -%} {{ states.image_processing.microsoftface_ip_webcam.attributes.faces.name }} {% endfor %}
But then no names are returned:
and
My goal is to have both the names displayed. e.g.
Carmen and Michiel
Could someone help me figure out what I’m am doing wrong?
ps I can access the seperate name values
{{states.image_processing.microsoftface_ip_webcam.attributes.faces[0].name }}
, but since the list doesn’t always have the same amount of values, I would like to create it dynamically.
Posts: 1
Participants: 1