I need to map some Attributes from a Json-File to Attributes of one Restful-Sensor.
I’ve tried a lot of combination (try an error) but now I have to ask some experts:-)
Example-Data:
platform: rest
resource: https://fahrplan.search.ch/api/route.json?from=Einsiedeln&to=Z%C3%BCrich,+F%C3%B6rrlibuckstr.+60
name: blablababla
json_attributes:
- ?????? if I want connections.0.departure from Json
- ?????? if I want connections.0.arrival from Json
- ?????? if I want connections.0.legs.0.line from Json
value_template: '{{ value_json.??????????? }}'
I need a sensor with anything as state and some attributes from the json-File.
value_template: ‘{{ value_json.blablababla.??? }}’
where the ??? are the attribute you want to map to the sensor… I am not familiar with the json_attributes key and I would just create multiple sensors for multiple attributes.
Are you sure this will work? Looking at the code (sensor/rest.py), I don’t think you can use anything but a “top level” JSON key for json_attributes. E.g., I think you can only use something like connections in this case. Then you’d have to use template sensors the get the individual pieces.
Of course I can create a sensor for each attribute I need, but then I will pull the hole Json-File with each call. That’s not necessary, because I get the hole file with the first call and the infos I need are all there…
I didn’t think that would work (although I was hoping! ) But what should work is to use the rest sensor to get the JSON results and put the connections key into an attribute. Then with template sensors you can extract the pieces you need, albeit into individual sensors.
Take a look at this reply to another person trying to do a similar thing and let me know if you think that would work for you, and if you need any help: