EDIT: I have solved this (but see @pnbruckner’s better solution).
{%- for train in states.sensor if train.entity_id.endswith('next_train_to_abc') -%}
{%- for attr in train.attributes %}
then access each one using loop.index
e.g.
states.sensor.next_train_to_wea.attributes.next_trains[loop.index].scheduled
I have several places where I loop through states in entities and act on them as appropriate but is it possible to loop through attributes?
I have a sensor which presents as follows:
states.sensor.next_train_to_abc.attributes.next_trains[0].scheduled
states.sensor.next_train_to_wea.attributes.next_trains[0].estimated
...
states.sensor.next_train_to_wea.attributes.next_trains[0].platform
states.sensor.next_train_to_wea.attributes.next_trains[1].scheduled
states.sensor.next_train_to_wea.attributes.next_trains[1].estimated
...
states.sensor.next_train_to_wea.attributes.next_trains[1].platform
and so on.
I would like to loop through next_trains
.
Is this possible? I couldn’t find a syntax that worked.