-
Notifications
You must be signed in to change notification settings - Fork 1
/
dev-console-fan.yaml
507 lines (441 loc) · 12.9 KB
/
dev-console-fan.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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
substitutions:
friendly_name: Console Fan
esphome:
name: console-fan-v2
# includes:
# - pid_simulator.h
# custom_component:
# - lambda: |-
# auto *my_component = new esphome::pid::PIDSimulator();
# App.register_component(my_component);
# return {my_component};
globals:
- id: dhttemp
type: float
restore_value: yes
initial_value: "0"
#########################
# ESP32 AND NETWORK SETUP
esp32:
board: nodemcu-32s
framework:
type: arduino
# pid climate log update is noisy, dial it back to warn
logger:
level: DEBUG
logs:
climate: ERROR
dht: WARN
# default HA integration, OTA updater and backup http web portal
api:
ota:
captive_portal:
wifi:
# Read the wifi/pass from secrets.yaml:
# wifi_ssid: "My Wifi XX"
# wifi_password: "XXXXXXX"
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "console-fan-ap"
password: ""
# on_press:
# then:
# - lambda: !lambda |-
# id(slider_helper).publish_state(false);
# id(slider1).update();
number:
## RECEIVE kp,ki and kd parameters from input_text.kx helpers in
# Home Assistant. See the PID controller below
# These helper values will get saved to flash thus permanently over-riding
# the initial values set in the PID below.
# KP
- platform: template
name: $friendly_name kp
icon: mdi:chart-bell-curve
optimistic: true
min_value: 0
max_value: 50
step: 0.001
set_action:
lambda: id(console_thermostat).set_kp( x );
# KI
- platform: template
name: $friendly_name ki
icon: mdi:chart-bell-curve
restore_value: true
min_value: 0
max_value: 50
step: 0.0001
set_action:
lambda: id(console_thermostat).set_ki( x );
# KD
- platform: template
name: $friendly_name kd
icon: mdi:chart-bell-curve
restore_value: true
min_value: -50
max_value: 50
step: 0.001
set_action:
lambda: id(console_thermostat).set_kd( x );
# Starting Integral Term
- platform: template
name: $friendly_name starting integral
icon: mdi:chart-bell-curve
restore_value: true
min_value: -100
max_value: 100
step: 0.1
set_action:
lambda: id(console_thermostat).set_starting_integral_term( -x/100 );
# output samples
- platform: template
name: $friendly_name output samples
icon: mdi:chart-bell-curve
restore_value: true
min_value: 1
max_value: 50
step: 1
set_action:
lambda: id(console_thermostat).set_output_samples( x );
# deadband_threshold
- platform: template
name: $friendly_name deadband threshold high
icon: mdi:chart-bell-curve
restore_value: true
min_value: 0
max_value: 50
step: 0.1
set_action:
lambda: id(console_thermostat).set_threshold_high( x );
- platform: template
name: $friendly_name deadband threshold low
icon: mdi:chart-bell-curve
restore_value: true
min_value: -50
max_value: 0
step: 0.1
set_action:
lambda: id(console_thermostat).set_threshold_low( x );
- platform: template
name: $friendly_name kp multiplier
icon: mdi:chart-bell-curve
restore_value: true
min_value: 0
max_value: .1
step: 0.001
set_action:
lambda: id(console_thermostat).set_kp_multiplier( x );
- platform: template
name: $friendly_name ki multiplier
icon: mdi:chart-bell-curve
restore_value: true
min_value: 0
max_value: .1
step: 0.001
set_action:
lambda: id(console_thermostat).set_ki_multiplier( x );
- platform: template
name: $friendly_name kd multiplier
icon: mdi:chart-bell-curve
restore_value: true
min_value: 0
max_value: .1
step: 0.001
set_action:
lambda: id(console_thermostat).set_kd_multiplier( x );
- platform: template
name: $friendly_name deadband output samples
icon: mdi:chart-bell-curve
restore_value: true
min_value: 0
max_value: 50
step: 1
set_action:
lambda: id(console_thermostat).set_deadband_output_samples( x );
text_sensor:
# Send IP Address
- platform: wifi_info
ip_address:
name: $friendly_name IP Address
# Send Uptime in raw seconds
- platform: template
name: $friendly_name Uptime
id: uptime_human
icon: mdi:clock-start
sensor:
# Send WiFi signal strength & uptime to HA
- platform: wifi_signal
name: $friendly_name WiFi Strength
update_interval: 60s
# This is a bit of overkill. It sends a human readable
# uptime string
# 1h 41m 32s instead of 6092 seconds
- platform: uptime
name: $friendly_name Uptime
id: uptime_sensor
update_interval: 60s
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
# Custom C++ code to generate the result
state: !lambda |-
int seconds = round(id(uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? to_string(days) + "d " : "") +
(hours ? to_string(hours) + "h " : "") +
(minutes ? to_string(minutes) + "m " : "") +
(to_string(seconds) + "s")
).c_str();
########################################################
# START THE FAN CONTROLLER SETUP
- platform: template
name: $friendly_name kp
id: kp
accuracy_decimals: 4
- platform: template
name: $friendly_name ki
id: ki
accuracy_decimals: 4
- platform: template
name: $friendly_name kd
id: kd
accuracy_decimals: 4
- platform: template
name: $friendly_name p term
id: p_term
unit_of_measurement: "%"
accuracy_decimals: 2
- platform: template
name: $friendly_name i term
id: i_term
unit_of_measurement: "%"
accuracy_decimals: 2
- platform: template
name: $friendly_name d term
id: d_term
unit_of_measurement: "%"
accuracy_decimals: 2
- platform: template
name: $friendly_name output value
unit_of_measurement: "%"
id: o_term
accuracy_decimals: 2
- platform: template
name: $friendly_name error value
id: e_term
accuracy_decimals: 2
- platform: template
name: $friendly_name is in deadband
id: in_deadband_term
accuracy_decimals: 0
- platform: template
name: $friendly_name zero
id: zero_value
update_interval: 60s
lambda: |-
return 0;
- platform: template
name: $friendly_name zero percent
unit_of_measurement: "%"
id: zero_value_percent
update_interval: 60s
lambda: |-
return 0;
# - platform: template
# name: $friendly_name deadband
# id: db_term
# accuracy_decimals: 2
# - platform: template
# name: $friendly_name derivative samples
# id: ds_term
# accuracy_decimals: 0
# - platform: template
# name: $friendly_name deadband multiplier
# id: pdm_term
# accuracy_decimals: 2
- platform: template
name: $friendly_name output samples
id: os_term
accuracy_decimals: 0
# deadband sensor outputs
- platform: template
name: $friendly_name deadband threshold low
id: tl_term
accuracy_decimals: 2
- platform: template
name: $friendly_name deadband threshold high
id: th_term
accuracy_decimals: 2
- platform: template
name: $friendly_name deadband kp multiplier
id: dkpm_term
accuracy_decimals: 2
- platform: template
name: $friendly_name deadband ki multiplier
id: dkim_term
accuracy_decimals: 2
- platform: template
name: $friendly_name deadband kd multiplier
id: dkdm_term
accuracy_decimals: 2
- platform: template
name: $friendly_name deadband output samples
id: dos_term
accuracy_decimals: 0
# GET TEMP/HUMIDITY FROM DHT11
- platform: dht
pin:
number: 33
mode:
input: true
pullup: true
temperature:
name: "Temperature"
id: console_fan_temperature
accuracy_decimals: 3
# If you don't smooth the output readings
# the PID controller over reacts to small changes.
filters:
# - sliding_window_moving_average:
# window_size: 6
# send_every: 1
# send_first_at: 1
- exponential_moving_average:
alpha: 0.1
send_every: 1
humidity:
name: "Humidity"
id: console_fan_humidity
# the DHT11 can only be read every 1s. Use 1.3s to be safe.
# Note that 15 x 1.3s means that the true temperature may
# take 19.5s to emerge
update_interval: 1.3s
# Take the "COOL" value of the pid and send
# it to the frontend to graph the output voltage
- platform: pid
name: "Fan Speed (PWM Voltage)"
climate_id: console_thermostat
type: COOL
output:
# Wire this pin (15) into the PWM pin of your 12v fan
# ledc is the name of the pwm output system on an esp32
- platform: ledc
id: console_fan_speed
pin: GPIO25
- platform: ledc
id: console_heat_speed
pin: GPIO27
# 25KHz is standard PC fan frequency, minimises buzzing
frequency: "25000 Hz"
# my fans stop working below 13% powerful.
# also they're powerful and loud, cap their max speed to 80%
min_power: 13%
max_power: 80%
# Good for debugging, you can manually set the fan speed.
fan:
- platform: speed
output: console_fan_speed
name: "Console Fan Speed"
# Expose a PID-controlled Thermostat
# Manual: https://esphome.io/components/climate/pid.html
climate:
- platform: pid
name: "Console Fan Thermostat"
id: console_thermostat
sensor: console_fan_temperature
# It is summer right now, so 30c is a decent target.
default_target_temperature: 30°C
cool_output: console_fan_speed
on_state:
- sensor.template.publish:
id: kp
state: !lambda "return id(console_thermostat).get_kp();"
- sensor.template.publish:
id: ki
state: !lambda "return id(console_thermostat).get_ki();"
- sensor.template.publish:
id: kd
state: !lambda "return id(console_thermostat).get_kd();"
- sensor.template.publish:
id: p_term
state: !lambda "return -id(console_thermostat).get_proportional_term() * 100.0;"
- sensor.template.publish:
id: i_term
state: !lambda "return -id(console_thermostat).get_integral_term()* 100.0;"
- sensor.template.publish:
id: d_term
state: !lambda "return -id(console_thermostat).get_derivative_term()* 100.0;"
- sensor.template.publish:
id: o_term
state: !lambda "return -id(console_thermostat).get_output_value()* 100.0;"
- sensor.template.publish:
id: e_term
state: !lambda "return -id(console_thermostat).get_error_value();"
- sensor.template.publish:
id: in_deadband_term
state: !lambda "return id(console_thermostat).in_deadband();"
- sensor.template.publish:
id: os_term
state: !lambda "return id(console_thermostat).get_output_samples();"
- sensor.template.publish:
id: tl_term
state: !lambda "return id(console_thermostat).get_threshold_low();"
- sensor.template.publish:
id: th_term
state: !lambda "return id(console_thermostat).get_threshold_high();"
- sensor.template.publish:
id: dkpm_term
state: !lambda "return id(console_thermostat).get_kp_multiplier();"
- sensor.template.publish:
id: dkim_term
state: !lambda "return id(console_thermostat).get_ki_multiplier();"
- sensor.template.publish:
id: dkdm_term
state: !lambda "return id(console_thermostat).get_kd_multiplier();"
- sensor.template.publish:
id: dos_term
state: !lambda "return id(console_thermostat).get_deadband_output_samples();"
# dummy heater. enable this if using autotune
heat_output: console_heat_speed
# The extents of the HA Thermostat
visual:
min_temperature: 20 °C
max_temperature: 50 °C
# See the README for setting up these parameters.
control_parameters:
kp: 0.3
ki: 0.0015
kd: 0
max_integral: 0.0
output_averaging_samples: 1
derivative_averaging_samples: 5
deadband_parameters:
threshold_high: 0.4°C
threshold_low: -1.0°C
kp_multiplier: 0.0
ki_multiplier: 0.04
kd_multiplier: 0.0
deadband_output_averaging_samples: 15
switch:
# Expose an ESP32 restart button to HA
- platform: restart
name: "Console Fan ESP32 Restart"
- platform: template
name: $friendly_name Reset Integral
turn_on_action:
- climate.pid.reset_integral_term: console_thermostat
button:
- platform: template
name: "PID Climate Autotune"
on_press:
- climate.pid.autotune: console_thermostat