Control Thermosmart thermostat

For heating/cooling related questions in Domoticz

Moderator: leecollings

kaashoek
Posts: 11
Joined: Saturday 20 September 2014 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Control Thermosmart thermostat

Post 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
kaashoek
Posts: 11
Joined: Saturday 20 September 2014 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Control Thermosmart thermostat

Post 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&param=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 );
    }
}

smika
Posts: 9
Joined: Sunday 13 April 2014 22:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Control Thermosmart thermostat

Post 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?
rron
Posts: 223
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: Control Thermosmart thermostat

Post 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.
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
smika
Posts: 9
Joined: Sunday 13 April 2014 22:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Control Thermosmart thermostat

Post 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.
rron
Posts: 223
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: Control Thermosmart thermostat

Post 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.
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
rron
Posts: 223
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: Control Thermosmart thermostat

Post 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.
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
pvm
Posts: 550
Joined: Tuesday 17 June 2014 22:14
Target OS: NAS (Synology & others)
Domoticz version: 4.10538
Location: NL
Contact:

Re: Control Thermosmart thermostat

Post by pvm »

Is it possible to override default program and set it to for example program 'not_home' ?
Synology NAS, slave PI3, ZWave (Fibaro), Xiaomi zigbee devices, BTLE plant sensor, DzVents, Dashticz on tablet, Logitech Media Server
RichardBokker
Posts: 39
Joined: Thursday 09 April 2015 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9317
Location: Netherlands
Contact:

Re: Control Thermosmart thermostat

Post by RichardBokker »

i'm just starting with this shizzle, so how can i add the temperature from the thermostart into a graph?
kaashoek
Posts: 11
Joined: Saturday 20 September 2014 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Control Thermosmart thermostat

Post 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
kaashoek
Posts: 11
Joined: Saturday 20 September 2014 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Control Thermosmart thermostat

Post 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
kaashoek
Posts: 11
Joined: Saturday 20 September 2014 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Control Thermosmart thermostat

Post 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.
kaashoek
Posts: 11
Joined: Saturday 20 September 2014 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Control Thermosmart thermostat

Post 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
RichardBokker
Posts: 39
Joined: Thursday 09 April 2015 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9317
Location: Netherlands
Contact:

Re: Control Thermosmart thermostat

Post 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.
smika
Posts: 9
Joined: Sunday 13 April 2014 22:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Control Thermosmart thermostat

Post 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&param=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?
rron
Posts: 223
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: Control Thermosmart thermostat

Post 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
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
rron
Posts: 223
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: Control Thermosmart thermostat

Post 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 :evil:
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
rron
Posts: 223
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: Control Thermosmart thermostat

Post 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&param=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. :?:
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
smika
Posts: 9
Joined: Sunday 13 April 2014 22:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Control Thermosmart thermostat

Post by smika »

Sorry, I haven't working. Hopefully the topic stater comes again on this forum and can help us.
rron
Posts: 223
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: Control Thermosmart thermostat

Post 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.
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests