Templating in rest headers

I should use a template, or be able to pick up a value from a state attribute inside rest headers.
I need to use an authentication token (that’s about 1050 characters long , so i can’t use a state but i need to use an attribute).
I can call a secret value, but this is not sufficient to me because this kind of authentication token must be renewed every 1 hour, so if i use a secret i would need to restart hassio every hour.

I would like to do something like this:

`sensor:

This is needed to integrate bticino smarther thermostat.

Hope to have written all the needed informations.

Thank you very much in advance

Hi RaceLuke, I’ve been looking for a way to integrate my BTicino Smarther thermostat in home assistant for months. Unfortunately I have too little programming knowledge to help you. I’ll continue to follow this topic and I put my thermostat at your disposal for any test.
Best regards, Michele.

Thanks

I already have the thermostat installed and working (with his app)…also working integrated in home assistant if i manually write the authentication token that expires every one hour (so, it works only for 1 hour)

Here is the link to the api to use for integration:
https://portal.developer.legrand.com/docs/services/smartherV2/operations/Chronothermostat-Measures

Did you manage to make the legrand API working with hassio ?

I’m surprised that the headers can’t be templated, this is something that can come quite useful, specifically for some authorization scenarios where non-static tokens have to be passed.

Hi all!
I found this request about bticino thermostat integration in home assistant.
I ask if someone have a solution to resolve this problem and if there is a way to integrate legrand/“bticino living now” API.

Regards

Hi, this request is here from jannuary, how we can have a response from team? I need the same thing. I’m a developer but i’m new to python. I can help for modify the component but i need someone who give me some information.
Can we collaborate toghether and make this change?
Thanks all.

Hey Guys,

I’m currently working on this, and believe I’m quite close. I have done some testing and seems like it would work.

I need to write and update testes where needed, then can create the PR to have this merged in.

How do you guys plan to store the token for use in this template though? My testing shows that I will have to get it set as an attribute since state values can only go to 255 chars, and my tokens are >255 chars.

You can have a preliminary look around in the rest-header-template branch if you want at: https://github.com/KiLLeRRaT/home-assistant/commits/rest-header-template

Cheers,

Hi sorry for long time, but i don’t have seen the reply! Anyway, thanks for support and for what you’ve done. I see that the code is developed, what about the merge in the main branch?
Anyway, about how to store the variable, i create a new sensor and in state i store the date of when the token is created, in the attributes i create a sub-attribute “token”…
Maybe a code is more clear! :smiley:

array(
‘state’ => date(“Y-m-d H:i:s”),
‘attributes’ => array(‘token’ => $_GET[‘code’])
);

and i call the value in yaml like this:

{{ states.sensor.my_token_sensor.attributes.token }}

Hope to help you and to have some information about your work!

Hi @engal89, Sorry, I’ve been a bit busy and haven’t had a chance to complete this.

As far as I remember, I just needed to create test cases and this was ready to do (unless it failed some test though).

I’m happy for you to build in the test cases and create a PR into my fork and I will create the PR to get it all sorted?

Let me know how you go or if you need info.

Regards,
Albert

Hi @KiLLeRRat, thanks for the possibility, but i’m a java developer and i don’t know nothing about python :frowning: i have seen your code, but i don’t know where to start :smiley: . I hope that one day this develop will be on the dev branch! in the meanwhile i try to study something about python and try to collaborate with your code! :slight_smile:

Could use some love here. I really need this and I can’t believe that HA hasn’t implemented it yet.

Someone else started work on this feature again, it’s waiting for a merge in this pull request:
Add REST sensor/binary_sensor/switch templated headers & params by koying · Pull Request #54426 · home-assistant/core (github.com)