Donât have a ReadNAS or anything to test it on, but reading that thread, the curl command will work with an extra parameter.
We will now have to do 2 separate curl commands. The first is to get your auth token. Again, without a device, this is just guess. Assuming the output looks like their example:
<script type="text/javascript">
<!--
csrfInsert("csrfpId", "mKrWJJlKMv5iqXUcSK7dEruWxdSbSqNi713aOVNCpYkLIA1wWmCUhmoZeV8EJ-jfXb6X6K6rT9InWOSd_OPiWPeonCpp01LC");
//-->
</script>
The following command could parse the token.
token=$(curl -sS -u username:password http://nas_ip/admin/csrf.html | grep -oP '"csrfpId", "\K[^"]+')
Now use that token in the other curl command you already use, whatever it may be, by adding the --header option. For example, if your shutdown command was the following (found from some random github page)
curl -u admin -k -d command=poweroff -d shutdown_option=1 -d OPERATION=set -d PAGE=System -d OUTER_TAB=tab_shutdown -d INNER_TAB=none https://{$1}/get_handler|awk -F"message>" '{print $2}'|awk -F"</" '{print $1}'
It would now be:
curl --header "X-CSRFToken: mKrWJJlKMv5iqXUcSK7dEruWxdSbSqNi713aOVNCpYkLIA1wWmCUhmoZeV8EJ-jfXb6X6K6rT9InWOSd_OPiWPeonCpp01LC" -u admin -k -d command=poweroff -d shutdown_option=1 -d OPERATION=set -d PAGE=System -d OUTER_TAB=tab_shutdown -d INNER_TAB=none https://{$1}/get_handler|awk -F"message>" '{print $2}'|awk -F"</" '{print $1}'
Iâm not sure how you are calling the curl command from Home Assistant, so itâs hard to tell you how to pass in the id. Maybe just make it a single bash script.
#!/bin/sh
host=192.168.0.1
token=$(curl -sS -u username:password http://$host/admin/csrf.html | grep -oP '"csrfpId", "\K[^"]+')
curl --header "X-CSRFToken: $token" -u admin -k -d command=poweroff -d shutdown_option=1 -d OPERATION=set -d PAGE=System -d OUTER_TAB=tab_shutdown -d INNER_TAB=none https://$host/get_handler|awk -F"message>" '{print $2}'|awk -F"</" '{print $1}'
Then you would just call this bash script from home assistant to shut down.
Hopefully that gives an idea how to do it. The parsing part could be handled many different ways. Iâm pretty bad at parsing syntaxâŚ