Good morning, could you help me please I want to get an attribute and normally I know, but with this I do not get it. I want for example to get the attribute “friendly_name” that is inside “packages”. With the following code I get everything from inside packages, but how can I get something specific from inside? Thanks in advance.
What does the state_attr
template in your first screenshot actually give? At a guess, you want something like:
state_attr('sensor.seventeentrack_packages_in_transit', 'packages')[0]['friendly_name']
to get the first friendly_name
in the list — there are two in your second screenshot.
1 Like
Thank you for helping me @Troon, I attach the result of the first code I sent. Your code works correctly, but it is possible that it shows me all the “friendly_name” available inside “packages” (the ones I show in the image).
You mean you want to see Enchufes, Funda Impresora 3D, Imou
?
If so, try this:
{% for package in state_attr('sensor.seventeentrack_packages_in_transit', 'packages') -%}
{{ package.friendly_name }}
{%- if loop.first %}, {% elif loop.last %} {% else %} and {% endif -%}
{%- endfor %}
This is just what I needed. Thank you very much!
Shorter version of the same thing (without the “and”!):
{{ state_attr('sensor.seventeentrack_packages_in_transit', 'packages')|map(attribute='friendly_name')|join(', ') }}
1 Like