Multiple RESTful sensors each with their own scan_interval

Hi there

Probably a n00b question but I suck at yaml so I have to ask.

I have 3 sensors that get their data from REST APIs.

I want each one to update at a different frequency because I don’t want to hit API limits.

The issue that I saw in my history is that the 2nd sensor was polling at the frequency that I set for my 1st sensor. So is my syntax below correct?

Basically, I want sensor 1 to update every 2 mins (120 secs), sensor 2 to update every 30 mins (1800 secs) and sensor 3 to update every 5 mins (300 secs).

sensor:
  - platform: rest
    name: External IP
    resource: https://ipapi.co/json/
    scan_interval: 120
    json_attributes:
      - org
    value_template: "{{ value_json.ip }}"
  - platform: rest
    name: "ESP API Calls"
    resource: https://developer.sepush.co.za/business/2.0/api_allowance
    scan_interval: 1800
    headers:
      token: XXXXXXXXXX
    value_template: "{{ value_json.allowance.count }}"
    json_attributes_path: "$.allowance"
    json_attributes:
      - limit
      - type
  - platform: rest
    scan_interval: 300
    name: "Loadshedding Schedule"
    resource: https://developer.sepush.co.za/business/2.0/area
    params:
      id: tshwane-7-erasmia
      test: current
    headers:
      token: XXXXXXXXXX
    value_template: "{{ value_json.events[0].note }}"
    json_attributes_path: "$.events[0]"
    json_attributes:
      - start
      - end

Hello fellow South African — and my sympathies.

Maybe I can save you a lot of trouble. Have a look here.

Credit to others on which this is based.

Hi Saffer!

Thank you, looks useful!

I do wanna use this to improve my yaml, so in my original code above, will all 3 sensors use a different scan_interval?

Also it’s very confusing when to use:

sensor:
  - platform: rest

vs

rest:
  sensor:

Any guidance on that?

I think you’ll see a warning in your log about the use of scan_interval. I recall it being removed, as the option is being deprecated for many platforms in favour of creating your own automation(s) to update entities. I think what you’re seeing is that your settings are ignored and only the default is used.

Also keep in mind there’s a REST platform and a REST sensor platform.

EDIT: Actually, I’m not sure what’s going on with the scan interval. I see the setting in both. Just carefully check your logs again for any other hints.