Restful sensors should support dynamic header templates

Came across this thread and it seems that many are in the same boat as me.

Using any of the rest sensors is a bit limited as most modern APIs require bearer-tokens that often are loaded in a separate call.
If the header: attribute of i.e. the the restful sensor supports templating, it would be possible to use one restful sensor to get the token and store it in a sensor attribute or state and then use another restful sensor to fetch data using the previously stored token in the second calls header template.

This feature request is about adding template support for the headers on all rest sensors.

sensor:
  - platform: rest
    resource: `http://domain/my/api`
    name: foo_status
    headers:
      Authorization: 'Bearer {{ state_attr("sensor.access_token", "token") }}'
    value_template: '{{}}'
    scan_interval: 30

Hi @esbenr

I’m facing the same situation. Did you found any solution or workaround you’d like to share?

Greetings

No unfortunately not.
I decided to build my own component for this and other architectural reasons.
But feel free to pick up the idea and make a pull request.

/Esben

Thanks for reply. I think I’ll go a similar way. To get a little competence in components is a nice side-effect.

Greetings

I would also love this feature as I’m stuck with the exact same problem.
Care to share your solution @esbenr ?

Hi,

I didn’t have time to make the change my selv and solved it by making a Node-RED flow instead.
But if you have the time feel free to pick it up and contribute. :slight_smile:

/Esben

is there already another workaround for this? or any solution? maybe storing the variable in a file? and then reading it with a curl command or something?

did you create a custom component for this? can you share it?