I’m trying to set up a REST Sensor where I read the attributes from a JSON page - where there is a parent key name it’s easy - e.g. messages[0].totaldiskspace
but I’m stumped with this feed:-
[
{"busService":"4","destinationName":"City, Cornerhouse T7","departureType":"estimated","time":"2018-05-18T12:50:51+01:00","minutes":"3.70","atcoCode":"3390G1","originName":"City, S Sherwood St G1","commonName":"City, S Sherwood St G1"},
{"busService":"4","destinationName":"City, Cornerhouse T7","departureType":"estimated","time":"2018-05-18T12:54:25+01:00","minutes":"7.27","atcoCode":"3390G1","originName":"City, S Sherwood St G1","commonName":"City, S Sherwood St G1"}
]
The YAML below doesn’t get any attributes, and the “obvious” [0].busService
is syntactically incorrect so you can’t use that (I’ve tried the Bus Service attributes in all three methods listed below, but one at a time)
sensor bus_stop:
- platform: rest
name: Live Bus
scan_interval: 90
json_attributes:
- '{{ value_json[0].busService }}'
- value_json[0].busService
- busService
- destinationName
- departureType
- time
resource: https://example.com/rest.json
value_template: '{{ value_json[0].minutes }}'
unit_of_measurement: "Mins"
How does one access array element [0] when there isn’t a parent Key Name?
(The Value Template is working as expected).