# Smart heating in the morning

I like to share this project which aims to simulate the smart heating present in some thermostats, in my case a Tado v3+. The aim is to obtain a certain temperature at a certain time, starting the heating well in advance. As a first step, I estimated the heating capacity of my system, in °C / h. This estimate is empirical, and can be done by observing the delta temperature and time during heating, or by creating a derivative sensor with the thermostat’s temperature sensor. In my case the observed values vary from about 0.5 to 1.5 °C / h, depending on the external temperature. First, I created a sensor to correct this heating ratio as a function of the external temperature (value from a sonoff zigbee sensor placed outdoor ‘sensor.sonoff_a480003084_temperature’). I consequently assumed that this variation occurs between a minimum (I chose 0 °C) and a maximum external temperature of 12 °C, which is the temperature below which my heating system is programmed to start (morning heating starts if the minimum temperature expected for the next day is below 12 °C). I then created two numeric helpers whose values are respectively the minimum and maximum °C / h (called ‘input_number.tado_offset_slope’ and ‘input_number.tado_max_slope’ with starting values of 0.5 and 1.5 as mentioned above) allowing future adjustments.

So, I calculated the correct ratio in °C / h as follows:

``````adjust_slope_outside_temp_living_room:
value_template: >
``````

below is a sensor that calculates the delta temperature to be filled in order to reach the preset temperature, as the difference between the target temperature and the current temperature in the room:

``````delta_t_tado_thermostat:
value_template: >
``````

the value can, of course, be positive or negative. The next sensor calculates the necessary time in minutes, dividing the temperature delta by the ratio in ° C / h and then multiplying by 60:

``````time_heating_tado_thermostat:
value_template: >
``````

the next step was to establish the start time of the heating. A good way for me was to use the next alarm sensor provided in the companion app. Since there are three of us in the house, I wrote a template that returns the value with the alarm set before, and then subtracts the time (converted in seconds) calculated above:

``````    set_preheating_thermostat_tado_living_room:
value_template: >
{%- set alarm_list = [(as_timestamp(states('sensor.emma_next_alarm'))),   (as_timestamp(states('sensor.pixel_2_xl_next_alarm'))), (as_timestamp(states('sensor.mi_a2_next_alarm'))) ] -%}
{% if (states('sensor.pixel_2_xl_next_alarm'))== "unavailable" and (states('sensor.emma_next_alarm'))== "unavailable" and (states('sensor.mi_a2_next_alarm'))== "unavailable" -%}
"08:00"
{%- else %}
{{(min(alarm_list)|float(default=1)-(states('sensor.time_heating_tado_thermostat')|float(default=1)*60)) | timestamp_custom('%I:%M') }}
{%- endif %}
``````

The sensor output is like “6:01”. If any alarm is available may be sunday…The value was then used in an automation that set the start time in the morning:

``````alias: Set tado thermostat by alarm living room
description: ''
trigger:
- platform: state
for:
hours: 0
minutes: 0
seconds: 0
milliseconds: 0
condition:
- condition: template
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
- sat
after: '00:00'
before: '11:00'
action:
- service: input_datetime.set_datetime
data:
time: '{{ states(''sensor.set_preheating_thermostat_tado_living_room'') }}'
target:
entity_id:
mode: single

``````

Condition is that heating time is>0. Automation that contain input_datetime.tado_thermostat_start1 is (This automation also sets up a tado smart radiator other than the thermostat):

``````alias: Tado schedule thermostat ON1
description: ''
trigger:
- platform: state
- platform: template
value_template: >-
{{ states('sensor.time') >=
- platform: state
- platform: state
condition:
- condition: template
- condition: template
value_template: >-
{{ states('sensor.time') >=
- condition: template
value_template: >-
{{ states('sensor.time') <=
- condition: template
value_template: >-
- condition: time
after: '00:00'
weekday:
- mon
- tue
- wed
- thu
- fri
- sat
action:
- delay:
hours: 0
minutes: 0
seconds: 30
milliseconds: 0
- service: climate.turn_on
target:
entity_id:
- service: climate.set_temperature
target:
entity_id:
data:
temperature: >
{{
- service: climate.set_temperature
target:
data:
temperature: |