[677] Tado thermostat

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.
rjblake
Posts: 119
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: [677] Tado thermostat

Post by rjblake » Saturday 25 March 2017 15:48

I run this script on startup of my Synology using the following bash script:

#!/bin/bash
php70 -f tado.php > /dev/null &

the PHP script has a 'while true' loop, so it runs indefinitely (unless there is a problem - haven't added any code to deal with this yet) and a variable declared in the start of the script

$sleep_time = "60";

means that it 'sleeps' for 60 seconds each time (i.e. runs once a minute). There is little/no point running more frequently, as Tado does not update more frequently, unless there is a >2% change

symen89
Posts: 2
Joined: Saturday 05 November 2016 13:39
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: [677] Tado thermostat

Post by symen89 » Sunday 16 April 2017 16:02

Does anyone has a Lua script to control my tado thermostat from domoticz?
I tried to use the script of https://github.com/WebSpider/tado_domoticz but when paste that script in domoticz, nothing happens.

barbaar
Posts: 44
Joined: Wednesday 24 December 2014 17:01
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: [677] Tado thermostat

Post by barbaar » Monday 17 April 2017 22:47

If you would have taken the effort to actually read this thread, you would have known that Tado has changed their API causing the LUA you use no longer to work. ;)

eXisTa
Posts: 11
Joined: Wednesday 20 May 2015 23:26
Target OS: Raspberry Pi
Domoticz version: V3.7392
Location: Netherlands
Contact:

Re: [677] Tado thermostat

Post by eXisTa » Sunday 23 April 2017 20:40

rjblake wrote:I run this script on startup of my Synology using the following bash script:

#!/bin/bash
php70 -f tado.php > /dev/null &

