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: "https://api.home-connect.com/security/oauth/token"
  method: POST
  headers:
    Content-Type: application/x-www-form-urlencoded
  payload: !secret homeconnect_refreshtoken_payload
  json_attributes:
    - 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.
Thanks!

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?

Thanks!
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: "https://api.home-connect.com/api/homeappliances/<haid>/programs/active"
  method: GET
  scan_interval: 180
  headers:
    authorization: 'Bearer {{ states.sensor.homeconnect_token_request.attributes["access_token"] }}'
    content-type: 'application/json'
  sensor:
  - name: washing_machine_json
    value_template: 'ok' 
    json_attributes:
      - 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)
image

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.

And…

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

Hello.

Sorry for my post, is a bit offtopic but related with those access tokens we get from Home Connect.
Im using the official Home Connect integration, everything works like i want, till the token expires ( didnt noticed if thats 12 hours or 24hours ). But after that, all my automations stops working.

You speek about a scan_interval and a rate limit of 100/day … but it looks like you using a different approuch to connect to your devices, right ?

Hi,

For this particular use case I have switched to the „Home Connect Alt“ Integration installed through HACS and never looked back - it works absolut flawless!