I’ve recently been trying to get more advanced with my configuration and I’ve want to pull data from a public API on the nearby bus stop on the latest buses. I’ve used the REST sensor to grab this information:
- platform: rest
resource: https://reading-opendata.r2p.com/api/v1/siri-sm?location=039026950002&api_token=[MY TOKEN]
method: GET
value_template: "{{ ((as_timestamp(value_json.Siri.ServiceDelivery.StopMonitoringDelivery.MonitoredStopVisit[0].MonitoredVehicleJourney.MonitoredCall.ExpectedArrivalTime) - as_timestamp(now())) / 60) | float }}"
name: "Next 33 Bus"
scan_interval: 60
unit_of_measurement: "minutes"
This works great, but only retrieves the next bus (first array item from MonitoredStopVisit
). However, the API actually returns the next few buses which I would love to parse out as attributes.
Does anyone have an idea how would I iterate over the Siri.ServiceDelivery.StopMonitoringDelivery.MonitoredStopVisit
array
and return all the MonitoredVehicleJourney.MonitoredCall.ExpectedArrivalTime
values as attributes?
As an example, I use an integration to pull similar information for the nearby train station. The sensor state specifies the minutes until the next time, but the attributes have a more complete list:
I just can’t reconcile how I turn the JSON output to an array of attributes…!
Any advice would be gratefully received.
Thanks.