the PHP script has a 'while true' loop, so it runs indefinitely (unless there is a problem - haven't added any code to deal with this yet) and a variable declared in the start of the script

$sleep_time = "60";

means that it 'sleeps' for 60 seconds each time (i.e. runs once a minute). There is little/no point running more frequently, as Tado does not update more frequently, unless there is a >2% change
Thank you very much for sharing the script. Works like a charm for me.
It would be nice to have this added to Domoticz as a built-in hardware.

rjblake
Posts: 119
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: [677] Tado thermostat

Post by rjblake » Tuesday 25 April 2017 14:15

eXisTa wrote:Thank you very much for sharing the script. Works like a charm for me.
It would be nice to have this added to Domoticz as a built-in hardware.
I was hoping to have a look at doing this, but have just not had the time lately due to work and other commitments. Might only be able to start on it in a few months, if lucky

timop
Posts: 25
Joined: Sunday 03 January 2016 18:10
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: [677] Tado thermostat

Post by timop » Wednesday 21 June 2017 15:48

tado.php doesnt work anymore, I think they changed again someting in tado...

rjblake
Posts: 119
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: [677] Tado thermostat

Post by rjblake » Wednesday 21 June 2017 22:16

Tado changed the API and unfortunately since it is not published, was not known. They've introduced 'client_secret' requirement, so the code has been modified (I think the client_secret is the same for all users and linked to the app/client). The code on GitHub has been updated and is working again.

jelmerk
Posts: 3
Joined: Wednesday 19 July 2017 12:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: [677] Tado thermostat

Post by jelmerk » Wednesday 19 July 2017 13:48

rjblake wrote:Tado changed the API and unfortunately since it is not published, was not known. They've introduced 'client_secret' requirement, so the code has been modified (I think the client_secret is the same for all users and linked to the app/client). The code on GitHub has been updated and is working again.
Hi, thanks for building the new script! I'm trying to get it to work on my RPi, and I'm encountering these errors. Any pointers?

Code: Select all

Token Age: 21 | Used cached token | PHP Notice:  Undefined index: homes in /home/pi/domoticz/scripts/tado.php on line 129
PHP Notice:  Undefined index: type in /home/pi/domoticz/scripts/tado.php on line 455
PHP Notice:  Undefined offset: 0 in /home/pi/domoticz/scripts/tado.php on line 297
PHP Notice:  Undefined index: setting in /home/pi/domoticz/scripts/tado.php on line 317
PHP Notice:  Undefined index: sensorDataPoints in /home/pi/domoticz/scripts/tado.php on line 318
PHP Notice:  Undefined index: sensorDataPoints in /home/pi/domoticz/scripts/tado.php on line 319
PHP Notice:  Undefined index: sensorDataPoints in /home/pi/domoticz/scripts/tado.php on line 320
HomeID:  - ZoneID:  - Temp&Humidity: ;;2 - Setpoint: 

rjblake
Posts: 119
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: [677] Tado thermostat

Post by rjblake » Wednesday 19 July 2017 16:46

Yup - Tado went and changed the API again!! :evil: Will try check later tonight to see if I can find a fix

rjblake
Posts: 119
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: [677] Tado thermostat

Post by rjblake » Wednesday 19 July 2017 21:30

I've updated the code. Should work now. They changed the 'client_id' and 'client_secret' in what looks like a step closer to releasing a public API. Hope they do as these break/fix solutions aren't much help

jelmerk
Posts: 3
Joined: Wednesday 19 July 2017 12:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: [677] Tado thermostat

Post by jelmerk » Wednesday 19 July 2017 21:35

Wow you are quick, thanks! It makes clear that the Tado change and my "mess" was a coincidence: I still get these results from running the php file:

Code: Select all

Token Age: 2 | Used cached token | PHP Notice:  Undefined index: homes in /home/pi/domoticz/scripts/tado.php on line 134
PHP Notice:  Undefined index: type in /home/pi/domoticz/scripts/tado.php on line 460
PHP Notice:  Undefined offset: 0 in /home/pi/domoticz/scripts/tado.php on line 302
PHP Notice:  Undefined index: setting in /home/pi/domoticz/scripts/tado.php on line 322
PHP Notice:  Undefined index: sensorDataPoints in /home/pi/domoticz/scripts/tado.php on line 323
PHP Notice:  Undefined index: sensorDataPoints in /home/pi/domoticz/scripts/tado.php on line 324
PHP Notice:  Undefined index: sensorDataPoints in /home/pi/domoticz/scripts/tado.php on line 325
HomeID:  - ZoneID:  - Temp&Humidity: ;;2 - Setpoint: 
Since I installed this on a "fresh" Pi3, I had to install PHP/curl etc. Maybe I messed up there. Anyhow, I'm not able to troubleshoot any further. Tho you mentioned that this is just a "quick fix" script, I appreciate any help!

rjblake
Posts: 119
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: [677] Tado thermostat

Post by rjblake » Thursday 20 July 2017 11:39

Can you attached the PHP file you are using? The line numbers where the errors are appearing do not match up to my script, so not sure what else you've changed. Also, I am running this using PHP 7.0; but can't recall if I used any specific v7.0 functions offhand (have run it with php v5.6.11 and it runs). It looks like the token file may have not have been created/written. Check if there is a file in your /tmp/ directory. The file/location is specified in the script ($token_file = "/tmp/tadotoken";). The 'user' that is running the script will need read/write permissions here.

Additionally, you'll need the JSON modules/extension installed if they are not as this will definitely cause an issue (check to see modules installed with "php -m" or "php70 -m").

jelmerk
Posts: 3
Joined: Wednesday 19 July 2017 12:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: [677] Tado thermostat

Post by jelmerk » Thursday 20 July 2017 18:27

First problem is that I screwed up copying the code from GitHub, that's corrected now. I'll check for the JSON library, thanks!
At least I'm getting the actual temp now, great :)

rjblake
Posts: 119
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: [677] Tado thermostat

Post by rjblake » Friday 21 July 2017 10:01

jelmerk wrote:First problem is that I screwed up copying the code from GitHub, that's corrected now. I'll check for the JSON library, thanks!
At least I'm getting the actual temp now, great :)
That would certainly cause a problem... ;)

If you are getting the actual temperature, that's a good start. If so, all good with the JSON bits as these are required to extract the temp/humidity. As long as you update the Domoticz bits in the code, it should be updating the devices in Domoticz too :)

airmarshall
Posts: 15
Joined: Friday 04 August 2017 19:21
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: [677] Tado thermostat

