Help with 2 json resources as sensors?

Hate to bother you guys yet again, I finally got a sensor working from my json api using get, however I need to pull from another json file on the same url endpoint, however can’t figure out how, the documentation sin’t helping me at all, (im visually impaired and use a screen reader that isn’t making sense of the docs) Below is what I have from the current sensor.

  resource: http://172.16.1.124:1337/api/v1/entries.json
  method: GET
  scan_interval: 60 
  sensor:
    - name: "BG_ENTRIES"
      value_template: "OK"
      json_attributes:
        - sgv
        - delta
        - direction
        - rssi

This gives the correct results. However I need to now pull data from /api/v1/treatments.json.
If i duplicate this and change the json file everything goes to a null value. Any ideas? Sorry if im sounding like a complete idiot. Thank you for your time.

Your configuration snippet appears to be somewhat incomplete - the first line should contain rest:, and then the second line should start with a hyphen in front of the resource definition. That way you can define multiple entries underneath the rest integration, each with their own URL (resource) and sensors.

So, a complete configuration with 2 resources would read like this (I just copied the whole configuration and only changed the URL, because I don’t know how the actual JSON response looks like, so you may need to change your sensor configuration):

rest:
  - resource: http://172.16.1.124:1337/api/v1/entries.json
    method: GET
    scan_interval: 60 
    sensor:
      - name: "BG_ENTRIES"
        value_template: "OK"
        json_attributes:
          - sgv
          - delta
          - direction
          - rssi
  - resource: http://172.16.1.124:1337/api/v1/treatments.json
    method: GET
    scan_interval: 60 
    sensor:
      - name: "TREATMENTS"
        value_template: "OK"
        json_attributes:
          - sgv
          - delta
          - direction
          - rssi

Thank you so much, now i feel like I should have caught that rest: section…Thank you for outlining it for me. I appriciate formatting it using my snippet details, when using a screen reader it all kinda gets mashed together and unless you can pick up on key highlights (url, variables, etc) it can be had to understand, so thank you!

1 Like