If I create a RESTful sensor fetching data from external API endpoint, how is the refresh frequency controlled? I’ve tried this:
- platform: rest
But regardless of the value (or no value at all) I can’t get the sensor to update automatically, it just stays as is until I refresh manually.
https://www.home-assistant.io/integrations/rest does not list anything on refresh frequency, but https://www.home-assistant.io/docs/configuration/platform_options/ does mention
scan_interval, although as mentioned, it has no effect. Plus it states “These options are being phased out and are only available for single platform integrations.”
Does the information change for what you’re scanning? If the answer is no, then you won’t see an update because the information is the same.
Right, that makes sense. However, once information changes - and since this is a pull activity - what determines how often the sensor will poll for updates?
That is the problem with polling.
Worst case you could have the “wrong” state scan_interval minus one second if the value updated just after you polled.
I’m still looking for tips here. I have set up a restful sensor and it’s hitting the rest endpoint like 100 times each hour, which is far too often and I’m getting complaints and unnecessarily reaching bandwitdh limits that prevent the sensor from working constantly. So I would like an option to limit the sensor to only poll once every
n minutes or something similar.
Searching for something similar I found some nice already answered threads that helped me out:
I have a rest platform that gathers data from my smart tv and a few template sensors that parses the gathered data into individual entities. It looks like this:
- platform: rest
resource: !secret samygo_tv_living_channelinfo
name: TV Living ChannelInfo
- platform: template…
is it possible to manually trigger a refresh of a restful sensor? According to the docs, there is no command for rest sensors. Only rest.refresh what I guess is to reload the configuration.
Background is: I have a template switch which is based on a rest sensor. If you toggle the switch, the command is sent. But the switch still shows the old state, until the next refresh of the rest sensor. This is confusing…
So basically, setup a very long scan_interval value for your sensor, and whenever you want to update the value run with an action the following:
- service: homeassistant.update_entity