Page 2 of 3

Re: [677] Tado thermostat

Posted: Saturday 25 March 2017 14:48
by rjblake
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

Re: [677] Tado thermostat

Posted: Sunday 16 April 2017 16:02
by symen89
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.

Re: [677] Tado thermostat

Posted: Monday 17 April 2017 22:47
by barbaar
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. ;)

Re: [677] Tado thermostat

Posted: Sunday 23 April 2017 20:40
by eXisTa
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.

Re: [677] Tado thermostat

Posted: Tuesday 25 April 2017 14:15
by rjblake
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

Re: [677] Tado thermostat

Posted: Wednesday 21 June 2017 15:48
by timop
tado.php doesnt work anymore, I think they changed again someting in tado...

Re: [677] Tado thermostat

Posted: Wednesday 21 June 2017 22:16
by rjblake
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.

Re: [677] Tado thermostat

Posted: Wednesday 19 July 2017 13:48
by jelmerk
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: 

Re: [677] Tado thermostat

Posted: Wednesday 19 July 2017 16:46
by rjblake
Yup - Tado went and changed the API again!! :evil: Will try check later tonight to see if I can find a fix

Re: [677] Tado thermostat

Posted: Wednesday 19 July 2017 21:30
by rjblake
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

Re: [677] Tado thermostat

Posted: Wednesday 19 July 2017 21:35
by jelmerk
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!

Re: [677] Tado thermostat

Posted: Thursday 20 July 2017 11:39
by rjblake
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").

Re: [677] Tado thermostat

Posted: Thursday 20 July 2017 18:27
by jelmerk
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 :)

Re: [677] Tado thermostat

Posted: Friday 21 July 2017 10:01
by rjblake
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 :)

Re: [677] Tado thermostat

Posted: Wednesday 13 September 2017 1:55
by airmarshall
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:$Password@$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

Re: [677] Tado thermostat

Posted: Tuesday 19 September 2017 14:16
by Danny94
Would love to see tado supported in domoticz. IFTTT just turns it on/off...

Re: [677] Tado thermostat

Posted: Saturday 23 September 2017 16:05
by rjblake
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:$Password@$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

Re: [677] Tado thermostat

Posted: Wednesday 04 October 2017 22:19
by airmarshall
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....

Re: [677] Tado thermostat

Posted: Thursday 05 October 2017 20:43
by airmarshall
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

Re: [677] Tado thermostat

Posted: Sunday 22 October 2017 15:02
by rjblake
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).