-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathconsole-fan.yaml
395 lines (340 loc) · 10.5 KB
/
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
substitutions:
friendly_name: Console Fan
esphome:
name: console-fan
# Throttle writing parameters to the internal flash memory to reduce ESP memory wear / degradation
preferences:
flash_write_interval: 15min
#########################
# 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:
- platform: esphome
wifi:
# Read the wifi/pass from secrets.yaml:
# wifi_ssid: "My Wifi XX"
# wifi_password: "XXXXXXX"
ssid: !secret wifi_ssid
password: !secret wifi_password
number:
## OPTIONAL:
# 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: kp
icon: mdi:chart-bell-curve
restore_value: true
initial_value: 0.3
min_value: 0
max_value: 50
step: 0.001
optimistic: true
set_action:
lambda: |-
id(console_thermostat).set_kp( x );
# KI
- platform: template
name: ki
icon: mdi:chart-bell-curve
restore_value: true
initial_value: 0.0015
min_value: 0
max_value: 50
step: 0.0001
optimistic: true
set_action:
lambda: id(console_thermostat).set_ki( x );
# KD
- platform: template
name: kd
icon: mdi:chart-bell-curve
restore_value: true
initial_value: 0.0
min_value: -50
max_value: 50
step: 0.001
optimistic: true
set_action:
lambda: id(console_thermostat).set_kd( x );
# Set threshold low
- platform: template
name: Deadband Threshold Low
icon: mdi:chart-bell-curve
restore_value: true
initial_value: -1.0
min_value: -20
max_value: 0
step: 0.1
optimistic: true
set_action:
lambda: id(console_thermostat).set_threshold_low( x );
# Set threshold high
- platform: template
name: Deadband Threshold High
icon: mdi:chart-bell-curve
restore_value: true
initial_value: 0.4
min_value: 0
max_value: 20
step: 0.1
optimistic: true
set_action:
lambda: id(console_thermostat).set_threshold_high( x );
# Set ki multiplier
- platform: template
name: Deadband ki Multiplier
icon: mdi:chart-bell-curve
restore_value: true
initial_value: 0.04
min_value: 0
max_value: .2
step: 0.01
optimistic: true
set_action:
lambda: id(console_thermostat).set_ki_multiplier( 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();
# Read the Tacho PIN and show measured RPM as a sensor (only with 4-pin PWM fans!)
# See instructions here: https://esphome.io/components/sensor/pulse_counter.html
- platform: pulse_counter
pin:
number: GPIO25 # Connect to any input PIN on the ESP
mode: INPUT_PULLUP
unit_of_measurement: 'RPM'
id: fan_speed
name: $friendly_name Fan Speed 1
accuracy_decimals: 0
filters:
- multiply: 0.5 # Depending on how many pulses the fan sends per round - should be 0.5 or 1 - try...
- platform: pulse_counter
pin:
number: GPIO26 # Connect to any input PIN on the ESP
mode: INPUT_PULLUP
unit_of_measurement: 'RPM'
id: fan_speed_2
name: $friendly_name Fan Speed 2
accuracy_decimals: 0
filters:
- multiply: 0.5 # Depending on how many pulses the fan sends per round - should be 0.5 or 1 - try...
########################################################
# START THE FAN CONTROLLER SETUP
- 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
# GET TEMP/HUMIDITY FROM DHT11
- platform: dht
pin: GPIO33
temperature:
name: "Temperature"
id: console_fan_temperature
accuracy_decimals: 3
# If you don't smooth the temperature readings
# the PID controller over reacts to small changes.
filters:
- 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.
update_interval: 1.3s
# Every time the fan speed is updated, this sensor will
# also be updated for displaying on the frontend.
# See proxy_output.
- platform: template
name: "Fan Speed (PWM Voltage)"
unit_of_measurement: "%"
id: fan_speed_pwm_voltage
output:
# Wire this pin (13) 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: GPIO13
# 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%
# At 0, actually turn it off, otherwise the power keeps going.
zero_means_zero: true
# This proxy output takes its input
# if the manual fan control is on, use the level from that
# otherwise use the PID control value.
# Then publish the result to the fan (ledc) and
# also publish to the template output sensor
- platform: template
id: proxy_output
type: float
write_action:
lambda: |-
float write_val =
(id(manual_fan_control).state) ?
id(manual_fan_control).speed / 100.0 : state*1.0;
id(console_fan_speed).set_level(write_val);
id(fan_speed_pwm_voltage).publish_state(write_val*100.0);
# If you turn this on, you can manually set the fan speed.
# The PID will be ignored. This is done via the proxy_output.
fan:
- platform: speed
id: manual_fan_control
output: proxy_output
name: "Manual 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: proxy_output
# cool_output: console_fan_speed
# ON state change, publish the values to the x_term numbers defined
# above, so that they can be viewed in HA
on_state:
- 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: in_deadband_term
state: !lambda 'return id(console_thermostat).in_deadband();'
- sensor.template.publish:
id: e_term
state: !lambda 'return -id(console_thermostat).get_error_value();'
# The extents of the HA Thermostat
visual:
min_temperature: 20 °C
max_temperature: 50 °C
# See the README for setting up these parameters.
# These are over ridden by the number templates above.
control_parameters:
kp: 0.3
ki: 0.0015
kd: 0
max_integral: 0.0
output_averaging_samples: 1
derivative_averaging_samples: 5
# How to behave when close to the target temperature?
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: ${friendly_name} ESP32 Restart
id: console_fan_restart
# Restart every day at 12:30am.
# I've had some memory issues lockup
# the device after a couple weeks
time:
- platform: homeassistant
on_time:
# Every morning at 12:30am
- seconds: 0
minutes: 30
hours: 0
then:
- switch.turn_on: console_fan_restart
# I was able to find good KP,KI,KD values manually, per the instructions,
# but you can try pressing the autotune button from home assistant and copying the
# values it produces.
# See more at: https://esphome.io/components/climate/pid.html#climate-pid-autotune-action
button:
- platform: template
name: "PID Climate Autotune"
on_press:
- climate.pid.autotune: console_thermostat