REST Sensor - passing !secrets

Am I right in thinking the headers in a REST sensor are a list of parameters that can be passed to the calling resource_template?

Specifically does this config…

  - platform: rest
    resource_template: http://api.weatherapi.com/v1/history.json?dt={{ now().strftime('%Y-%m-%d') }}
    headers:
      key: !secret weatherapi_api_key
      q: !secret weather_api_location

produce the URL I am hoping for?
i.e…

http://api.weatherapi.com/v1/history.json?dt=2020-06-02&key=[ MY_SECRET_KEY ]&q=[ MY_SECRET_LOCATION ]

Because it doesn’t seem to work… Or have I completely misunderstood something?
In which case is there way to create the resource and still keep my secrets secret?

The key-value-pairs that you specify under headers become part of the payload of the request, not part of the URL.
As far as I know you cannot access secrets as part of a template.

1 Like