Sensor - platform rest scan interval - "system default"

Hi,
In the “rest” integration for sensors, you can (I have defined) a parameter that defines the time between each check (scan_interval). What I don’t know, and I haven’t found in the documentation, is if I don’t define the parameter, what is the default value?

I use this sensor to extract the values of my “Airzone” system, and I would not want to remove the parameter and flood the endpoint with requests.
Where could I see or how could I know the default refresh rate?

Thanks in advance

The default is 10 seconds. I had to look at the source to see:

DEFAULT_TIMEOUT = 10

That doesn’t actually control the scan interval. It is the default for the request timeout.

The default is actually 30 seconds, and it’s defined here.

2 Likes

Some integrations’ docs declare different defaults but the rest integration does not appear to have any code to override that 30 seconds default from the sensor platform.

Which is why I said the default was 30 seconds and pointed to the sensor component level code. :slightly_smiling_face:

Thanks, it was the information I needed, :wink:

Hi Phil,

sorry to revive an old topic, but I was looking for the same info and I read your post.

The documentation here is not correct? I’m asking because the RESTful Sensor has a specific timeout option.

And effectively, I configured 2 restful sensors with scan_interval: 120, and it looks like they poll the device every 2 minutes as per documentation above.

{"timestamp": "2021-07-23T05:29:25+00:00", "type": "HTTP-Info"},
{"timestamp": "2021-07-23T05:29:25+00:00", "type": "HTTP-List"},
{"timestamp": "2021-07-23T05:27:26+00:00", "type": "HTTP-Info"},
{"timestamp": "2021-07-23T05:27:26+00:00", "type": "HTTP-List"},
{"timestamp": "2021-07-23T05:25:26+00:00", "type": "HTTP-Info"},
{"timestamp": "2021-07-23T05:25:26+00:00", "type": "HTTP-List"},

Thanks for any clarification on this.

Hi alex, as Phil comments in the other post, “restful” has this value hardcoded at the code level.

I guess that line in the code is a default value, and when you change the value in the configuration of the sensor, it uses it. Check the log I added to the post, I have 2 rest sensors configured like this, and they poll every 2m as you can see. I used scan_interval: 120:

  - platform: rest
    scan_interval: 120
    resource_template: "{{ states('input_text.nuki_bridge_url') }}/list?&token={{ states('input_text.nuki_bridge_token') | urlencode }}"
    name: "Nuki Bridge Endpoint List"
    force_update: false
    value_template: "OK"
    json_attributes:
      - lastKnownState
      - firmwareVersion
      - nukiId
      - name

  - platform: rest
    scan_interval: 120
    resource_template: "{{ states('input_text.nuki_bridge_url') }}/info?&token={{ states('input_text.nuki_bridge_token') | urlencode }}"
    name: "Nuki Bridge Endpoint Info"
    force_update: false
    value_template: "OK"
    json_attributes:
      - versions
      - scanResults
      - wlanConnected
      - serverConnected

In the init of the rest component there’s the code, with a default imported. It’s configurable:

image

Hi,
Is it possible to change this value dynamically? The API I’m calling has a daily limit and I’d prefer not to query at all at night and more often during the day.

No, not in the sensor config.

And yes (with a workaround).

Set the scan interval to a very large number (years). Then use an automation to call the homeassistant.update_entity service https://www.home-assistant.io/docs/scripts/service-calls/#homeassistant-services to update your sensor when you want to.

The “dynamic” part comes from how you define your trigger(s) and condition(s).

2 Likes