Get attributes from sensor based on index (beginner)

Hello,

I searched a lot but couldn’t find a simple solution to a relatively small problem I have.
Sorry if the topic is well documented, I tried my best.

My trash sensor has a list of attributes with the type of trash and the remaining days before it gets picked up.

All I want to do, is to create a template which gives me access to the second (or third) attribute in the dictionary. basically I want to create a sensor which tells me the following pick up date after the next one.

I managed to get the first (or the last entry) by using this filter method but how do I get the attribute with a specic index?

{{ states.sensor.abfallnaechster.attributes | first }}

Thanks a lot!

1 Like

Copy-paste this into the Template Editor and experiment with it:

{{ state_attr('sensor.abfallnaechster', 'in 11 Tagen') }}

Think he does not know the name. Could be 11 but 12 as well and as far as I understood, he wants the n-th item.

{{ (states.sensor.abfallnaechster.attributes|list)[1] }}

could be perhaps a starting point.

If the goal is to get the value of the sensor’s second attribute (regardless of the attribute’s name), it can be done like this:

{{ (states.sensor.abfallnaechster.attributes.values() | list)[1] }}
2 Likes

This is exactly what I was looking for. Thanks!