-
Notifications
You must be signed in to change notification settings - Fork 10
/
trv_calibrator.yaml
105 lines (94 loc) · 3.61 KB
/
trv_calibrator.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
blueprint:
name: TRV Calibrator
description: Calibrate your TRV using an external sensor
domain: automation
input:
trv:
name: Smart TRV
selector:
entity:
domain: climate
temperature_sensor:
name: Temperature Sensor
description: Sensor used to calibrate your TRV
selector:
entity:
domain: sensor
device_class: temperature
trv_calibration_number:
name: TRV Calibration Entity
description: If you can't find it it's possible that your TRV don't support calibration. Consider using the Better Thermostat custom integration instead.
selector:
entity:
domain: number
device_class: temperature
delay_in_minutes:
name: Delay in minutes
description: Your thermostat will take some time to update the current temperature after calibration. The delay should be higher than this time.
default: 1
selector:
number:
min: 1
max: 60
step: 1
mode: restart
variables:
trv: !input trv
trv_calibration_number: !input trv_calibration_number
temperature_sensor: !input temperature_sensor
trigger:
- platform: state
entity_id: !input trv
for:
hours: 0
minutes: 0
seconds: 0
- platform: state
entity_id: !input trv_calibration_number
for:
hours: 0
minutes: 0
seconds: 0
- platform: state
entity_id: !input temperature_sensor
for:
hours: 0
minutes: 0
seconds: 0
condition:
- condition: template
value_template: '{{ state_attr(trv, "current_temperature") != None }}'
- condition: template
value_template: '{{ states(trv_calibration_number) != "unavailable" and states(trv_calibration_number) != "unknown" }}'
- condition: template
value_template: '{{ states(temperature_sensor) != "unavailable" and states(temperature_sensor) != "unknown" }}'
action:
- delay:
hours: 0
minutes: !input delay_in_minutes
seconds: 0
milliseconds: 0
- service: number.set_value
target:
entity_id: !input trv_calibration_number
data:
value: >-
{% set room_temperature = states(temperature_sensor) | float %}
{% set trv_temperature = state_attr(trv, "current_temperature") | float(0) %}
{% set trv_calibration = states(trv_calibration_number) | float %}
{% set trv_calibration_min = state_attr(trv_calibration_number, "min") | float(-5) %}
{% set trv_calibration_max = state_attr(trv_calibration_number, "max") | float(5) %}
{% set trv_calibration_step = state_attr(trv_calibration_number, "step") | float(1) %}
{% set step = trv_calibration_step | string %}
{% if step.split(".") | length > 1 -%}
{% set trv_calibration_step_decimals = step.split(".")[1] | length %}
{%- else -%}
{% set trv_calibration_step_decimals = 0 %}
{%- endif %}
{% set new_trv_calibration = room_temperature - trv_temperature + trv_calibration %}
{% set new_trv_calibration_bounded = [ [ (new_trv_calibration - new_trv_calibration % trv_calibration_step) | round(trv_calibration_step_decimals), trv_calibration_min ] | max, trv_calibration_max ] | min %}
{% if new_trv_calibration_bounded < trv_calibration - trv_calibration_step or trv_calibration + trv_calibration_step < new_trv_calibration_bounded -%}
{{ new_trv_calibration_bounded }}
{%- else -%}
{{ states(trv_calibration_number) }}
{%- endif %}