Page 1 of 6
Control Thermosmart thermostat
Posted: Tuesday 10 March 2015 11:28
by kaashoek
Using the public API of the Thermosmart thermostat I am now able to switch on/off the heating based on the alarm setting from a Visonic powerplus that controls a X10 switch to signal the state of the alarm and a mochad interface in Domoticz to monitor the X10 switch. (seems complicated)
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"
A similar scrip is created to start the heating using "pause":"false" as POST parameters
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
I linked the switch with the scripts by adding the script as (example)
Code: Select all
script://home/pi/thermosmart/pause.sh
The visonic powerplus can control X10 switches to I set it to switch on/off a switch whenever the alarm is switched on/off, after a first alarm switching domoticz has discovered the switch and I activated the switched and called it "Armed"
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
Re: Control Thermosmart thermostat
Posted: Wednesday 11 March 2015 11:07
by kaashoek
Using the Thermosmart webhook url the temperature object in Domoticz is update every time the temperature changes
Ensure the webhook is set correctly
Code: Select all
http://my.public.domoticz.address.com/thermosmart/events.php
The domoticz server has a web server that serves the following events.php file
Code: Select all
<?php
$device = '84'; // set to the device ID of the dummy thermometer created in Domoticz
$json = file_get_contents('php://input');
$obj = json_decode($json);
foreach ($obj as $key => $value) {
if ($key == 'room_temperature') {
// file_put_contents( "/tmp/thermosmart.log", $value . "\n", FILE_APPEND );
$url = '127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=' . $device . '&nvalue=0&svalue=' . $value;
// file_put_contents( "/tmp/thermosmart.log", $url. "\n", FILE_APPEND );
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
// file_put_contents( "/tmp/thermosmart.log", $output. "\n", FILE_APPEND );
}
}
Control Thermosmart thermostat
Posted: Tuesday 24 March 2015 19:22
by smika
I find my hardware name and hardware password (SECRET=ssss and THERMOSTAT_ID=IT12345) on a sticker from Thermosmart. But where can i find my client ID?
Re: Control Thermosmart thermostat
Posted: Thursday 26 March 2015 17:42
by rron
smika wrote:I find my hardware name and hardware password (SECRET=ssss and THERMOSTAT_ID=IT12345) on a sticker from Thermosmart. But where can i find my client ID?
You can find this on the instructioncard including with your ip adres.
Re: Control Thermosmart thermostat
Posted: Friday 27 March 2015 11:10
by smika
rron wrote:smika wrote:I find my hardware name and hardware password (SECRET=ssss and THERMOSTAT_ID=IT12345) on a sticker from Thermosmart. But where can i find my client ID?
You can find this on the instructioncard including with your ip adres.
I have only the following lines:
Hardware name:
Hardware Password:
Mac adres
Ip Nummer
SSID
But I don't have a client_id.
Re: Control Thermosmart thermostat
Posted: Saturday 28 March 2015 13:09
by rron
smika wrote:rron wrote:smika wrote:I find my hardware name and hardware password (SECRET=ssss and THERMOSTAT_ID=IT12345) on a sticker from Thermosmart. But where can i find my client ID?
You can find this on the instructioncard including with your ip adres.
I have only the following lines:
Hardware name:
Hardware Password:
Mac adres
Ip Nummer
SSID
But I don't have a client_id.
Is your hardware name not your ID? Maybe you can also find it on the back of your thermosmart.
Re: Control Thermosmart thermostat
Posted: Saturday 28 March 2015 13:13
by rron
kaashoek wrote:Using the public API of the Thermosmart thermostat I am now able to switch on/off the heating based on the alarm setting from a Visonic powerplus that controls a X10 switch to signal the state of the alarm and a mochad interface in Domoticz to monitor the X10 switch. (seems complicated)
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"
A similar scrip is created to start the heating using "pause":"false" as POST parameters
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
I linked the switch with the scripts by adding the script as (example)
Code: Select all
script://home/pi/thermosmart/pause.sh
The visonic powerplus can control X10 switches to I set it to switch on/off a switch whenever the alarm is switched on/off, after a first alarm switching domoticz has discovered the switch and I activated the switched and called it "Armed"
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
@ kaashoek,
Did you already succeed to import all yor settings into domoticz? I' m very curious to do that.
Re: Control Thermosmart thermostat
Posted: Sunday 12 April 2015 23:22
by pvm
Is it possible to override default program and set it to for example program 'not_home' ?
Re: Control Thermosmart thermostat
Posted: Tuesday 14 April 2015 10:50
by RichardBokker
i'm just starting with this shizzle, so how can i add the temperature from the thermostart into a graph?
Re: Control Thermosmart thermostat
Posted: Friday 17 April 2015 10:36
by kaashoek
Add a dummy device under setup/hardware and then add a virtual sensor of type temperature.
Goto the setup/devices and record the Idx number of the newly create temperature sensor.
Use this Idx number in the php file (see previous postings) that is being used to service the callback webhook from thermosmart
Re: Control Thermosmart thermostat
Posted: Friday 17 April 2015 10:44
by kaashoek
pvm wrote:Is it possible to override default program and set it to for example program 'not_home' ?
Yes, you can set everything through the thermosmart API, google for the thermosmart API doc
Re: Control Thermosmart thermostat
Posted: Friday 17 April 2015 10:54
by kaashoek
smika wrote:I find my hardware name and hardware password (SECRET=ssss and THERMOSTAT_ID=IT12345) on a sticker from Thermosmart. But where can i find my client ID?
You should apply for API access to thermostart. They will send you a client ID and a Secret.
Re: Control Thermosmart thermostat
Posted: Friday 17 April 2015 13:21
by kaashoek
When requesting API access you will have to provide the webhook (on one of your servers) Thermosmart will access at all updates so you can then get the data back into domoticz.
I added a small web server to the server running domoticz and let the webhook point to a page served by this small web server.
The page served can be found in one of the other posts
Re: Control Thermosmart thermostat
Posted: Monday 20 April 2015 11:30
by RichardBokker
The part of the webhook i can't understand...
I need to place that php somewhere and i need to do something with the webhook.
But how? The site of thermosmart is also saying something about webhook, but i dont get it.. lol.
Re: Control Thermosmart thermostat
Posted: Saturday 16 May 2015 16:18
by smika
I got an error when I try the webhook
/var/www/html/thermosmart# php events.php
PHP Warning: Invalid argument supplied for foreach() in /var/www/html/thermosmart/events.php on line 8
Script:
Code: Select all
<?php
$device = '164'; // set to the device ID of the dummy thermometer created in Domoticz
$json = file_get_contents('php://input');
$obj = json_decode($json);
foreach ($obj as $key => $value) {
if ($key == 'room_temperature') {
// file_put_contents( "/tmp/thermosmart.log", $value . "\n", FILE_APPEND );
$url = '127.0.0.1:8083/json.htm?type=command¶m=udevice&idx=' . $device . '&nvalue=0&svalue=' . $value;
// file_put_contents( "/tmp/thermosmart.log", $url. "\n", FILE_APPEND );
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
// file_put_contents( "/tmp/thermosmart.log", $output. "\n", FILE_APPEND );
}
}
Can someone tell what's going wrong?
Re: Control Thermosmart thermostat
Posted: Thursday 28 May 2015 13:27
by rron
RichardBokker wrote:i'm just starting with this shizzle, so how can i add the temperature from the thermostart into a graph?
Did you receive the api from thermosmart already? I' m still waiting on it.
Ronald
Re: Control Thermosmart thermostat
Posted: Wednesday 03 June 2015 13:18
by rron
rron wrote:RichardBokker wrote:i'm just starting with this shizzle, so how can i add the temperature from the thermostart into a graph?
Did you receive the api from thermosmart already? I' m still waiting on it.
Ronald
Still waiting for the api from thermosmart
Re: Control Thermosmart thermostat
Posted: Tuesday 09 June 2015 22:07
by rron
smika wrote:I got an error when I try the webhook
/var/www/html/thermosmart# php events.php
PHP Warning: Invalid argument supplied for foreach() in /var/www/html/thermosmart/events.php on line 8
Script:
Code: Select all
<?php
$device = '164'; // set to the device ID of the dummy thermometer created in Domoticz
$json = file_get_contents('php://input');
$obj = json_decode($json);
foreach ($obj as $key => $value) {
if ($key == 'room_temperature') {
// file_put_contents( "/tmp/thermosmart.log", $value . "\n", FILE_APPEND );
$url = '127.0.0.1:8083/json.htm?type=command¶m=udevice&idx=' . $device . '&nvalue=0&svalue=' . $value;
// file_put_contents( "/tmp/thermosmart.log", $url. "\n", FILE_APPEND );
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
// file_put_contents( "/tmp/thermosmart.log", $output. "\n", FILE_APPEND );
}
}
Can someone tell what's going wrong?
@smika,
Have you got it working allready? I have still aproblem with the webhook part.
Re: Control Thermosmart thermostat
Posted: Sunday 28 June 2015 18:23
by smika
Sorry, I haven't working. Hopefully the topic stater comes again on this forum and can help us.
Re: Control Thermosmart thermostat
Posted: Monday 29 June 2015 21:42
by rron
smika wrote:Sorry, I haven't working. Hopefully the topic stater comes again on this forum and can help us.
I hope so. The only part I have working is the pause script. I 'm still trying.