Post by airmarshall » Wednesday 13 September 2017 1:55

Hi Guys, Hopefully you can help me. I wish to use the tado api to find out whether or not tado is current calling for heat and use this to toggle a virtual switch. The end goal is to make 2 set's of electric underfloor heating systems 'smart' by leveraging the power of tado geofencing and heating demand management.

So far I have identified the variable I require and added to the latest version of the script to parse this out as an 'On' or 'Off' variable. However I'm having trouble updating a virtual switch. I added a function to update a switch device but the domoticz switch itself doesn't update.

Below are all my modifications in case it helps someone, maybe @rjblake can incorporate them into his script once we have them working if others will find this useful?

Code: Select all

$tado_heatdemandIDX = "120"; // Your Domoticz DeviceID for the current Tado Heat Demand

$tado_heating_status = get_heating_status($token_file, $home_id, $zone_id);

$DOMO_update = update_switchdevice($tado_heatdemandIDX, $tado_heating_status, $DOMOIPAddress, $DOMOPort, $Username, $Password, $DOMOUpdate);

function get_heating_status($token_file, $home_id, $zone_id) // Gets Status (Heat Demand On/OFF) for ZoneID
{
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, "https://my.tado.com/api/v2/homes/$home_id/zones/$zone_id/state");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");

	$file = file_get_contents($token_file, true);
	$headers = array();
	$headers[] = "Authorization: Bearer $file";
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

	$parsed_json = json_decode(curl_exec($ch), true);
	$heatdemand = $parsed_json['activityDataPoints']['heatingPower']['percentage'];
	if ($heatdemand > 0)
		{$heatingstatus = 'On';}
	else
		{$heatingstatus = 'Off';}
	
	if (curl_errno($ch))
		{
		    echo 'Error:' . curl_error($ch);
		}
	curl_close ($ch);
	return $heatingstatus;	
}

function update_switchdevice($idx, $switchstate, $DOMOIPAddress, $DOMOPort, $Username, $Password, $DOMOUpdate) // Updates Domoticz Devices
{
	if ($DOMOUpdate == 1)
	{	
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_URL, "http://$Username:[email protected]$DOMOIPAddress:$DOMOPort/json.htm?type=command&param=switchlight&idx=$idx&switchcmd=$switchstate");
		curl_exec($ch);
		curl_close($ch);
	}
}
UPDATE 18-9-17

Not sure what I did but it works now. So the script queries tado api to find out whether or not there is currently a demand for heat and uses this to toggle a DOMO virtual switch. I plan to use that virtual switch to trigger sonoff relays. I've also added a check within the script so that it only updates the switch if the demand has changed, rather than continually updating it, therefore I can use logic like - if switch is off and last update was > 10 mins etc etc etc

Danny94
Posts: 12
Joined: Monday 18 January 2016 19:14
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: [677] Tado thermostat

Post by Danny94 » Tuesday 19 September 2017 14:16

Would love to see tado supported in domoticz. IFTTT just turns it on/off...
3x Hue Lux, 1x Hue Ambiance, 1x Hue rgbwstrip, 1x Hue Iris, 4x KiKa, KiKa doorbell
Raspberry Pi 3, RFXtrx433 USB

rjblake
Posts: 119
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: [677] Tado thermostat

Post by rjblake » Saturday 23 September 2017 16:05

airmarshall wrote:
Wednesday 13 September 2017 1:55
Hi Guys, Hopefully you can help me. I wish to use the tado api to find out whether or not tado is current calling for heat and use this to toggle a virtual switch. The end goal is to make 2 set's of electric underfloor heating systems 'smart' by leveraging the power of tado geofencing and heating demand management.

So far I have identified the variable I require and added to the latest version of the script to parse this out as an 'On' or 'Off' variable. However I'm having trouble updating a virtual switch. I added a function to update a switch device but the domoticz switch itself doesn't update.

Below are all my modifications in case it helps someone, maybe @rjblake can incorporate them into his script once we have them working if others will find this useful?

Code: Select all

$tado_heatdemandIDX = "120"; // Your Domoticz DeviceID for the current Tado Heat Demand

