Tado API JSON

Hello my friends,

i am using Tado. There is a json api. At this time i’m using the rest component to get my information but it is possible to use a post method and to merge sensor 1 & 2 to one sensor with multiple information ? Tado is also using a presence detection maybe someone could build a component for the tado thermostat? Thank you!

sensor:
  platform: rest
  resource: [my.tado.com/mobile/1.9/getCurre ... &password=](https://my.tado.com/mobile/1.9/getCurrentState?username=&password=)
  value_template: '{{ value_json.insideTemp}}'
  method: GET
  name: Heizung aktuelle Temperatur
  unit_of_measurement: "°C"

sensor 2:
  platform: rest
  resource: [my.tado.com/mobile/1.9/getCurre ... &password=](https://my.tado.com/mobile/1.9/getCurrentState?username=&password=)
  value_template: '{{ value_json.setPointTemp}}'
  method: GET
  name: Heizung Temperatur
  unit_of_measurement: "°C"
1 Like

The rest platforms usually support POST and GET. The template sensor can be used to display information for other sensors. But not the other way around.

Here https://home-assistant.io/getting-started/devices/#customizing-devices-and-services there’s an example where they put several MQTT sensors inside one, maybe you can apply it here as well.

i configured rest sensors that query the tado api v2. the mobile/1.9 api does not seem to support zones. this still doesn’t solve the problem of displaying the set and the actual temperatur together, put i lets home assistant gather all tado data from all zones — and lets me push and view them in grafana.

(replace HOME_ID, USERNAME and PASSWORD with your own values and query all avalailable zones.)

sensor:
- platform: rest
  resource: https://my.tado.com/api/v2/homes/HOME_ID/zones/1/state?username=USERNAME&password=PASSWORD
  value_template: '{{ value_json.sensorDataPoints.humidity.percentage }}'
  unit_of_measurement: °C
  name: 'tado zone 1 humidity'
- platform: rest
  resource: https://my.tado.com/api/v2/homes/HOME_ID/zones/1/state?username=USERNAME&password=PASSWORD
  value_template: '{{ value_json.sensorDataPoints.insideTemperature.celsius }}'
  unit_of_measurement: °C
  name: 'tado zone 1 temperature'
- platform: rest
  resource: https://my.tado.com/api/v2/homes/HOME_ID/zones/1/state?username=USERNAME&password=PASSWORD
  value_template: '{{ value_json.setting.temperature.celsius }}'
  unit_of_measurement: °C
  name: 'tado zone 1 set temperature'
- platform: rest
  resource: https://my.tado.com/api/v2/homes/HOME_ID/zones/1/state?username=USERNAME&password=PASSWORD
  value_template: '{{ value_json.activityDataPoints.heatingPower.percentage }}'
  unit_of_measurement: '%'
  name: 'tado zone 1 heating power'

i particularly like the heatingPower.percentage which lets me observe how the thermostats request heating power from the boiler.

btw., there is a way to also set the temperature manually, like stephen c phillips pointed out here. it actually works, if you send a PUT request to

https://my.tado.com/api/v2/homes/HOME/zones/1/overlay?username=USERNAME&password=PASSWORD 

with a payload like

{setting: {type: "HEATING", power: "ON", temperature: {celsius: 22}}, termination: {type: "MANUAL"}}

even if the tado api is not official or public yet, with this data it should actually be possible to build a custum component, possibly by fiddling with the generic thermostat component.

it seems that querying the tado api like described above might be problematic. after letting HA query the tado api every 30 seconds for a couple of hours, my tado devices disconnected. i could only reconnect by restarting the base, brodge and thermostat. instead of directly querying with

...?username=USERNAME&password=PASSWORD 

i wrapped the query with PyTado. PyTado uses oauth for authentication and does not seem to upset the API or my devices. my web app connection gets disconnected a couple of times a day — and i need to relogin — but that’s about it.

i ended up writing a little python code that queries the tado api with PyTado and gets executed every 2 minutes. the scripts cache the resulting json in a file, that i parse into HA with the command line sensor and a corrsponding cat command and value templates like described above.

Hi! Would you mind sharing that code please? Sounds like it might be exactly what I need (until someone has the time to create a proper component for Tado). Thanks :slight_smile:

first, i modified pytado (https://github.com/chrism0dwk/PyTado) a bit (added getDevices and let it dump the api json answers).

then i created a python files to get the device data and write them to a file:

for each tado zone, i created a python file to get and write the zone status data:

since my HA is running on a mac, i created some launch agents, to query the tado api every 2 minutes:

to get the data into HA, i created a couple of sensors:

sensor:
  platform: command_line
  command: '/bin/cat /Users/ix/.homeassistant/tado/state_1.json'
  value_template: '{{ value_json.sensorDataPoints.humidity.percentage }}'
  unit_of_measurement: '%'
  name: 'tado bathroom humidity'

sensor:
  platform: command_line
  command: '/bin/cat /Users/ix/.homeassistant/tado/state_1.json'
  value_template: '{{ value_json.sensorDataPoints.insideTemperature.celsius }}'
  unit_of_measurement: °C
  name: 'tado bathroom temperature'

sensor:
  platform: command_line
  command: '/bin/cat /Users/ix/.homeassistant/tado/state_1.json'
  value_template: '{{ value_json.setting.temperature.celsius }}'
  unit_of_measurement: °C
  name: 'tado bathroom set temperature'

sensor:
  platform: command_line
  command: '/bin/cat /Users/ix/.homeassistant/tado/state_1.json'
  value_template: '{{ value_json.activityDataPoints.heatingPower.percentage }}'
  unit_of_measurement: '%'
  name: 'tado zone 1 heating power'

i also created a sensor, to check if the devices are online (change the 0 according to your zone settings):

sensor:
  platform: command_line
  command: '/bin/cat /Users/ix/.homeassistant/tado/devices.json'
  value_template: >
    {% if value_json.0.connectionState.value == 1 %}
      online
    {% else %}
      offline
    {% endif %}
  name: Status tado bathroom

this works pretty well, except for the problem, that the tado bridge disconnects from time to time, which i suspect might have to do something, with checking the API through PyTado. instead of fixing this problem, i just restart the bridge (automatically through HA) if the API reports the device as offline.

of course it would be nice, to have this implemented as a component, but thats out of my reach. all the data is there, you can set the temperature through the api and get data for all zones. also it might be a good idea to wait a bit for an official API, but i’ve been using this setup for a couple of weeks now.

I created a custom component

i’m open for any constructive criticism

5 Likes

great! looks good and i tried to test it right away. however i couldn’t test it, because i’m still on HA version 0.31.1 and you’re using hass.data which was introduced a little later than 0.31.1. i’ll test it later on another, up to date HA server.


ok, tried to run it on HA 0.35.3 and got SSL handshake errors:

17-01-03 14:40:35 homeassistant.bootstrap: Error during setup of component tado_v1
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect
    server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 401, in wrap_socket
    _context=self, _session=session)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 808, in __init__
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1061, in do_handshake
    self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 683, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)

i tried to disable verifying certificates, but can’t change the PyTado-Dependency locally. curiously when i use PyTado with my own simple scripts, i do not get SSL errors.

(i also did a fresh install of python3 and HA. installing. an install of pip3 install certifi didn’t help either.)


according to the poster of this hint, it’s „highly discouraged“ to do this, but it works. i added this to the top of the tado_v1.py file:

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

I had the same problem on my mac (mac os sierra).

There semse to be a problem with python using the correct openssl version. I couldn’t fix this problem neither, but it did work on my raspberry pi with debian jessy.

It works great on Raspberry Pi HA 35.3. Thanks for your work and look forward to the updates :wink:

1 Like

Great! I will try to create a climate-device. When I figure out, how to change the temperature setting through the api :slight_smile:

edit:
hmm diplix posted the solution already! will try that for the next version!

2 Likes

i don’t know much about python programming, but i’m glad if i can assist, help out or test. i’ll also keep on watching the github-repo.

(oh, and i also got tado_v1 to run. works great and looks good.)

Thanks a lot! I was working on something similar and just by chance I found this.

Thanks for the custom component, it works great for the Smart Thermostat. I am also using a Smart Radiator Thermostat and the Climate function for that device isnt working correctly for me. It constantly shows 21 degrees for the schedule and doesnt show a current temperature.

The standalone temperature sensor works fine and shows correctly though.

Also what does the Overlay sensor relate to?

Sorry for asking a dump question, but in the source it is mentioned that https://github.com/wmalgadey/PyTado/archive/0.1.10.zip#PyTado==0.1.10’ is required. Do you have a hint how to install it? Thanks.

this is normaly installed by hass automatically.

Do you get an error message?

I do not own a radiator thermostat. I thought that tado hides the actual thermostats and just presents a zone! I am working on a hass release as an official component. Maybe try again with this component?

The Overlay sensor is just for information purpose. On my.tado.com the change to the temperature setting is done with an overlay type (manual, timer or “tado mode”).

1 Like

I have found the problem. diplix mentioned it already a few posts earlier - thanks:

according to the poster of this http://stackoverflow.com/questions/27835619/ssl-certificate-verify-failed-error, it’s „highly discouraged“ to do this, but it works. i added this to the top of the tado_v1.py file:

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

Is there a possibility to get also the presence information from the tado response?
Thx manmac