I need some help with “json_attributes_path:” and “json_attributes:”.
I have a Rest sensor where I want all of the wind_speed_of_gust values from this API link as attributes. There are around 57 of the wind_speed_of_gust in the API.
https://api.met.no/weatherapi/locationforecast/2.0/complete?lat=58.97023884691835&lon=5.723643489610628
This json_path only lists up all of the wind_speed_of_gust values, but what should I type in the “json_attributes:” field when there are no names before the values in the output?
$…timeseries…instant.details.wind_speed_of_gust
This json_path lists up everything below “details” including “wind_speed_of_gust” but as far as I understand I cant type wind_speed_of_gust[0], [1], [2], etc. Only “wind_speed_of_gust” one time, but I need all of them.
$…timeseries…instant.details
I even tried this json_path but the sensor attribute was waaay too big because it basically includes the whole API content, so HA was not happy.
json_attributes_path: "$.properties"
json_attributes:
- timeseries
The best thing for me would be to get all the dates AND the wind_speed_of_gust values listed up.
This is my yaml code which outputs only the first wind_speed_of_gust:
- scan_interval: 600
resource: https://api.met.no/weatherapi/locationforecast/2.0/complete?lat=58.97023884691835&lon=5.723643489610628
sensor:
- name: Vindkast
value_template: "{{ value_json.properties.timeseries[0].time }}"
json_attributes_path: "$..timeseries..instant.details"
json_attributes:
- wind_speed_of_gust
I am using https://jsonpath.com/ and https://jsonviewer.stack.hu/ to test the paths.