$tado_heating_status = get_heating_status($token_file, $home_id, $zone_id);

$DOMO_update = update_switchdevice($tado_heatdemandIDX, $tado_heating_status, $DOMOIPAddress, $DOMOPort, $Username, $Password, $DOMOUpdate);

function get_heating_status($token_file, $home_id, $zone_id) // Gets Status (Heat Demand On/OFF) for ZoneID
{
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, "https://my.tado.com/api/v2/homes/$home_id/zones/$zone_id/state");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");

	$file = file_get_contents($token_file, true);
	$headers = array();
	$headers[] = "Authorization: Bearer $file";
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

	$parsed_json = json_decode(curl_exec($ch), true);
	$heatdemand = $parsed_json['activityDataPoints']['heatingPower']['percentage'];
	if ($heatdemand > 0)
		{$heatingstatus = 'On';}
	else
		{$heatingstatus = 'Off';}
	
	if (curl_errno($ch))
		{
		    echo 'Error:' . curl_error($ch);
		}
	curl_close ($ch);
	return $heatingstatus;	
}

function update_switchdevice($idx, $switchstate, $DOMOIPAddress, $DOMOPort, $Username, $Password, $DOMOUpdate) // Updates Domoticz Devices
{
	if ($DOMOUpdate == 1)
	{	
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_URL, "http://$Username:[email protected]$DOMOIPAddress:$DOMOPort/json.htm?type=command&param=switchlight&idx=$idx&switchcmd=$switchstate");
		curl_exec($ch);
		curl_close($ch);
	}
}
UPDATE 18-9-17

Not sure what I did but it works now. So the script queries tado api to find out whether or not there is currently a demand for heat and uses this to toggle a DOMO virtual switch. I plan to use that virtual switch to trigger sonoff relays. I've also added a check within the script so that it only updates the switch if the demand has changed, rather than continually updating it, therefore I can use logic like - if switch is off and last update was > 10 mins etc etc etc
Nice stuff - I've just seen this post now (bit too damn busy lately). I'll add to the master code on GitHub so others can pick it up as well. Thanks

airmarshall
Posts: 15
Joined: Friday 04 August 2017 19:21
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: [677] Tado thermostat

Post by airmarshall » Wednesday 04 October 2017 22:19

Don't incorporate any changes yet as it's causing problems and I need to troubleshoot. Basically the script is doing what I wanted it to but every time it runs it causes the domoticz eventsystem and openZwave to restart == big problems!

I need to go back to the script as you supply it, test it as is to make sure the same problem doesn't occur, then re-build in my changes....

airmarshall
Posts: 15
Joined: Friday 04 August 2017 19:21
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: [677] Tado thermostat

Post by airmarshall » Thursday 05 October 2017 20:43

Ok, I am running the script 'as-is' from the git, and it's restarting the eventsystem and OZW everytime it does a JSON update. I've set the update wait to 180s, hence the 3 minute restart!

See http://www.domoticz.com/forum/viewtopic ... 94#p152622 for the log reports.

Can anyone else confirm they are also experiencing this?

Domoticz version: 3.8450 ... but it was also doing it with the latest stable as well.

Why would this be? Do I need to seek assitance in another part of the forum. rjblake, what do you think?

I have a presence detection script running on my router that updates a virtual switch in a very similar manner that doesn't cause this behaviour.


Troubleshooting has led me to believe it's actually a domoticz bug. If I disable the tado temp+humidity process from the script my heat demand switch works fine without crashing the database and causing restarts. More info on the bug here: viewtopic.php?f=6&t=19733

rjblake
Posts: 119
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: [677] Tado thermostat

Post by rjblake » Sunday 22 October 2017 15:02

Hi - been away a bit and just seen this. I have aded this to my script running on Synology (v3.8153) and do not see the problem occuring. Both my Temp+Humidity and Switch device are updating as expected. I will check my logs, but not aware of any crash. What I will change is the constant updating of the switch device each time even if no state change. Doesn't make sense to me to do this, as would rather only see logged changes to the state (i.e. from Off to On and vice versa).

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests