How can I bring this JSON data from an API into an entity? The datetime in the JSON array is dynamic/relative. (Last 7 days of rainfall history). I know I can reference the first value by value_json[‘days’][0], but how can I wildcard this?
I’m fine with all these dumped into a attributes of a state. Ideally, with the attribute name the date, and the attribute value the amount.
Example JSON Response:
{
"queryCost": 8,
"latitude": 41.886456,
"longitude": -87.62325,
"resolvedAddress": "60601, USA",
"address": "60601",
"timezone": "America/Chicago",
"tzoffset": -5,
"days": [
{
"datetime": "2024-03-30",
"precip": 0.447
},
{
"datetime": "2024-03-31",
"precip": 0.179
},
{
"datetime": "2024-04-01",
"precip": 0.553
},
{
"datetime": "2024-04-02",
"precip": 0.259
},
{
"datetime": "2024-04-03",
"precip": 0.248
},
{
"datetime": "2024-04-04",
"precip": 0.059
},
{
"datetime": "2024-04-05",
"precip": 0
},
{
"datetime": "2024-04-06",
"precip": 0
}
]
}
I’ve been playing around with this, obviously doesn’t work.
- platform: rest
name: VisualCrossingPrecipHistory
device_class: precipitation
unique_id: 'VisualCrossingPrecipHistory'
scan_interval:
minutes: 360
resource_template: "https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/XXXXX/last7days?unitGroup=us&elements=datetime%2Cprecip&include=days&key=XXXXXXXXXXXX&contentType=json"
value_template: "{{ value_json }}"
json_attributes_path: "$.['days']"
json_attributes:
- datetime
- precip