#Help with a simple json scraper

6 messages · Page 1 of 1 (latest)

scarlet ruin
#

I'm trying to set up my first scraper integration. I'm hitting my purpleair sensor locally since the purpleair API is deprecated.

I've read the scrape docs but don't see any examples for parsing json.

The purpleair local json payload is pretty simple (at /json), it looks like this:

{
  "pm2.5_aqi":4,
  "p_0_3_um":264.00,
}
``` etc.

I'm confused because the `select` string in the sensor map is required, but that's for html tags, which isn't relevant for me. I understand I need to use `value_template` to teach HA how to grab the right value out of the json response. I'm not sure how to reference the entire json object so I can then index it to grab `"p_0_3_um"` for example. 

Can someone provide a sample scraper config for that?
finite aspen
#

this scrape integration is for web pages, can you consider using the rest integration instead for json payloads?

scarlet ruin
#

That totally works!

#

Thanks for the help.

Here's my config

sensor:
  - platform: rest
    resource: http://10.0.0.22/json?live=true
    name: "PurpleAir Sensor"
    scan_interval: 120
    json_attributes:
      - current_temp_f
      - current_humidity
      - pressure
      - pm2.5_aqi
      - pm1_0_cf_1
      - pm2_5_cf_1
      - pm10_0_cf_1
    value_template: "{{ value_json['pm2.5_aqi'] }}"

I was hoping to grab all those json attributes as separate values that I could reference, but it looks like only the pm2.5_aqi value is coming out.

Is there a way to grab all those values without creating a second sensor? I feel I shouldn't have to make 10 requests to get the 10 values from the single request.

finite aspen
#

You can have several sensors for that single rest platform. I think there were some examples for that. Now those values are attributes for your sensor, you can use them in many places like that