My local Environment Department publishes a range of air quality stats via an API at https://www.dpie.nsw.gov.au/air-quality/air-quality-data-services/air-quality-api. I’m trying to setup a REST sensor to collect the data from this API. However, I’m having trouble getting it to work and hope that someone that better understand JSON formatting can help please?
An example of the data coming back from the API is formatted as follows:
[
{
"Site_Id": 190,
"Parameter": {
"ParameterCode": "NEPH",
"ParameterDescription": "Nephelometer ",
"Units": "10^-4 m^-1",
"UnitsDescription": "10^-4 m^-1",
"Category": "Averages",
"SubCategory": "Hourly",
"Frequency": "Hourly average"
},
"Date": "2021-09-20",
"Hour": 18,
"HourDescription": "5 pm - 6 pm",
"Value": 0.09,
"AirQualityCategory": null,
"DeterminingPollutant": null
},
{
"Site_Id": 190,
"Parameter": {
"ParameterCode": "PM10",
"ParameterDescription": "PM10",
"Units": "µg/m³",
"UnitsDescription": "microgram per cubic meter",
"Category": "Averages",
"SubCategory": "Hourly",
"Frequency": "Hourly average"
},
"Date": "2021-09-20",
"Hour": 18,
"HourDescription": "5 pm - 6 pm",
"Value": 19.302,
"AirQualityCategory": "GOOD",
"DeterminingPollutant": null
}
]
I have been trying to use a REST Sensor, but am confused as to the difference between this and the REST integration? In any event, it seems messy because the value is always in a ‘Value’ subfield and the field name (NEPH or PM10 in the example above) is a sub-sub field under ‘Parameter’.
Thus far I have the following in my sensors.yaml file:
- platform: rest
name: 'Chullora Air Quality'
json_attributes:
- PM10
resource: https://data.airquality.nsw.gov.au/api/Data/get_Observations
method: POST
payload: '{ "Parameters": [ "PM10","NEPH" ], "Sites": [190], "StartDate": "2021-09-20T17:00:00", "EndDate": "2021-09-20T18:00:00", "Categories": ["Averages", "Site AQC", "Regional AQC"], "Frequency": ["Hourly average"] }'
timeout: 150
json_attributes_path: "[0].response"
json_attributes:
- Site_Id
- Hour
- Value
- Date
I’ve spent hours reading and re-reading the Documentation without success. Any solutions or pointers to what I’m doing wrong would be gratefully received.