Switching the Thermosmart off is done with this example scrip (pause.sh)
Code: Select all
USERNAME=xxxx
PASSWORD=yyyy
CLIENT_ID=zzzz
SECRET=ssss
THERMOSTAT_ID=IT12345
# 1. Login (username: either thermostat ID or email, in this case, we use thermostat ID)
curl -k -c cookie.txt -vd "username=$USERNAME&password=$PASSWORD" "https://api.thermosmart.com/login"
# 2. Get Authorize Dialog
curl -k -b cookie.txt --output answer.html -v "https://api.thermosmart.com/oauth2/authorize?response_type=code&client_id=$CLIENT_ID&redirect_uri=http://clientapp.com/done"
TID=`grep transaction answer.html | sed "s/.*value=\"\(.*\)\".*/\1/"`
echo "---------------------------------"
echo "$TID"
echo "---------------------------------"
# 3. Authorize (read out transaction_id from the HTML form received in the previous step). transaction_id prevents from XSRF attacks.
curl -k -b cookie.txt --output code.txt -vd "transaction_id=$TID" "https://api.thermosmart.com/oauth2/authorize/decision"
CODE=`cat code.txt | sed "s/.*code=\(.*\).*/\1\n/"`
echo "-------------------------------"
echo "$CODE"
echo "-------------------------------"
# 4. Exchange authorization code for Access token (read out the code from the previous response)
curl -k -u $CLIENT_ID:$SECRET --output access.txt -b cookie.txt -vd "grant_type=authorization_code&code=$CODE&redirect_uri=http://clientapp.com/done" "https://api.thermosmart.com/oauth2/token"
ACCESS=`cat access.txt | sed "s/.*token\":\"\(.*\)\",\"thermostat.*/\1\n/"`
echo "-------------------------------"
echo "$ACCESS"
echo "-------------------------------"
# 5. Access protected resource
curl -H "Content-Type: application/json" -X POST -d '{"pause":true}' "https://api.thermosmart.com/thermostat/$THERMOSTAT_ID/pause?access_token=$ACCESS"
I created a virtual X10 switch by sending a netcat command to mochad, causing domoticz to add the H1 switch,which I activated and named "Heating"
Code: Select all
echo "pl H1 on" | nc localhost 1099
Code: Select all
script://home/pi/thermosmart/pause.sh
Then I created two simple blockly scripts to link the heating switch with the inverse armed switch
Future improvement steps:
- Find out how long the Thermosmart access token is valid so I can create a Thermosmart device using JSON directly in Domoticz
- Add all other Thermosmart parameters to monitor the full state of the heating