Hi, I’m trying to parse data from this api (https://data.cdc.gov/resource/2ew6-ywp6.json?county_names=Kings). The top level json element is unlabeled, and I’m struggling to figure out how to access the desired elements.
Here’s the general structure of my sensor, which works so long as I take the entire API response as a single element:
- platform: command_line
name: "COVID WasteWater"
scan_interval: 60
command: >
echo "{ \"data\":" $(
curl -s https://data.cdc.gov/resource/2ew6-ywp6.json?county_names=Kings
) "}"
value_template: >
{{ value_json }}
But, I’d like to use a value template that ingests each API response separately, and allows me to access the json attributes, like this:
- platform: command_line
name: "COVID WasteWater"
scan_interval: 60
command: >
echo "{ \"data\":" $(
curl -s https://data.cdc.gov/resource/2ew6-ywp6.json?county_names=Kings
) "}"
value_template: >
{{ value_json[0] }}
json_attributes:
- wwtp_id
- date_end
- detect_prop_15d
- percentile
{{ value_json[0] }}
works in the dev_tools template, but doesn’t retrieve any data when actually configuered in the sensor. I’ve also tried {{ value_json[0] | default }}
based on this post.