I am connecting to my reef controller via API. The controller requires cookie authentication which I have working fine. The problem is that the cookie must be refreshed every couple months. I have now setup 7 terrariums using the same controller. It will now be a headache to manually refresh 8 cookies once they expire.
I will use one of my switches for this example. The switch references my secrets file which contains the cookie for each controller. The format of the cookie must be auth=longlistofcharacters
A user from the controllers forum has a perl script to auto update the cookie. However, I have not been able to make it work in my setup. I have been able to setup an automation that saves the cookie in a cookie.txt file within home assistant. But the file contains more than what is actually needed. Is there a way to reference the cookie.txt file and use only the portion needed. Below is the results shown in cookie.txt.
The value_template splits it at each space, and returns the seventh part ([6] is zero-based). I don’t believe headers can use a template, though. You might have to set it up differently.
Your body_on and body_off appear to be missing a closing }.
Thanks for noticing the missing closing. It was working so I looked over it.
I left out the first part of the file thinking that it would not matter and the formatting was not correct in prior post. Below is the full cookie.txt. The spaces for the cookie line appear to be tabs, not spaces. There is an arrow pointing to the right after each word that does not transfer over to this post. If I change to looking for ‘auth’ then I can get the actual cookie, however, there is a space before it. If I try ‘auth+space’ or ‘auth+tab’ it comes back blank.
Thanks. That worked. It now shows correctly. If I used the template editor, I am able to get the correct information. However, the switch is not showing up. To simplify things, I am now trying to get the cookie directly in the switch rather than storing it in my secrets.yaml and then trying to get it in the switch. Once that is working, I will move it over to my secrets. Is the cookie line below correct?