-
Notifications
You must be signed in to change notification settings - Fork 5
/
blueprint.yaml
91 lines (87 loc) · 4.58 KB
/
blueprint.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
blueprint:
name: Tado temperature offset beta
description: Ensure the Tado smart valve has the temp of a separate sensor
domain: automation
input:
source_temp_sensor:
name: Source Temperature sensor
description: This sensor will be used as the source.
selector:
entity:
domain: sensor
device_class: temperature
target_tado:
name: Tado
description: The Tado to set the offset on.
selector:
entity:
domain: climate
variables:
tolerance: 1
target_tado: !input target_tado
source_temp_sensor: !input source_temp_sensor
#early_start: ("binary_sensor." ~ target_tado ~ "_early_start")|regex_replace("climate.", ignorecase=True)
tado_temp: "{{ state_attr(target_tado, 'current_temperature') | float }}" # Temp tado thinks it's at
current_offset: "{{ state_attr(target_tado, 'offset_celsius') }}" # Tado sensors offset
tado_real_temp: "{{ ( tado_temp - current_offset) | float }}" # The temperature measured at the tado sensor
actual_temp: "{{ states(source_temp_sensor) | float }}" # Temperature measured by the other sensor
offset: "{{ ( actual_temp - tado_temp ) | round }}" # Difference between the two sensors, as they are currently calibrated
calculated_offset: "{{ (offset + current_offset ) | round }}" # The offset needed on the tado sensor to best equilibrate the two sensor measurements
#raw_calculated_offset: "{{ (offset + current_offset ) | round }}" # The offset needed on the tado sensor to best equilibrate the two sensor measurements
#calculated_offset: "{% if (tado_real_temp - actual_temp) | float > 1 %}{{raw_calculated_offset * 2}}{% else %}{{raw_calculated_offset}}{% endif %}" # If the the tado sensor temperature is alot higher than the other sensor, the double the offset, this causes the tado to aim to overshoot the temperature and reduces the chance of it going on and off many times
last_updated: "{{ state_attr(source_temp_sensor, 'offset_last_changed') if state_attr(source_temp_sensor, 'offset_last_changed') != None else utcnow() - timedelta(seconds=(900|int +100)) }}"
trigger:
- platform: state
entity_id: !input target_tado
attribute: current_temperature
- platform: state
entity_id: !input source_temp_sensor
# Because I have a condition to only adjust offset when in home mode, I also want to trigger when I get home to immediately sync temp
- platform: state
entity_id: !input target_tado
attribute: preset_mode
to: home
- platform: state
entity_id: !input target_tado
attribute: hvac_action
- platform: template
value_template: "{{ offset >= 1 }}"
condition:
# Only run if temp states are a number i.e. hasn't become 'unavailable'
- "{{ tado_temp|int != 0 or tado_temp == '0' }}"
- "{{ actual_temp|int != 0 or actual_temp == '0' }}"
# Only run if the climate device is preset is 'home' or if 'early start' has been activated or offset is more than a difference of 2
- "{{ state_attr(target_tado, 'preset_mode') == 'home' or states(early_start) == 'on' or offset|float >= 2 or offset|float <= -2}}"
# Only run if new offset is different to current offset
- "{{ offset != 0 }}"
# Only run if there is a difference in temperature greater than the tolerance
- "{{ (actual_temp - tado_temp)|abs > tolerance }}"
# Only run if offset hasn't been changed for longer than 15 minutes
- "{{ ( as_timestamp(now()) - as_timestamp(state_attr('this', 'last_triggered')) |int(0) ) > 900 }}"
# Only change the offset if it is going to make a difference to hvac action (so will send above or below target temp based on current hvac action state)
- "{{ (state_attr(target_tado, 'hvac_action') == 'heating' and (tado_temp + calculated_offset) >= state_attr(target_tado, 'temperature')|float) or ((state_attr(target_tado, 'hvac_action') == 'idle' and (tado_temp + calculated_offset) <= state_attr(target_tado, 'temperature')|float))}}"
action:
- service: system_log.write
data:
message: >
{{ target_tado }} has temp difference of {{ offset }}. Setting offset to {{ calculated_offset }}
level: info
logger: blueprints.tado.offset
- service: system_log.write
data:
message: >
target: {{ target_tado }}
source: {{ source_temp_sensor }}
temp difference: {{ offset }}
actual_temp: {{ actual_temp }}
tado_temp: {{ tado_temp }}
current_offset: {{ current_offset }}
calculated_offset: {{ calculated_offset }}
heating_state : {{ state_attr(target_tado, 'hvac_action') }}
level: debug
logger: blueprints.tado.offset
- service: tado.set_climate_temperature_offset
data:
offset: "{{ calculated_offset }}"
entity_id: "{{ target_tado }}"
mode: single