Is there any way to get dynamic headers when RESTful sensors? The Bearer token (in Authorization header) of my REST api changes every 24 hours. So I need to updated the headers property in the rest sensor. For example:
Not really. I fix the solution by using a secret variable as authorization token. This secret is saved in secret.yaml as usual, so I refresh the yaml file once per day by using an external script thanks to a crontab entry.
I’m in the same boat, it would be great to have it driven from a template, then I can jimmy up another sensor whose state is the token or something like that.
I ended up customizing the restful sensor component to accept templates in the header option.
Works pretty well as long as the template checks that the sensor with the token has a state, however since this was basically my first foray into python it is in no state to open up a pull request.
I had the same need, my workaround was to use the command_line sensor with curl instead (the template here fetching the token from another sensor retrieving it):
It’s the closest workaround but there are features differences between the two, unfortunately.
Namely, the rest sensor supports ‘json_attributes_path’ for grabbing nested attributes.