Please help with the correct approach to the followng task: I need to make sensor, which value is taken from a remote resourse via HTTP GET method. The problem is that first I need to login to this resourse (with POST), get the cookie, then use this cookie to GET required data.
As far as I understrand, its impossible to do it with a single command for REST sensor, so i need to write a python script to do several HTTP requests and invoke this script from the Command line sensor. After i tried official python_scripts integration, it turned out that it does not support import requests, so I tried unofficial pyscript integration. It still doesn’t work, only during initialisation. I asked at this at pyscript topic: Pyscript - new integration for easy and powerful Python scripting - #181 by Vsider , but no answer there, I now think that maybe pyscript is not intended such use and I probably took the wrong way in the very beginning.
Unfortunately, I couldn’t find similar solutions on this forum and would appreciate a hint.
Several, but lets take an example: the value is parameter update_available in seciton <MYURL>api/s/default/stat/sysinfo.
So if you try simply get without login you’ll get the following:
If you login first, according to the instructions from my link, get the cookie and try to get the json data with this with cookie - you get the data you need and can extract required value, but the problem is to implement several HTTP requests in Home assistant sensor, so that the sensor (in this case binary sensor) becomes true when the update is actually available.
I just wondered if the same values were not present on your devices too, so you could extract them through SMNP, but if they are not then either Node-Red or a bash script might be the solution.
@Mattias_Persson
Incredible, that’s exactly the solution what I was looking for. Thanks, mate!
The only thing I added is this line at the end of command: