forked from nliaudat/floor-heating-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heating_channel.yaml
224 lines (204 loc) · 9.28 KB
/
heating_channel.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
########### Climate thermostat
climate:
- platform: thermostat
id: ${id}_thermostat
name: ${frendly_name}
sensor: ${temperature_sensor}
default_preset: ${default_preset}
on_boot_restore_from: memory
startup_delay: true
preset: #ECO, AWAY, BOOST, COMFORT, HOME, SLEEP, ACTIVITY
- name: ${preset_1_name}
default_target_temperature_low: ${preset_1_target_temperature_low}
default_target_temperature_high: ${preset_1_target_temperature_high}
mode: ${preset_1_mode} #OFF, AUTO, HEAT, COOL, HEAT_COOL, FAN_ONLY, DRY
- name: ${preset_2_name}
default_target_temperature_low: ${preset_2_target_temperature_low}
default_target_temperature_high: ${preset_2_target_temperature_high}
mode: ${preset_2_mode}
- name: ${preset_3_name}
default_target_temperature_low: ${preset_3_target_temperature_low}
default_target_temperature_high: ${preset_3_target_temperature_high}
mode: ${preset_3_mode}
min_cooling_off_time: 300s
min_cooling_run_time: 300s
min_heating_off_time: 300s
min_heating_run_time: 300s
min_idle_time: 30s
heat_action:
- lambda: 'return;' # do nothing cause action is triggered by time interval
cool_action:
- lambda: 'return;'
idle_action:
- lambda: 'return;'
visual:
min_temperature: ${visual_min_temperature}
max_temperature: ${visual_max_temperature}
temperature_step: ${visual_temperature_step}
########### cover
cover:
- platform: endstop
name: CH${channel_number}
device_class: shutter
open_action:
- switch.turn_on: CH${channel_number}_IB_pin
- switch.turn_off: CH${channel_number}_IA_pin
open_duration: 60s
open_endstop: BEMF_${channel_number}_sensor
close_action:
- switch.turn_on: CH${channel_number}_IA_pin
- switch.turn_off: CH${channel_number}_IB_pin
close_duration: 60s
close_endstop: BEMF_${channel_number}_sensor
stop_action:
- switch.turn_off: CH${channel_number}_IA_pin
- switch.turn_off: CH${channel_number}_IB_pin
max_duration : 65s
#assumed_state: true
id: CH${channel_number}_cover
number:
- platform: template
name: "bemf_trigger_${channel_number}"
optimistic: true
min_value: 0.005
max_value: 150.00
step: 0.005
restore_value: true
initial_value: ${bemf_trigger_initial_value}
id: bemf_trigger_${channel_number}
script:
- id: calibrate_CH${channel_number}_cover
then:
- logger.log: "Calibrate CH${channel_number}_cover"
- cover.close: CH${channel_number}_cover
- delay: 5s
- cover.open: CH${channel_number}_cover
- delay: 5s
- cover.close: CH${channel_number}_cover
- delay: 5s
- cover.open: CH${channel_number}_cover
- delay: 5s
- cover.close: CH${channel_number}_cover
- delay: 5s
- cover.open: CH${channel_number}_cover
- delay: 60s
- cover.close: CH${channel_number}_cover
- delay: 60s
- cover.close: CH${channel_number}_cover
- delay: 60s
- cover.close: CH${channel_number}_cover
- id: TH${channel_number}_check
then:
- lambda: |-
if (id(${id}_thermostat).mode == CLIMATE_MODE_OFF) {return;}
ESP_LOGD("main", "TH${channel_number}_check triggered");
// check if any others actuator is running. If yes, stop action and return.
if (id(CH${bemf_linked_with_channel}_cover).current_operation != COVER_OPERATION_IDLE) {
ESP_LOGD("main", "CH${bemf_linked_with_channel} running cause CH${channel_number} cancel operation");
return;
}
// get info from climate
//float current_temp = id(${id}_thermostat).current_temperature;
//float target_temp_low = id(${id}_thermostat).target_temperature_low;
//float target_temp_high = id(${id}_thermostat).target_temperature_high ;
//float diff_temp = (target_temp_high + target_temp_low)/2 - current_temp;
// get info from cover
//float current_position = id(CH${channel_number}_cover).position;
//arduino map function : return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; in_min=-1;in_max=1;out_min=0;out_max=1
//simplified => f(x) = (x+1)/2
//rounded at 0.1 => f(x) = round(((x+1)/2)/0.1)*0.1
//float target_position = round(((diff_temp+1)/2)/0.1)*0.1;
float target_position = round(((((id(${id}_thermostat).target_temperature_high + id(${id}_thermostat).target_temperature_low)/2 - id(${id}_thermostat).current_temperature)+1)/2)/0.1)*0.1;
//normalize
if (target_position >1) { target_position = 1;}
if (target_position <0) { target_position = 0;}
//call movement if target_position change consequently
if (abs(id(CH${channel_number}_cover).position - target_position) > id(min_movement).state/100) {
auto call = id(CH${channel_number}_cover).make_call();
call.set_position(target_position);
call.perform();
ESP_LOGD("main", "Adjustment done for CH${channel_number} set to position %f", target_position);
} else {
ESP_LOGD("main", "No adjustment done for CH${channel_number} cause min movement (%f) is not reached", id(min_movement).state);
}
### back electromotive force (back EMF)
### https://en.wikipedia.org/wiki/Counter-electromotive_force
binary_sensor:
- platform: template
id: BEMF_${channel_number}_sensor
name: "BEMF CH${channel_number} sensor"
lambda: return ((id(${bemf_sensor_adc}).state >= id(bemf_trigger_${channel_number}).state));
on_press:
then:
- lambda: |-
if (id(CH${channel_number}_cover).current_operation == COVER_OPERATION_OPENING) {
auto call = id(CH${channel_number}_cover).make_call();
call.set_command_stop();
call.perform();
ESP_LOGD("main", "CH${channel_number} opening endstop reached at %f V", id(${bemf_sensor_adc}).state);
//id(bemf_opening_${channel_number}).publish_state(id(${bemf_sensor_adc}).state *1000);
id(CH${channel_number}_cover).position = 1.0; //1.0 = 100% = OPEN
id(CH${channel_number}_cover).publish_state();
} else if (id(CH${channel_number}_cover).current_operation == COVER_OPERATION_CLOSING) {
auto call = id(CH${channel_number}_cover).make_call();
call.set_command_stop();
call.perform();
ESP_LOGD("main", "CH${channel_number} closing endstop reached at %f V", id(${bemf_sensor_adc}).state);
//id(bemf_closing_${channel_number}).publish_state(id(${bemf_sensor_adc}).state * 1000);
id(CH${channel_number}_cover).position = 0.0; //0.0 = 0% = CLOSED
id(CH${channel_number}_cover).publish_state();
}
switch:
- platform: gpio
name: "CH${channel_number} IA"
pin:
sn74hc595: sn74hc595_hub
number: ${sn74hc595_IA_pin}
inverted: False
internal: true
on_turn_on: #interlock do not support templating => replaced with switch.turn_off
- switch.turn_off: CH${channel_number}_IB_pin
- delay: 200ms #allow for switching time and any discharge
id: CH${channel_number}_IA_pin
#interlock: [CH${channel_number}_IA_pin, CH${channel_number}_IB_pin] #interlock: &interlock_group_CH1 [CH1_IA_pin, CH1_IB_pin]
restore_mode: always off
- platform: gpio
name: "CH${channel_number} IB"
pin:
sn74hc595: sn74hc595_hub
number: ${sn74hc595_IB_pin}
inverted: False
internal: true
on_turn_on:
- switch.turn_off: CH${channel_number}_IA_pin
- delay: 200ms #allow for switching time and any discharge
id: CH${channel_number}_IB_pin
#interlock: CH${channel_number}_IA_pin #interlock: *interlock_group_CH1
restore_mode: always off
- platform: template
name: "Run ${frendly_name} check"
turn_on_action:
- script.execute: TH${channel_number}_check
interval:
- interval: ${check_interval}
then:
- script.execute: TH${channel_number}_check
# sensor:
# - platform: template
# id: bemf_opening_${channel_number}
# name: bemf_opening_${channel_number}
# accuracy_decimals: 0
# update_interval: never
# unit_of_measurement: 'mV'
# device_class: voltage
# state_class: measurement
# #internal: true
# - platform: template
# id: bemf_closing_${channel_number}
# name: bemf_closing_${channel_number}
# accuracy_decimals: 0
# update_interval: never
# unit_of_measurement: 'mV'
# device_class: voltage
# state_class: measurement
# #internal: true