-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathventilation-controller.yaml
323 lines (290 loc) · 9.17 KB
/
ventilation-controller.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
substitutions:
device_name: "Ventilation Controller ESP32"
device_name_short: "Ventilation ESP32"
espname: "ventilation-controller"
esphome:
name: "ventilation-controller"
comment: "ESP32 Devkit v1" #See https://www.aliexpress.com/snapshot/0.html?orderId=8129027763971973&productId=4000244398073
# Description:
# ESP32 Development Board ESP-32 ESP-32S WiFi Bluetooth Dual Cores CPU MCU Board IOT For LuaNode For NodeMcu ESP32S
esp32:
board: esp32doit-devkit-v1
packages:
wifi: !include /config/esphome/common/wifi.yaml
network_diagnostics: !include /config/esphome/common/network_diagnostics.yaml
base_config: !include /config/esphome/common/base_config.yaml
wifi:
ap:
ssid: ${device_name_short} Hotspot
output:
- platform: ledc
pin: 22
id: pwm_output
fan:
- platform: speed
output: pwm_output
speed_count: 100
name: "Ventilation System"
id: ventilationsystem
sensor:
# ADC sensors
- platform: adc
pin: 35
name: "Downstairs CO2 Input"
update_interval: 1s
filters:
- multiply: 16.93
- or:
- throttle_average: 60s
- delta: 0.5
- platform: adc
pin: 34
name: "Analog Output Voltage"
update_interval: 1s
filters:
- multiply: 16.16
- or:
- throttle_average: 60s
- delta: 0.5
- platform: adc
pin: 33
name: "Bathroom Button Signal"
update_interval: 1s
internal: true
filters:
- multiply: 16.93
- or:
- throttle_average: 60s
- delta: 0.5
- platform: adc
pin: 32
name: "12V Board Supply Voltage"
update_interval: 1s
filters:
- multiply: 16.93
- or:
- throttle_average: 60s
- delta: 0.5
# HA sensors
- platform: homeassistant
name: "Home Max Humidity"
entity_id: sensor.home_max_humidity
id: ha_home_max_humidity
device_class: "humidity"
- platform: homeassistant
name: "Home Mean Humidity"
entity_id: sensor.home_mean_humidity
id: ha_home_mean_humidity
device_class: "humidity"
- platform: homeassistant
name: "Home Mean Humidity Without Bathroom"
entity_id: sensor.home_mean_humidity_without_bathroom
id: ha_home_mean_humidity_without_bathroom
device_class: "humidity"
- platform: homeassistant
name: "Home Median Humidity"
entity_id: sensor.home_median_humidity
id: ha_home_median_humidity
device_class: "humidity"
- platform: homeassistant
name: "Home Max CO2"
entity_id: sensor.home_max_co2
id: ha_home_max_co2
device_class: "carbon_dioxide"
- platform: homeassistant
name: "Home Mean CO2"
entity_id: sensor.home_mean_co2
id: ha_home_mean_co2
device_class: "carbon_dioxide"
- platform: homeassistant
name: "Home Median CO2"
entity_id: sensor.home_median_co2
id: ha_home_median_co2
device_class: "carbon_dioxide"
- platform: homeassistant
name: "Bathroom Humidity"
entity_id: sensor.humidity_bathroom
id: ha_humidity_bathroom
device_class: "humidity"
- platform: homeassistant
name: "Bathroom Humidity Min"
entity_id: sensor.humidity_bathroom_min
id: ha_humidity_bathroom_min
device_class: "humidity"
- platform: homeassistant
name: "Bathroom Humidity Max"
entity_id: sensor.humidity_bathroom_max
id: ha_humidity_bathroom_max
device_class: "humidity"
- platform: homeassistant
name: "Bedroom CO2 Concentration"
entity_id: sensor.bedroom_co2
device_class: "carbon_dioxide"
id: ha_co2_bedroom
- platform: homeassistant
name: "Bedroom CO2 Concentration Min"
entity_id: sensor.co2_value_bedroom_min
device_class: "carbon_dioxide"
id: ha_co2_bedroom_min
- platform: homeassistant
name: "Study CO2 Concentration"
entity_id: sensor.study_co2
device_class: "carbon_dioxide"
id: ha_co2_study
- platform: homeassistant
name: "Livingroom CO2 Concentration"
entity_id: sensor.living_room_co2
device_class: "carbon_dioxide"
id: ha_co2_livingroom
# Template sensors:
- platform: template
name: "Ventilation Setting Bathroom Humidity"
id: fan_setting_bathroom_humidity
update_interval: 10s
accuracy_decimals: 0
unit_of_measurement: "%"
lambda: |-
// Get the current and minimum humidity values
float current_humidity = id(ha_humidity_bathroom).state;
float min_humidity = id(ha_humidity_bathroom_min).state;
// Calculate the difference between the current humidity and the minimum humidity
float humidity_diff = current_humidity - min_humidity;
// Calculate the fan setting based on the difference
float fan_setting = 0.0;
if (humidity_diff >= 0.0) {
fan_setting = humidity_diff / (100.0 - min_humidity) * 100.0;
}
// Set the fan setting to the nearest speed value
float rounded_fan_setting = round(fan_setting);
// Return the fan setting
return rounded_fan_setting;
- platform: template
name: "Ventilation Setting Humidity"
id: fan_setting_humidity
update_interval: 10s
accuracy_decimals: 0
unit_of_measurement: "%"
lambda: |-
// Get the current and minimum humidity values
float median_humidity = id(ha_home_median_humidity).state;
float max_humidity = id(ha_home_max_humidity).state;
// Calculate the difference between the current humidity and the minimum humidity
float humidity_diff = max_humidity - median_humidity;
// Calculate the fan setting based on the difference
float fan_setting = 0.0;
if (humidity_diff >= 0.0) {
fan_setting = humidity_diff / (100.0 - median_humidity) * 100.0;
}
// Set the fan setting to the nearest speed value
float rounded_fan_setting = round(fan_setting);
// Return the fan setting
return rounded_fan_setting;
- platform: template
name: "Ventilation Setting CO2"
id: fan_setting_co2
update_interval: 10s
accuracy_decimals: 0
unit_of_measurement: "%"
lambda: |-
// Get the current and minimum humidity values
float max_co2_concentration = id(ha_home_max_co2).state;
float median_co2_concentration = id(ha_home_median_co2).state;
// Fan sensitivity in % per PPM
float fan_sensitivity = id(number_co2_fan_sensitivity).state;
// Offset CO2 value
float co2_offset = id(number_co2_offset).state;
// Calculate the fan setting based on the difference
float fan_setting = 0.0;
float fan_setting_max_CO2 = (max_co2_concentration - co2_offset) * fan_sensitivity;
float fan_setting_median_CO2 = (median_co2_concentration - co2_offset) * (fan_sensitivity * 2);
fan_setting = max(fan_setting_max_CO2, fan_setting_median_CO2);
// Set the fan setting to the nearest speed value
float rounded_fan_setting = round(fan_setting);
if (rounded_fan_setting > 100) {
// If it is, return the limit value
return 100;
} else {
// Otherwise, return the current value
return rounded_fan_setting;
}
- platform: template
name: "Fan Speed Setting"
id: fan_speed_setting
lambda: |-
// Get the current values of the input sensors
float var_fan_setting_co2 = id(fan_setting_co2).state;
float var_fan_setting_humidity = id(fan_setting_humidity).state;
// Find the maximum value of the three sensors
float fan_setting = 0;
float fan_setting_1 = max(var_fan_setting_humidity, var_fan_setting_co2);
fan_setting = fan_setting_1;
// Return the maximum value
if (id(fan_speed_override).state) {
return id(override_fan_speed).state;
} else {
return fan_setting;
}
update_interval: 1s
accuracy_decimals: 0
unit_of_measurement: "%"
filters:
- sliding_window_moving_average:
window_size: 60
send_every: 60
on_value:
then:
- fan.turn_on:
id: ventilationsystem
speed: !lambda "return id(fan_speed_setting).state;"
number:
- platform: template
name: Override Fan Speed
icon: mdi:fan
min_value: 0
step: 1
max_value: 100
optimistic: true
id: override_fan_speed
- platform: template
name: Override Fan Duration
icon: mdi:clock
unit_of_measurement: min
min_value: 15
step: 5
max_value: 600
optimistic: true
id: override_fan_duration
- platform: template
name: "CO2 Offset"
optimistic: true
initial_value: 400
restore_value: true
min_value: 0
max_value: 1000
step: 1
id: number_co2_offset
- platform: template
name: "CO2 Fan Sensitivity"
optimistic: true
initial_value: 0.1 # in % per ppm
restore_value: true
min_value: 0
max_value: 10
step: 0.01
id: number_co2_fan_sensitivity
switch:
- platform: template
name: "Fan Speed Override"
optimistic: true
id: fan_speed_override
on_turn_on:
- fan.turn_on:
id: ventilationsystem
speed: !lambda "return id(override_fan_speed).state;"
- delay: !lambda "return (id(override_fan_duration).state) * 60 * 1000;"
- switch.turn_off: fan_speed_override
on_turn_off:
- delay: 5s
- fan.turn_on:
id: ventilationsystem
speed: !lambda "return id(fan_speed_setting).state;"