REST: get the last occurrence (first of the list)

Hi,
I need to grab the 4 fields of the last (I mean the first of the list) occurence (of this url) using a sensor.
This code not works:

sensor:
  - platform: rest
    name: "air"
    json_attributes:
      - data
      - descrizione
      - previsione
      - tendenza
    value_template: "{{ value_json() }}"
    resource: https://dati.comune.milano.it/dataset/cc3c732a-99e1-432d-948d-12caad4c336d/resource/91451e4a-e73f-4db9-9c2b-22a6a0753ebd
    scan_interval: 21600

Thanks all.

Try adding the json_attributes_path as $.XX
XX being the XXth set of data.
This will only work if that info is always on the XXth location…better to try and get the data sorted from old>new and take 0 as XX

1 Like

And your url is wrong…you should get the json, not the webpage…
try this and play around

  - platform: rest
    name: "air"
    json_attributes_path : "$.35"
    json_attributes:
      - data
      - descrizione
      - previsione
      - tendenza
    value_template: "{{ value_json.0.data }}"
    resource: https://dati.comune.milano.it/dataset/cc3c732a-99e1-432d-948d-12caad4c336d/resource/91451e4a-e73f-4db9-9c2b-22a6a0753ebd/download/qaria_reportariagiorno_2022-05-21.json
    scan_interval: 21600