@danielo515 wrote:
Hello.
I want to run a rest command every hour to fetch an auth token and then I want to use that token in some other automations.
I can’t find any good way of doing this.
If this were a normal application I will just make a post request and store the result token in some temporary variable, but I don’t find any HASSIO way of doing this.
What I tried so far:
- Set the basic auth (username and password) in secrets.yaml
- Because you can’t access secrets from templates ( I don’t understand this limitation) create an input text to hold the secret values
- Create a rest sensor that uses the input text values like this:
- platform: rest resource: http://192.168.0.121/cgi-bin/api.cgi?cmd=Login&token=null method: POST payload: '[{"userName":"{{ states.input_text.xxx_user.state }}","password":"{{ states.input_text.xxx_password.state }}"}]' value_template: '{{ value_json.0.value }}' json_attributes: - value.Token.lease_time - value.Token.name
And that’s all for now. The rest sensor has been failing but I don’t know why because I don’t know what is the exact request it is doing. Is there any log where I can see the actual request? If I try a curl request with this same values I get a satisfactory response, which looks like this:
[ { "cmd" : "Login", "code" : 0, "value" : { "Token" : { "leaseTime" : 3600, "name" : "the-actual-token-value" } } } ]
Do you know of any other better approach?
I would love to use AppDaemon, but it seems to be a silo where you can’t fetch values from.Thanks in advance
Posts: 8
Participants: 3