-
Notifications
You must be signed in to change notification settings - Fork 0
/
esphome.yml
256 lines (232 loc) · 6.34 KB
/
esphome.yml
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
esphome:
name: living-room-air
friendly_name: Living Room Air
esp32:
board: esp32-c3-devkitm-1
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: ""
ota:
- platform: esphome
password: ""
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Living-Room-Air Fallback Hotspot"
password: ""
captive_portal:
esp32_ble_tracker:
scan_parameters:
interval: 1100ms
window: 1100ms
active: true
bluetooth_proxy:
active: true
light:
- platform: neopixelbus
type: GRB
variant: WS2812X
pin: GPIO20
num_leds: 1
name: "Health LED"
id: healthled
interval:
- interval: 180s
# Two-minute interval to extend the life span of the PMS7003 sensor
then:
- switch.turn_on: pms_switch
- delay: 45s
- switch.turn_off: pms_switch
# PlantCare A1 Config
# D0 (GPIO2): Set as Relay2 for RST.
# D1 (GPIO3): Set as PMS5003 RX.
# D2 (GPIO4): Set as PMS5003 TX.
# D4 (GPIO6): Set as Relay1 for SET.
# D7 (GPIO20): WS2812B-2020
switch:
- platform: template
name: "PMS7003"
internal: true
id: pms_switch
optimistic: true
turn_on_action:
- uart.write:
id: pms7003_uart
data: [0x42, 0x4D, 0xE4, 0x00, 0x01, 0x01, 0x74]
turn_off_action:
- uart.write:
id: pms7003_uart
data: [0x42, 0x4D, 0xE4, 0x00, 0x00, 0x01, 0x73]
uart:
id: pms7003_uart
tx_pin: GPIO3
rx_pin: GPIO4
baud_rate: 9600
sensor:
- platform: pmsx003
type: PMSX003
uart_id: pms7003_uart
pm_1_0:
name: "PM <1.0µm"
id: pm1
filters:
- sliding_window_moving_average:
window_size: 30
send_every: 30
pm_2_5:
name: "PM <2.5µm"
id: pm2_5
filters:
- sliding_window_moving_average:
window_size: 30
send_every: 30
pm_10_0:
name: "PM <10.0µm"
id: pm10
filters:
- sliding_window_moving_average:
window_size: 30
send_every: 30
# The WHO guidelines work with 24-hour averages of the PM2.5 and PM10 sensors
- platform: template
name: "PM <2.5µm 24h average"
id: pm2_5_avg_24h
icon: mdi:chemical-weapon
unit_of_measurement: µg/m³
lambda: |-
return id(pm2_5).state;
update_interval: 60s
filters:
- sliding_window_moving_average:
window_size: 1440 # = 24 hours x 60 minutes
send_every: 1
on_value:
then:
- script.execute: update_aqi
- platform: template
name: "PM <10.0µm 24h average"
id: pm10_avg_24h
icon: mdi:chemical-weapon
unit_of_measurement: µg/m³
lambda: |-
return id(pm10).state;
update_interval: 60s
filters:
- sliding_window_moving_average:
window_size: 1440 # = 24 hours x 60 minutes
send_every: 1
on_value:
then:
- script.execute: update_aqi
- platform: wifi_signal
name: "WiFi Signal"
update_interval: 60s
- platform: uptime # Uptime in Seconds
name: Uptime Sensor
id: uptime_sensor
update_interval: 60s
internal: True
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
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 ? String(days) + "d " : "") +
(hours ? String(hours) + "h " : "") +
(minutes ? String(minutes) + "m " : "") +
(String(seconds) + "s")
).c_str();
# A textual presentation of the AQI
text_sensor:
- platform: template
name: "Air Quality Index"
id: aqi
icon: mdi:air-filter
- platform: template # Human Readable Uptime
name: Uptime
id: uptime_human
icon: mdi:clock-start
# This script is called on every update of the relevant sensor values.
script:
- id: update_aqi
mode: restart
then:
# Bad if at least one of the sensor values is bad
- if:
condition:
or:
- sensor.in_range:
id: pm2_5_avg_24h
above: 25
- sensor.in_range:
id: pm10_avg_24h
above: 50
- sensor.in_range:
id: pm2_5
above: 500
- sensor.in_range:
id: pm10
above: 1000
then:
- text_sensor.template.publish:
id: aqi
state: Bad
- light.turn_on:
id: healthled
brightness: 100%
red: 100%
green: 0%
blue: 0%
else:
# Acceptable if at least one of the sensor values is acceptable
- if:
condition:
or:
- sensor.in_range:
id: pm2_5_avg_24h
above: 12
- sensor.in_range:
id: pm10_avg_24h
above: 25
- sensor.in_range:
id: pm2_5
above: 50
- sensor.in_range:
id: pm10
above: 100
then:
- text_sensor.template.publish:
id: aqi
state: Acceptable
- light.turn_on:
id: healthled
brightness: 100%
red: 100%
green: 100%
blue: 0%
else:
# Otherwise good (all of the sensor values are good)
- text_sensor.template.publish:
id: aqi
state: Good
- light.turn_on:
id: healthled
brightness: 20%
red: 0%
green: 100%
blue: 0%