-
Notifications
You must be signed in to change notification settings - Fork 0
/
env-monitor.yaml
352 lines (330 loc) · 12.4 KB
/
env-monitor.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
substitutions:
devicename: envmon
upper_devicename: EnvMon
esphome:
name: $devicename
includes:
- GP2Y1010AU0F.h
- LD2410.h
- RGBCalc.h
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "0nFrfzxfR86aJlKBz8UJ+I/v9+jzp1Xb8X/6K/iB954="
ota:
password: "de66b76db75abcfb03ae21314cd950d1"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Env-Monitor Fallback Hotspot"
password: "7bqceQpZUOas"
captive_portal:
http_request:
useragent: esphome/device
timeout: 10s
id: http_request_data
i2c:
- id: i2c1
sda: 21
scl: 22
scan: true
- id: i2c2
sda: 18
scl: 19
scan: true
uart:
id: uart1
tx_pin: 16
rx_pin: 17
baud_rate: 256000
parity: NONE
stop_bits: 1
custom_component:
- lambda: |-
return {new LD2410(id(uart1))};
components:
- id: ld2410
- lambda: |-
return {new RGBCalc()};
components:
- id: rgbcalc
globals:
- id: temperature_r
type: int
- id: temperature_g
type: int
- id: temperature_b
type: int
- id: dust_density_r
type: int
- id: dust_density_g
type: int
- id: dust_density_b
type: int
- id: humidity_r
type: int
- id: humidity_g
type: int
- id: humidity_b
type: int
binary_sensor:
- platform: gpio
pin:
number: 0
mode:
input: true
pullup: true
name: ${upper_devicename} DS-2SC1Q140IY Shield Button
on_press:
then:
- switch.toggle: shield_switch
- platform: custom
lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
return {uart_component->hasTarget,uart_component->hasMovingTarget,uart_component->hasStillTarget};
binary_sensors:
- name: ${upper_devicename} LD2410 Target
id: target
- name: ${upper_devicename} LD2410 Moving Target
id: moving_target
- name: ${upper_devicename} LD2410 Still Target
id: still_target
- platform: gpio
pin: 23
name: ${upper_devicename} PIR
switch:
- platform: gpio
pin:
number: 25
name: ${upper_devicename} DS-2SC1Q140IY Shield Switch
id: "shield_switch"
on_turn_on:
then:
- http_request.send:
method: PUT
url: http://admin:th82201806.@192.168.68.232:80/ISAPI/PTZCtrl/channels/1/presets/2/goto
on_turn_off:
then:
- http_request.send:
method: PUT
url: http://admin:th82201806.@192.168.68.232:80/ISAPI/PTZCtrl/channels/1/presets/1/goto
sensor:
- platform: custom
lambda: |-
auto dust_sensor = new GP2Y1010AU0F();
App.register_component(dust_sensor);
return {dust_sensor};
sensors:
name: ${upper_devicename} GP2Y1010AU0F Dust Density
accuracy_decimals: 2
unit_of_measurement: "µg/m³"
on_value:
then:
- http_request.post:
url: http://192.168.68.170/json/state
headers:
Content-Type: application/json
on_response:
then:
- lambda: |-
json::parse_json(id(http_request_data).get_string(), [](JsonObject root) {
ESP_LOGI("main", "Update Dust Density Response: %d", root["success"].as<bool>());
});
json: |-
if(!id(target).state) return;
const JsonArray &segs = root.createNestedArray("seg");
const JsonObject &seg = segs.createNestedObject();
const JsonArray &cols = seg.createNestedArray("col");
const JsonArray &pri = cols.createNestedArray();
const JsonArray &bg = cols.createNestedArray();
const JsonArray &ter = cols.createNestedArray();
static int dust_density_i = 0;
seg["id"] = dust_density_i;
rgb_t rgb = {0, 0, 0};
// 粉尘密度[0,800]映射到光谱[380,780]
// double wave_len = 380 + x / 2.0;
double wave_len = x / 2.0;
wave_len = wave_len > 780 ? 780 : wave_len;
auto rgb_component = static_cast<RGBCalc *>(rgbcalc);
rgb_component->calc(wave_len, &rgb);
id(dust_density_r) = rgb.r;
id(dust_density_g) = rgb.g;
id(dust_density_b) = rgb.b;
// 设置三种颜色
pri[0] = id(temperature_r);
pri[1] = id(temperature_g);
pri[2] = id(temperature_b);
bg[0] = id(dust_density_r);
bg[1] = id(dust_density_g);
bg[2] = id(dust_density_b);
ter[0] = id(humidity_r);
ter[1] = id(humidity_g);
ter[2] = id(humidity_b);
ESP_LOGI("main", "Update %d Dust Density: %f, Color[[%d,%d,%d],[%d,%d,%d],[%d,%d,%d]]", dust_density_i, x,
id(temperature_r), id(temperature_g), id(temperature_b),
id(dust_density_r), id(dust_density_g), id(dust_density_b),
id(humidity_r), id(humidity_g), id(humidity_b));
dust_density_i += 1;
dust_density_i %= 6;
- platform: bh1750
name: ${upper_devicename} BH1750 Illuminance
address: 0x23
update_interval: 3s
i2c_id: i2c1
on_value:
then:
- http_request.post:
url: http://192.168.68.170/json/state
headers:
Content-Type: application/json
on_response:
then:
- lambda: |-
json::parse_json(id(http_request_data).get_string(), [](JsonObject root) {
ESP_LOGI("main", "Update Illuminance Response: %d", root["success"].as<bool>());
});
json: |-
const JsonArray &segs = root.createNestedArray("seg");
const JsonObject &seg = segs.createNestedObject();
static int illuminance_i = 0;
seg["id"] = illuminance_i;
// 亮度[0,63]映射到数值[0,255]
int v = id(target).state && x < 64 ? (64 - x) * 4 : 0;
seg["bri"] = v;
ESP_LOGI("main", "Update %d Illuminance: %f, Value(%d)", illuminance_i, x, v);
illuminance_i += 1;
illuminance_i %= 6;
- platform: aht10
update_interval: 3s
i2c_id: i2c2
temperature:
name: ${upper_devicename} AHT10 Temperature
on_value:
then:
- http_request.post:
url: http://192.168.68.170/json/state
headers:
Content-Type: application/json
on_response:
then:
- lambda: |-
json::parse_json(id(http_request_data).get_string(), [](JsonObject root) {
ESP_LOGI("main", "Update Temperature Response: %d", root["success"].as<bool>());
});
json: |-
if(!id(target).state) return;
const JsonArray &segs = root.createNestedArray("seg");
const JsonObject &seg = segs.createNestedObject();
const JsonArray &cols = seg.createNestedArray("col");
const JsonArray &pri = cols.createNestedArray();
const JsonArray &bg = cols.createNestedArray();
const JsonArray &ter = cols.createNestedArray();
static int temperature_i = 0;
seg["id"] = temperature_i;
rgb_t rgb = {0, 0, 0};
// 温度[0,40]映射到光谱[380,780]
double wave_len = 380 + x * 10.0;
wave_len = wave_len > 780 ? 780 : wave_len;
auto rgb_component = static_cast<RGBCalc *>(rgbcalc);
rgb_component->calc(wave_len, &rgb);
id(temperature_r) = rgb.r;
id(temperature_g) = rgb.g;
id(temperature_b) = rgb.b;
// 设置三种颜色
pri[0] = id(temperature_r);
pri[1] = id(temperature_g);
pri[2] = id(temperature_b);
bg[0] = id(dust_density_r);
bg[1] = id(dust_density_g);
bg[2] = id(dust_density_b);
ter[0] = id(humidity_r);
ter[1] = id(humidity_g);
ter[2] = id(humidity_b);
ESP_LOGI("main", "Update %d Temperature: %f, Color[[%d,%d,%d],[%d,%d,%d],[%d,%d,%d]]", temperature_i, x,
id(temperature_r), id(temperature_g), id(temperature_b),
id(dust_density_r), id(dust_density_g), id(dust_density_b),
id(humidity_r), id(humidity_g), id(humidity_b));
temperature_i += 1;
temperature_i %= 6;
humidity:
name: ${upper_devicename} AHT10 Humidity
on_value:
then:
- http_request.post:
url: http://192.168.68.170/json/state
headers:
Content-Type: application/json
on_response:
then:
- lambda: |-
json::parse_json(id(http_request_data).get_string(), [](JsonObject root) {
ESP_LOGI("main", "Update Humidity Response: %d", root["success"].as<bool>());
});
json: |-
if(!id(target).state) return;
const JsonArray &segs = root.createNestedArray("seg");
const JsonObject &seg = segs.createNestedObject();
const JsonArray &cols = seg.createNestedArray("col");
const JsonArray &pri = cols.createNestedArray();
const JsonArray &bg = cols.createNestedArray();
const JsonArray &ter = cols.createNestedArray();
static int humidity_i = 0;
seg["id"] = humidity_i;
rgb_t rgb = {0, 0, 0};
// 湿度[0,100]映射到光谱[380,780]
double wave_len = 380 + x * 4.0;
wave_len = wave_len > 780 ? 780 : wave_len;
auto rgb_component = static_cast<RGBCalc *>(rgbcalc);
rgb_component->calc(wave_len, &rgb);
id(humidity_r) = rgb.r;
id(humidity_g) = rgb.g;
id(humidity_b) = rgb.b;
// 设置三种颜色
pri[0] = id(temperature_r);
pri[1] = id(temperature_g);
pri[2] = id(temperature_b);
bg[0] = id(dust_density_r);
bg[1] = id(dust_density_g);
bg[2] = id(dust_density_b);
ter[0] = id(humidity_r);
ter[1] = id(humidity_g);
ter[2] = id(humidity_b);
ESP_LOGI("main", "Update %d Humidity: %f, Color[[%d,%d,%d],[%d,%d,%d],[%d,%d,%d]]", humidity_i, x,
id(temperature_r), id(temperature_g), id(temperature_b),
id(dust_density_r), id(dust_density_g), id(dust_density_b),
id(humidity_r), id(humidity_g), id(humidity_b));
humidity_i += 1;
humidity_i %= 6;
- platform: custom
lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
return {uart_component->movingTargetDistance,uart_component->movingTargetEnergy,uart_component->stillTargetDistance,uart_component->stillTargetEnergy,uart_component->detectDistance};
sensors:
- name: ${upper_devicename} LD2410 Moving Target Distance
id: moving_target_distance
unit_of_measurement: "cm"
accuracy_decimals: 0
- name: ${upper_devicename} LD2410 Moving Target Energy
id: moving_target_energy
unit_of_measurement: "%"
accuracy_decimals: 0
- name: ${upper_devicename} LD2410 Still Target Distance
id: still_target_distance
unit_of_measurement: "cm"
accuracy_decimals: 0
- name: ${upper_devicename} LD2410 Still Target Energy
id: still_target_energy
unit_of_measurement: "%"
accuracy_decimals: 0
- name: ${upper_devicename} LD2410 Target Distance
id: detect_distance
unit_of_measurement: "cm"
accuracy_decimals: 0