Syntax to extract values from repeated attributes from Sensor

Apologies for this post, but I am very new in terms of trying to code in HA.

I have added the UK National Rail integration where a sensor had been successfully set up. In Developer Tools I can see its attributes and values. I would like to retrieve some values from there where I can add them to a dashboard via more custom sensors. Existing dashboards that I had seen are a bit bulky and I just need very simple info.

I have tried using {{state_attr(‘sensor.train_schedule_lem_bho’,‘trains’)[1].lines}} to retrieve by lines but it doesn’t seem to work from post here. Also since there are “repetitive” attributes I like to retrieve (e.g “Scheduled”), how do we identify them? is it by occurrence?

Thank you!

Copy-paste the following into the Template Editor and let me know if reports the first train’s scheduled arrival time (or an error).

{% set t = state_attr('sensor.train_schedule_lem_bho', 'dests').BHO.Arrival.trains %}

{{ t[0].scheduled }}
1 Like

OMG this is amazing! Thank you so much. I will try to re use your code and explore more. Thanks again! :pray:t2: :pray:t2: :pray:t2:

1 Like