I have a few rest sensors that each have a different resource and each one relies on another sensor state being available.
In my scenario, first I have a sensor which does a POST to retrieve a bearer token. Next I have a sensor which does a GET and uses the token in its header for the request to retrieve an API key. Lastly I have a sensor which does another GET and users the key in its header to get the data I need.
The first sensor works perfectly since it doesn’t rely on anything else but the other two show as unknown unless I trigger the update entity service manually via developer tools.
Is there a way to have the second sensor wait for a value from the first and so on?
Here’s a command line script I use for updating my printer internal clock that does something similar to get a cookie to allow uploading of a config file. Might help…
Thanks for sharing that. The part I can’t figure out is I need to take the returned json output from my first curl and use it as a header in the second curl.
It does seem a bit clunky to store outputs in files for the next curl to use. I was looking at shell commands but from my understanding they would need to be triggered using automations as where I want to create a sensor (see usage case below).
My use case is to get consumption readings from my power company which are available via their website and then dump them into a sensor for use in HA. They don’t expose any APIs to get the data so I had to work at it a bit via the browser tools to retrieve the specific calls, headers, keys etc.
My first curl is a POST which uses my credentials to get the bearer token.
Next is a GET where I pass the bearer token in the header which gives me the API key.
Then one more POST where I pass the bearer token and API key to get the power consumption readings.