Please help! Scrape Sensor

My config in configuration.yaml:

  - platform: scrape
    name: PSI Readings
    resource: https://api.data.gov.sg/v1/environment/psi
    select: "do not know what to enter here"
    value_template: '{{do not know what to enter here as well}}'
    unit_of_measurement: "ug/m3"

The line of data that I need from the body of data:

"pm25_twenty_four_hourly":{"west":11,"national":16,"east":9,"central":16,"south":10,"north":12}

And format it such that it shows:

West: 11
East: 9
Central: 16
South: 10
North: 12

Please do not kill me, as my background is not a web developer. Please point me to the right direction where I can learn.

Thanks in advance!

Use the rest sensor, not the scrape.

- platform: rest
  name: Kansas Corona
  resource: "https://api.data.gov.sg/v1/environment/psi"
  json_attributes_path: "$.items[0].readings.pm25_twenty_four_hourly"
  scan_interval: 3600  #seconds
  value_template: "{{ value_json.items[0].readings.pm25_twenty_four_hourly.values() | sum }}"
  unit_of_measurement: "ug/m3"
  json_attributes:
    - west
    - national
    - east
    - central
    - south
    - north
2 Likes

Thanks for your help, @petro! I have managed to get the values I wanted. However, I thought earlier that string would be the same, and I wanted to try it myself. Hence, I omitted it from the first post, and now I am stuck again.

My config:

  - platform: rest
    name: PSI Status
    resource: "https://api.data.gov.sg/v1/environment/psi"
    json_attributes_path: "$.items[0].api_info.status"
    scan_interval: 3600  #seconds
    value_template: "{{ value_json.items[0].api_info.status.value() }}"

And also

    value_template: "{{ value_json.items[0].api_info.status.string() }}

The sensor returns no value/string. I would like to format it such that it shows:

Healthy

Secondly,

"update_timestamp":"2020-03-27T02:08:53+08:00"

Format it such that it shows:

02:08 on 27-03-2020

Appreciate you for taking time to help.