RESTful sensor refreshes too frequently

Hi everybody,

I am currently having some issue with the RESTful sensor and maybe need someone to point out any obvious misconfiguration.
I am trying to create a sensor to refresh an access token for home connect but only every x hours since there is a rate limit (max. 100 / day) and the access token is valid for 24 hours.
The sensor keeps polling every 30 seconds regardless of the configured scan_interval. I have already restarted HA

- platform: rest
  name: homeconnect_token_request
  resource_template: ""
  method: POST
    Content-Type: application/x-www-form-urlencoded
  payload: !secret homeconnect_refreshtoken_payload
    - access_token
    - token_type
    - expires_in
  value_template: 'ok'
  scan_interval: 7200

Do you have any ideas on this?
Why is my “scan_interval” not working as intended - I have viewed the code of the component and as far as I can see it should work this way.

I’m not so sure. This may have worked at some point, but the rest platform is now using a shared coordinator that appears to take its configuration from the rest integration, and otherwise falls back to DEFAULT_SCAN_INTERVAL which is defined as 15 (seconds). Unfortunately that does not explain the behaviour you observe.

It’s fairly easy to transform your configuration to the new integration, and that clearly has scan_interval defined in its schema. I would give that a try first.

The Restfull sensor (old style) doesn’t actually support overriding the scan_inteval

The new one does, and the 60sec are likely picked from a rest integration configuration:

Neither of those docs even mention a scan interval, other than in one random, unrelated example each. Am I missing something, or is this just a “hidden” attribute?

Seems to be undocumented like in the RESTful Sensor. Hopefully it will not fade-out silently again.

One issue I now have with the rest integration:

- resource: "<haid>/programs/active"
  method: GET
  scan_interval: 180
    authorization: 'Bearer {{ states.sensor.homeconnect_token_request.attributes["access_token"] }}'
    content-type: 'application/json'
  - name: washing_machine_json
    value_template: 'ok' 
      - data
      - error

The jinja template in the header doesn’t seem to evaluate - I can’t really prove it but I get an “access token malformed” error. And even with log_level debug for the rest component the curl isn’t visible.

Anyone have noticed the same?
Or has someone a different idea to get the refreshed access_tokens into the header dynamically?

— edit —

Ok I have seen somebody has already worked on the templating for headers and the change was merged into homeassistant-dev 3 weeks ago. Hopefully it will arrive in the next (minor) release

Ok, I am very confused (but I must confess to not even realising that there was a new REST integration (although it isn’t that new)

But anyway…

I am using the old format and use scan_interval which I am pretty sure must be working else I think I would have been blocked on a few endpoints by now for over using them.


I wish someone would update it to allow !secrets in a templated resource / resource_template

Putting the full resource:, including template, in secrets might work, I guess