Need some help here with the command line switch in the config.yaml:
I already have a standard domotic system connected to a webserver in my house that I can control with tablet or computer.Now I want to control everything with home assistant.
With Wireshark I was able to get all the actions I need.Problem is that is first need to login to the webserver from my domotic system to turn on a light :
url://[email protected]:8080 and then another url to turn on the light like:
url:://xxx.xxx.x.xxx:8080/action/6640, So, I need to make 2 commands to make it work. I already tried to combine like:
url://[email protected]:8080/action/6640 but this is not working. How to putt this in the config.yaml?
This not working,
When I copy the url from the config.yaml into my browser it works.So the url is valid and working.Ports on my router are also open.
What could be wrong here?
thanks
I think the reply from the login call will have some token to indicate that login is successful, and that token has to be included in the second call to signify it comes from a logged in user.
But I have no idea of the details, or how to implement that with curl.
Think I figured it out:
When you login for the first time to the webserver from my domotic system need to fill in name & password and confirm to save the settings on that device.I found out that you receive a cookie(with token?) from the server.
So next time when you login it goes directly to the control buttons without need to login again.
How can I login now from home assistant to the webserver to receive that cookie and save it?
Is it something like : ?
switch:
platform: command_line
switches:
lights:
command_on: "/usr/bin/curl -X GET http://192.168.0.141:8080/action/6640 -H Cookie:PHPSESSID=XXXXXXXXXX -H connection:keep-alive
It sounds like the cookie you get from the login has a limited life time - which isnât surprising as most login systems will log you out after a period of inactivity.
So you will need to get a new cookie using curl, and then send that cookie using a second curl command.
As I said before, curl seems to have that capability, but I canât give the details, because I have never done it before, but in principle the line would be
curl --cookie-jar /tmp/cookies <your url including username & password> ; curl --cookie /tmp/cookies 'http://192.168.0.141:8080/action/6640/' + other headers
where /tmp/cookies is a file to store cookies. I have no idea if this is a valid filename on hassos, so you may have to experiment with that, and the first url to get the cookie.
this is not working after a lot of trial and error.
Because I have a working curl (with a limited life time) is there any possibility that I can add an extra header like -H. 'Expire:0 ?
I was thinking because I already have a working curl command (with a limited lifetime) to make one switch to turn on every hour (due to the lifetime of the phpsessid) for about x seconds and turn off again.
Can this work to keep the session alive?
Does anyone know how to do this?