(JSON) REST Sensor with attributes help

So I’ve set up an Air Quality sensor using the REST platform to pull data from EPA Victoria (https://www.epa.vic.gov.au/) and it’s working well. However, I’d like it to take on a few more attributes which I can’t workout how to do.

The JSON data supplied by the link for the sensor I use is as follows:

{
  "siteID" : "4afe6adc-cbac-4bf1-afbe-ff98d59564f9",
  "siteName" : "Melbourne CBD",
  "siteType" : "Standard",
  "geometry" : {
    "type" : "Point",
    "coordinates" : [
      -37.8073959,
      144.97
    ]
  },
  "siteHealthAdvices" : [
    {
      "since" : "2020-01-05T11:00:00Z",
      "until" : "2020-01-05T12:00:00Z",
      "healthParameter" : "PM2.5",
      "averageValue" : 1.8,
      "unit" : "µg/m³",
      "healthAdvice" : "Good",
      "healthAdviceColor" : "#64A13C",
      "healthCode" : "1021"
    }
  ],
  "parameters" : [
    {
      "name" : "PM2.5",
      "timeSeriesReadings" : [
        {
          "timeSeriesName" : "1HR_AV",
          "readings" : [
            {
              "since" : "2020-01-05T11:00:00Z",
              "until" : "2020-01-05T12:00:00Z",
              "averageValue" : 1.8,
              "unit" : "µg/m³",
              "confidence" : 91.67,
              "totalSample" : 12,
              "healthAdvice" : "Good",
              "healthAdviceColor" : "#64A13C",
              "healthCode" : "1021"
            }
          ]
        },
        {
          "timeSeriesName" : "24HR_AV",
          "readings" : [
            {
              "since" : "2020-01-04T12:00:00Z",
              "until" : "2020-01-05T12:00:00Z",
              "averageValue" : 4.6,
              "unit" : "µg/m³",
              "confidence" : 95.49,
              "totalSample" : 288,
              "healthAdvice" : "Good",
              "healthAdviceColor" : "#64A13C",
              "healthCode" : "1029"
            }
          ]
        }
      ]
    }
  ]
}

The sensor set up is as follows:

- platform: rest
  resource: "https://gateway.api.epa.vic.gov.au/environmentMonitoring/v1/sites/4afe6adc-cbac-4bf1-afbe-ff98d59564f9/parameters?X-API-Key=sekritkey"
  name: Melbourne Air Quality
  json_attributes:
    - siteName
  value_template: '{{ value_json["siteHealthAdvices"][0]["healthAdvice"].title() }}'
  headers:
    User-Agent: Home Assistant
    Content-Type: application/json

And I get the following:

How am I able to include few of the other data fields as attributes? Mainly the “averageValue” that’s under “siteHealthAdvices”.

Cheers!

json_attributes

(string | list)

A list of keys to extract values from a JSON dictionary result and then set as sensor attributes.

That’s what I used, but it doesn’t explain how to set non-top level categories as attributes, which is what I’m after so it’s of no help

sorry i didnt see you did that in the sensor
you need to create a template sensor as well
with a
value_template: "{{ states.sensor.melbourne_air_quality.attributes.siteHealthAdvices[0].averageValue }}"

That, and he also needs to add siteHealthAdvices under the json_attributes list of the REST sensor.

I think understands that part already.
My question to @icaman004
Is there a NSW one ?

I’ve given up and just created 2 sensors, one to get the value, and one to get the condition. I’ve tried everything I can think of and there’s just no way I can get a non-top level data field as an attribute.

They both work, just aren’t as neat as I’d like them to be but are functional and do the job I want.

There would have to be a NSW one as well, but since I don’t live there I’m not sure what their organisation is or how it would work as far as getting the data. Using the WAQI component you’d be able to get what you need, but reason I went to EPA VIC is because that’s the standard used here, and matches with warnings issues on radio etc, whereas WAQI uses a different standard to report air quality

@icaman004 If you post your code im sure someone on here can help you solve it, @pnbruckner is an expert, with templates, me I suck at it, im more node-red logical thinker. Well at least i think i am.:thinking: