-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathESPHome Code
More file actions
280 lines (247 loc) · 5.91 KB
/
ESPHome Code
File metadata and controls
280 lines (247 loc) · 5.91 KB
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
esphome:
name: air-quality-sensor
friendly_name: Air Quality Sensor
esp32:
board: esp32-c3-devkitm-1
framework:
type: arduino
variant: ESP32C3
# Enable logging
logger:
# Enable Home Assistant API
api:
# encryption:
# key: ""
ota:
- platform: esphome
password: ""
wifi:
ssid: YOURSSID
password: YOURPASSWORD
# fast_connect: true
power_save_mode: none
output_power: 20dB
reboot_timeout: 0s
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Livingroom-Air-Quality-Sensor"
password: ""
captive_portal:
uart:
#UART_1 is for Presensce Sensor
- id: uart_1
tx_pin: GPIO21 #Grey
rx_pin: GPIO20 #Blue
baud_rate: 256000
parity: NONE
stop_bits: 1
#UART_2 is for PM2.5 Sensoe Reading
- id: uart_2
rx_pin: GPIO7 #RED
baud_rate: 9600
i2c:
#I2C for Enviromental Sensor
- id: bus_a
sda: GPIO8 #8 SDA YELLOW
scl: GPIO9 #9 SCL GREEN
scan: true
ld2410:
id: livingroom_ld2410
uart_id: uart_1
binary_sensor:
- platform: ld2410
has_target:
name: Presence
has_moving_target:
name: Moving Target
has_still_target:
name: Still Target
out_pin_presence_status:
name: out pin presence status
- platform: gpio
name: fan
id: fan
pin:
#Fan Status Reading
number: 10 #WHITE
inverted: True
sensor:
- platform: pm1006
uart_id: uart_2
pm_2_5:
name: "Air Pollutants"
id: air_pollutants
accuracy_decimals: 1
filters:
- sliding_window_moving_average:
window_size: 10
send_every: 10
- platform: ld2410
moving_distance:
name: "Moving Distance"
still_distance:
name: "Still Distance"
moving_energy:
name: "Moving Energy"
still_energy:
name: "Still Energy"
detection_distance:
name: "Detection Distance"
- platform: ens160_i2c
i2c_id: bus_a
eco2:
name: "ENS160 eCO2"
id: ens160_eco2
tvoc:
name: "ENS160 VOC"
id: ens160_voc
aqi:
id: ens160_air_quality_index
name: "ENS160 Air Quality Index"
update_interval: 60s
address: 0x53
compensation:
temperature: temperature
humidity: humidity
- platform: aht10
variant: AHT20
temperature:
name: "Temperature"
id: temperature
filters:
- offset: -16.5
humidity:
name: "Humidity"
id: humidity
filters:
- offset: 43
switch:
- platform: ld2410
engineering_mode:
name: "engineering mode"
bluetooth:
name: "control bluetooth"
- platform: gpio
# Fan Control
pin: 6
name: FAN
number:
- platform: ld2410
timeout:
name: timeout
light_threshold:
name: light threshold
max_move_distance_gate:
name: max move distance gate
max_still_distance_gate:
name: max still distance gate
g0:
move_threshold:
name: g0 move threshold
still_threshold:
name: g0 still threshold
g1:
move_threshold:
name: g1 move threshold
still_threshold:
name: g1 still threshold
g2:
move_threshold:
name: g2 move threshold
still_threshold:
name: g2 still threshold
g3:
move_threshold:
name: g3 move threshold
still_threshold:
name: g3 still threshold
g4:
move_threshold:
name: g4 move threshold
still_threshold:
name: g4 still threshold
g5:
move_threshold:
name: g5 move threshold
still_threshold:
name: g5 still threshold
g6:
move_threshold:
name: g6 move threshold
still_threshold:
name: g6 still threshold
g7:
move_threshold:
name: g7 move threshold
still_threshold:
name: g7 still threshold
g8:
move_threshold:
name: g8 move threshold
still_threshold:
name: g8 still threshold
button:
- platform: ld2410
factory_reset:
name: "factory reset"
restart:
name: "restart"
query_params:
name: query params
text_sensor:
- platform: ld2410
version:
name: "firmware version"
- platform: template
name: "ENS160 Air Quality Rating"
lambda: |-
switch ( (int) (id(ens160_air_quality_index).state) ) {
case 1: return {"Excellent"};
case 2: return {"Good"};
case 3: return {"Moderate"};
case 4: return {"Poor"};
case 5: return {"Unhealthy"};
default: return {"Not Available"};
}
- platform: template
name: "Air Quality Recommendation"
lambda: |-
std::string action = "";
if (id(ens160_air_quality_index).has_state()) {
int aqi = (int) id(ens160_air_quality_index).state;
if (aqi >= 4) {
action += "Turn Air purifier ON. ";
}
}
if (id(ens160_voc).has_state() && id(ens160_voc).state > 350) {
action += "Ventilate room (high VOC). ";
}
if (id(ens160_eco2).has_state() && id(ens160_eco2).state > 900) {
action += "Open window (high CO₂). ";
}
if (id(air_pollutants).has_state() && id(air_pollutants).state > 12) {
action += "Limit activity (PM2.5). ";
}
if (id(temperature).has_state() && id(temperature).state > 25) {
action += "Cool room. ";
} else if (id(temperature).state < 18) {
action += "Heat room. ";
}
if (id(humidity).has_state() && id(humidity).state > 65) {
action += "Dehumidify. ";
} else if (id(humidity).state < 40) {
action += "Use humidifier. ";
}
return action.empty() ? "Air quality is OK." : action;
icon: "mdi:lightbulb-on-outline"
update_interval: 60s
select:
- platform: ld2410
distance_resolution:
name: "distance resolution"
baud_rate:
name: "baud rate"
light_function:
name: light function
out_pin_level:
name: out pin level