-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathheating_channel_PID.yaml
325 lines (295 loc) · 11.6 KB
/
heating_channel_PID.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
## see discussion https://github.com/nliaudat/floor-heating-controller/discussions/11
## and https://github.com/Karl-opec/floor-heating-controller/blob/main/climate.yaml
climate:
- platform: pid
name: ${frendly_name}
id: PID_CH${channel_number}
sensor: ${temperature_sensor}
default_target_temperature: ${default_target_temperature}
#target_temperature_command_topic: Hz/Hz.Bd.Th_Climate/desired-temp
heat_output: heater_ch${channel_number}
control_parameters:
kp: ${pid_kp}
ki: ${pid_ki}
kd: ${pid_kd}
min_integral: 0.003
max_integral: 0.997
starting_integral_term: 0.1 # set for reboot 12%
output_averaging_samples: 2 # smooth the output over 5 samples
derivative_averaging_samples: 5 # smooth the derivative value over 10 samples
visual:
min_temperature: ${visual_min_temperature}
max_temperature: ${visual_max_temperature}
temperature_step: ${visual_temperature_step}
# web_server:
# sorting_group_id: sorting_group_climate
output:
- platform: template
id: heater_ch${channel_number}
type: float
min_power: 0.001
max_power: 0.998
write_action:
- cover.control:
id: CH${channel_number}_cover
position: !lambda |-
if (abs(id(CH${channel_number}_cover).position - state) >= id(${id_prefix}min_movement).state/100) { return state; }
else if (abs(id(CH${channel_number}_cover).position) >= id(${id_prefix}min_movement).state/100 ) {return id(CH${channel_number}_cover).position;}
else {
auto call = id(CH${channel_number}_cover).make_call();
call.set_command_close();
call.perform();
return (0.000);
}
- logger.log:
format: "heater CH${channel_number} Target pos: %.3f Actual pos: %.3f"
args: [ 'state','id(CH${channel_number}_cover).position' ]
########### cover
cover:
- platform: endstop
name: CH${channel_number}
device_class: shutter
open_action:
- switch.turn_on: CH${channel_number}_IA_pin
- switch.turn_off: CH${channel_number}_IB_pin
open_duration: 60s
open_endstop: BEMF_${channel_number}_sensor
close_action:
- switch.turn_on: CH${channel_number}_IB_pin
- switch.turn_off: CH${channel_number}_IA_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
# web_server:
# sorting_group_id: sorting_group_covers
number:
- platform: template
name: "bemf_trigger_${channel_number}"
optimistic: true
min_value: 0.005
max_value: 1.50
step: 0.005
restore_value: true
initial_value: ${bemf_trigger_initial_value}
id: bemf_trigger_${channel_number}
# web_server:
# sorting_group_id: sorting_group_inputs
- platform: template
name: "Kp_ch${channel_number}"
id: kp_${channel_number}
min_value: 0.010
max_value: 1.000
step: 0.01
initial_value: ${pid_kp}
optimistic: true
entity_category: config
restore_value: true
on_value:
then:
- climate.pid.set_control_parameters:
id: PID_CH${channel_number}
kp: !lambda "return x;"
ki: !lambda "return id(PID_CH${channel_number}).get_ki();"
kd: !lambda "return id(PID_CH${channel_number}).get_kd();"
icon: mdi:chart-line-variant
- platform: template
name: "Ki_ch${channel_number}"
id: ki_${channel_number}
min_value: 0.00005
max_value: 0.004
step: 0.00005
initial_value: ${pid_ki}
optimistic: true
entity_category: config
restore_value: true
on_value:
then:
- climate.pid.set_control_parameters:
id: PID_CH${channel_number}
kp: !lambda "return id(PID_CH${channel_number}).get_kp();"
ki: !lambda "return x;"
kd: !lambda "return id(PID_CH${channel_number}).get_kd();"
icon: mdi:math-integral-box
- platform: template
name: "Kd-ch${channel_number}"
min_value: 0.01
max_value: 10.00
step: 0.01
id: kd_${channel_number}
initial_value: ${pid_kd}
optimistic: true
entity_category: config
restore_value: true
on_value:
then:
- climate.pid.set_control_parameters:
id: PID_CH${channel_number}
kp: !lambda "return id(PID_CH${channel_number}).get_kp();"
ki: !lambda "return id(PID_CH${channel_number}).get_ki();"
kd: !lambda "return x;"
icon: mdi:delta
script:
- id: calibrate_CH${channel_number}_cover
then:
- logger.log:
format: "Calibrate CH${channel_number}"
tag: heat_ctrl_main
- 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 (abs(id(CH${channel_number}_cover).position < id(${id_prefix}min_movement).state/100 )) {
# {auto call = id(CH${channel_number}_cover).make_call();
# call.set_position(id(${id_prefix}min_movement).state/100 + 0.01);
# call.perform();
# ESP_LOGD("main", "Adjustment done for CH${channel_number} set to position close %3f", id(CH${channel_number}_cover).position);}
# {auto call = id(CH${channel_number}_cover).make_call();
# call.set_command_close();
# call.perform();
# ESP_LOGD("main", "Adjustment done for CH${channel_number} set to position close");}
# };
### 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();
id(CH${channel_number}_cover).position = 1.0; //1.0 = 100% = OPEN
id(CH${channel_number}_cover).publish_state();
id(${id_prefix}bemf_logs).publish_state("CH${channel_number} opening endstop reached at " + to_string(id(${bemf_sensor_adc}).state) + " V");
ESP_LOGD("heat_ctrl_bemf", "CH${channel_number} opening endstop reached at %f V", id(${bemf_sensor_adc}).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();
id(CH${channel_number}_cover).position = 0.0; //0.0 = 0% = CLOSED
id(CH${channel_number}_cover).publish_state();
id(${id_prefix}bemf_logs).publish_state("CH${channel_number} closing endstop reached at " + to_string(id(${bemf_sensor_adc}).state) + " V");
ESP_LOGD("heat_ctrl_bemf", "CH${channel_number} closing endstop reached at %f V", id(${bemf_sensor_adc}).state);
}
internal: true
# web_server:
# sorting_group_id: sorting_group_BEMF
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
# web_server:
# sorting_group_id: sorting_group_actions
# - 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
button:
- platform: template
name: "PID ${frendly_name} Autotune"
on_press:
- climate.pid.set_control_parameters:
id: PID_CH${channel_number}
kp: 0.0
ki: 0.0
kd: 0.0
- climate.pid.autotune: PID_CH${channel_number}
# web_server:
# sorting_group_id: sorting_group_actions
###https://esphome.io/components/climate/pid.html?highlight=pid#pid-sensor
sensor:
- platform: pid
name: "PID ${frendly_name} RESULT"
id: PID_CH${channel_number}_result
type: RESULT
# web_server:
# sorting_group_id: sorting_group_sensors
- platform: pid
name: "PID ${frendly_name} KP"
id: PID_CH${channel_number}_kp
type: KP
# web_server:
# sorting_group_id: sorting_group_sensors
- platform: pid
name: "PID ${frendly_name} KI"
id: PID_CH${channel_number}_ki
type: KI
# web_server:
# sorting_group_id: sorting_group_sensors
- platform: pid
name: "PID ${frendly_name} KD"
id: PID_CH${channel_number}_kd
type: KD
# web_server:
# sorting_group_id: sorting_group_sensors
# 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