Finally, I was able to make it. I used Web Developer Tools in Chrome as you advised and could build two cURL commands: One to log in to the router and to get the cookie with session ID and then another command to reboot it, using the session ID I got earlier.
However, now I am stuck on the easiest part, which is the automation one. For whatever reason, if I call both cURL shell commands, one after another in the Developer Tools Service, the calls work and the router is rebooted. However, if I run the commands (inserting a 5 seconds wait between commands) in an automation, the router is not rebooted.
shell_command:
reiniciar_movistar_login: "curl -c /config/tmp/cookie-jar.txt 'http://[ROUTER_IP]/te_acceso_router.cgi' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Origin: http://[ROUTER_IP]' -H 'Upgrade-Insecure-Requests: 1' -H 'DNT: 1' -H 'Content-Type: application/x-www-form-urlencoded' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' -H 'Referer: http://[ROUTER_IP]/te_acceso_router.html' -H 'Accept-Language: en-US,en;q=0.9,es;q=0.8' -H 'Cookie: sessionID=' --data-raw 'loginPassword=PASSWORD' --compressed --insecure"
reiniciar_movistar_reboot: "curl -b /config/tmp/cookie-jar.txt 'http://[ROUTER_IP]/rebootinfo.cgi?sessionKey=' -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1' -H 'DNT: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' -H 'Referer: http://[ROUTER_IP]/resetrouter.html' -H 'Accept-Language: en-US,en;q=0.9,es;q=0.8' --compressed --insecure"
And this is just a simple automation I created to check it:
alias: Reiniciar Routers
description: ''
trigger:
- platform: time
at: '04:15'
condition: []
action:
- service: shell_command.reiniciar_movistar_login
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- service: shell_command.reiniciar_movistar_reboot
mode: single
I am guessing that the automation is perhaps opening two shells in the background, so the remote host (router) is generating two different session IDs, although I am not sure. I will try to figure it out tomorrow, but I am just saying in case you or someone else has any suggestion.
Any idea on how to concatenate both commands in one cURL line just in case it works that way?