-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasement-s3.yaml
653 lines (596 loc) · 17.5 KB
/
basement-s3.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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
# dss1322 Pin1 = GND, Pin2 = Vcc, Pin4 = SCLK, Pin5 = MOSI, Pin14 = DC, Pin15 = RST (опционально),
###################################################################
## WEMOS S3 mini ##
## |EN| | 1| |#| |33| |43| tuart ##
## | 2| | 3| ADC |#| |37| |44| ruart ##
## | 4| reset | 5| SWpeltye |#| |38| |36| scl ##
## |12| clk | 6| SWvent |#| |34| |35| sca ##
## |13| ds | 7| SWopen |#| |21| |18| AM2302 ##
## |11| mosi | 8| SWclose |#| |17| |16| BiWater ##
## |10| CS | 9| Buzzer |#| |GN| |GN| ##
## |3V| |14| |#| |15| led |5V| ##
###################################################################
substitutions:
name: "basement"
lastname: APC
device_description: "Контроллер подвала"
esphome:
name: "${name}"
comment: "${device_description}"
on_boot:
then:
- switch.turn_on: close_vent
project:
name: esphome.basement-controller
version: "2.0"
esp32:
board: esp32-s3-devkitc-1
framework:
type: arduino
external_components:
- source: github://ananyevgv/esphome-apc-ups
refresh: 0s
- source: github://pr#5198
components: [ aht10 ]
logger:
baud_rate: 0
api:
password: !secret api_pass
ota:
password: !secret ota_pass
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
power_save_mode: none
uart:
tx_pin: 43
rx_pin: 44
baud_rate: 2400
id: uart_0
apc_ups:
- id: ups0
uart_id: uart_0
spi:
clk_pin: 12 #36 Pin4 DSS1322
mosi_pin: 11 #35 Pin5 DSS1322
i2c:
sda: 35
scl: 36
scan: true
id: bus_a
# frequency: 400khz
output:
- platform: ledc
pin: 9
id: buzzer
sun:
latitude: 57.00000000°
longitude: 39.0000000°
font:
- file: 'font/b.ttf'
id: font1
size: 12
- file: 'font/b.ttf'
id: font2
size: 28
- file: 'font/b.ttf'
id: font3
size: 18
animation:
- file: "picture/fan.gif"
id: gfan
resize: 24x24
- file: "picture/open.gif"
id: gopen
resize: 24x24
- file: "picture/close.gif"
id: gclosed
resize: 24x24
- file: "picture/water.gif"
id: gwater
resize: 24x24
- file: "picture/pump.gif"
id: gpump
resize: 24x24
- file: "picture/tower.gif"
id: gtower
resize: 24x24
image:
- file: mdi:fridge
id: ifridge
resize: 24x24
- file: mdi:sine-wave
id: iwave
resize: 24x24
- file: mdi:weather-night
id: imoon
resize: 24x24
- file: mdi:home-thermometer-outline
id: ihome
resize: 16x16
- file: mdi:sun-thermometer
id: isthermometer
resize: 16x16
- file: mdi:thermometer-low
id: ithermometer
resize: 16x16
- file: mdi:water-percent
id: ipercent
resize: 16x16
- file: mdi:sun-wireless-outline
id: isun
resize: 16x16
- file: mdi:wifi-strength-1
id: i_wifi1
resize: 16x16
- file: mdi:wifi-strength-2
id: i_wifi2
resize: 16x16
- file: mdi:wifi-strength-3
id: i_wifi3
resize: 16x16
- file: mdi:wifi-strength-4
id: i_wifi4
resize: 16x16
- file: mdi:wifi-strength-off-outline
id: i_wifioff
resize: 16x16
binary_sensor:
- platform: apc_ups
apc_ups_id: ups0
runtime_calibration:
name: "${lastname} runtime calibration"
smart_trim:
name: "${lastname} smart trim"
smart_boost:
name: "${lastname} smart boost"
on_line:
name: "${lastname} on line"
on_battery:
name: "${lastname} on battery"
output_overloaded:
name: "${lastname} output overloaded"
battery_low:
name: "${lastname} battery low"
replace_battery:
name: "${lastname} replace battery"
- platform: gpio
pin:
number: 16
mode: INPUT_PULLUP
inverted: True
name: "${name} water!"
device_class: moisture
id: water
on_press:
then:
- output.turn_on: buzzer
- light.turn_on: led
on_release:
then:
- light.turn_off: led
- output.turn_off: buzzer
# бинарный сенсор по току
- platform: analog_threshold
name: "${name} pump"
sensor_id: pump_current
device_class: plug
threshold: 0.2
id: pump
on_press:
then:
- sensor.template.publish:
id: pump_on
state: !lambda 'return id(sntp_time).now().timestamp;'
on_release:
then:
- number.set:
id: counter
value: !lambda |-
return ((id(counter).state)+1);
- sensor.template.publish:
id: pump_off
state: !lambda 'return id(sntp_time).now().timestamp;'
number:
- platform: template
name: ${name} Counter
id: counter
update_interval: 30s
min_value: 0
max_value: 50
step: 0
optimistic: true
initial_value: 0
internal: true
button:
- platform: restart
name: "${name} Restart"
switch:
- platform: gpio
name: "${name} on-peltye"
id: cool
pin: 5
icon: "mdi:fridge"
on_turn_on:
- switch.turn_off: vent
- switch.turn_on: cool
- switch.turn_on: close_vent
on_turn_off:
- switch.turn_off: cool
- platform: gpio
name: "${name} on_vent"
id: vent
icon: "mdi:fan"
pin: 6
on_turn_on:
- switch.turn_off: cool
- switch.turn_on: open_vent
- switch.turn_on: vent
on_turn_off:
- switch.turn_on: close_vent
- switch.turn_off: vent
- platform: gpio
name: "${name} open_vent"
id: open_vent
icon: "mdi:valve-open"
pin: 7
on_turn_on:
- switch.turn_off: close_vent
- switch.turn_on: open_vent
- delay: 10s
- switch.turn_off: open_vent
on_turn_off:
- switch.turn_off: open_vent
- platform: gpio
name: "${name} close_vent"
id: close_vent
icon: "mdi:valve-closed"
pin: 8
on_turn_on:
- switch.turn_off: open_vent
- switch.turn_on: close_vent
- delay: 10s
- switch.turn_off: close_vent
on_turn_off:
- switch.turn_off: close_vent
light:
- platform: status_led
name: "Water Led"
pin: 15
id: led
internal: True
text_sensor:
- platform: wifi_info
ip_address:
name: "${name} IP Address"
icon: mdi:ip
id: ip
ssid:
name: "${name} SSID"
icon: mdi:access-point-network
mac_address:
name: "${name} Mac"
icon: mdi:lan
- platform: apc_ups
apc_ups_id: ups0
cause_of_last_transfer:
name: "${lastname} cause of last transfer"
filters:
- substitute:
- "R -> неприемлемая скорость изменения напряжения сети" # unacce table utility voltage rate of change
# - "S -> передача по команде U или активация ИБП" #transfer due to U command or activation of UPS
# - "NA -> причина перевода по-прежнему недоступна" прочитайте еще раз # transfer reason still not available; read again
# - "H -> высокое напряжение сети" #high utility voltage
# - "L -> низкое напряжение сети" #low utility voltage
# - "T -> скачок напряжения" #line voltage notch or spike
- "O -> никаких переходов с момента включения" #no transfers since turnon
firmware_revision:
name: "${lastname} firmware revision"
manufacture_date:
name: "${lastname} manufacture date"
last_battery_change_date:
name: "${lastname} last battery change date"
serial_number:
name: "${lastname} serial number"
old_firmware_version:
name: "${lastname} old firmware version"
# measure_upc_firmware:
# name: "${lastname} measure_upc_firmware"
# copyright_notice:
# name: "${lastname} copyright_notice"
self_test_results:
name: "${lastname} self_test_results"
filters:
- substitute:
- "OK -> хорошая батарея" #good battery
- "BT -> произошел сбой из-за недостаточной емкости" #failed due to insufficient capacity
- "NG -> произошел сбой из-за перегрузки" #failed due to overload
- "NO -> результаты отсутствуют (за последние 5 минут тест не проводился)" # no results available (no test performed in last 5 minutes
alarm_delay:
name: "${lastname} alarm_delay"
filters:
- substitute:
- "0 -> Задержка в 5 секунд после отключения питания" #5 second delay after power fail
- "T -> Задержка в 30 секунд" #30 second delay
- "L -> сигнал тревоги только при низком заряде батареи" #alarm at low battery only
- "N -> никакой тревоги" # no alarm
line_quality:
name: "${lastname} line_quality"
filters:
- substitute:
- "00 -> неприемлемый" # unacceptable
- "FF -> приемлемый" # acceptable
sensor:
- platform: apc_ups
apc_ups_id: ups0
battery_voltage:
name: "${lastname} battery voltage"
grid_frequency:
name: "${lastname} grid frequency"
grid_voltage:
name: "${lastname} grid voltage"
id: grid_voltage
ac_output_voltage:
name: "${lastname} ac output voltage"
ac_output_load:
name: "${lastname} ac output load"
id: load
status_bitmask:
name: "${lastname} status bitmask"
state_of_charge:
name: "${lastname} state of charge"
device_class: BATTERY
estimated_runtime:
name: "${lastname} estimated runtime"
internal_temperature:
name: "${lastname} internal temperature"
ambient_temperature:
name: "${lastname} ambient temperature"
max_grid_voltage:
name: "${lastname} max grid voltage"
min_grid_voltage:
name: "${lastname} min grid voltage"
# ambient_humidity:
# name: "${lastname} ambient humidity"
low_transfer_voltage:
name: "${lastname} low transfer voltage"
nominal_output_voltage:
name: "${lastname} nominal output voltage"
upper_transfer_voltage:
name: "${lastname} upper transfer voltage"
nominal_battery_voltage:
name: "${lastname} nominal_battery_voltage"
return_threshold:
name: "${lastname} return_threshold"
filters:
- calibrate_linear:
method: exact
datapoints:
- 0 -> 0
- 1 -> 15
- 2 -> 25
- 3 -> 90
# расчет потребляемой мощности +- лапоть
- platform: copy
source_id: load
name: "${lastname} UPC power"
filters:
- lambda: return (x * 0.007);
unit_of_measurement: "kW"
device_class: "power"
id: apc_power
accuracy_decimals: 3
- platform: total_daily_energy
name: "${lastname} Total Daily Energy"
power_id: apc_power
accuracy_decimals: 1
- platform: wifi_signal
name: ${name} Wifi
update_interval: 60s
id: wifi_signal_db
entity_category: "diagnostic"
# Reports the WiFi signal strength in %
- platform: copy
source_id: wifi_signal_db
name: "${name} WiFi Percent"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "%"
entity_category: "diagnostic"
id: WiFiP
- platform: aht10
temperature:
name: "${name} outdor_T"
id: t_outdor
humidity:
name: "${name} outdor_%"
id: h_outdor
update_interval: 60s
address: 0x38
i2c_id: bus_a
- platform: absolute_humidity
name: "${name} Absolute Humidity outdor"
temperature: t_outdor
humidity: h_outdor
###############################################
- platform: aht10
temperature:
name: "${name} holod_T"
id: t_indor
humidity:
name: "${name} holod_%"
id: h_indor
update_interval: 60s
address: 0x39
##############################################
- platform: dht
pin: 18
temperature:
name: "${name} server_T"
# id: t_indor
humidity:
name: "${name} server_%"
# id: h_indor
model: AM2302
- platform: absolute_humidity
name: "${name} Absolute Humidity"
temperature: t_indor
humidity: h_indor
# измеряем переменный ток
- platform: adc
pin: 3 #2
id: adc_sensor
- platform: ct_clamp
sensor: adc_sensor
name: "pump current"
id: pump_current
update_interval: 5s
- platform: sun
name: "${name} Elevation"
type: elevation
id: elevation
- platform: template
name: "time pump off"
device_class: timestamp
id: pump_off
update_interval: never
- platform: template
name: "time pump on"
device_class: timestamp
id: pump_on
update_interval: never
- platform: template
name: "pump working"
lambda: |-
return id(counter).state;
accuracy_decimals: 0
icon: mdi:counter
- platform: duty_time
id: pump_work_time
name: pump Work Time
sensor: pump
restore: false
last_time:
name: pump Turn-On Time
id: pump_turn_on_time
climate:
- platform: thermostat
id: Holodilnik
min_cooling_off_time: 5s
min_cooling_run_time: 5s
min_idle_time: 5s
visual:
min_temperature: 5 °C
max_temperature: 9 °C
temperature_step: 0.5 °C
name: "${name} Холодильник"
sensor: t_indor
cool_action:
- if:
condition:
lambda: return (id(t_indor).state - id(t_outdor).state) > 3;
then:
- switch.turn_on: vent
else:
- switch.turn_on: cool
idle_action:
- switch.turn_off: vent
- switch.turn_off: cool
off_mode:
- switch.turn_off: vent
- switch.turn_off: cool
display:
- platform: ssd1322_spi
model: "SSD1322 256x64"
reset_pin: 4 #Pin15 = RST
cs_pin: 10 #34 Pin16 DSS1322
dc_pin: 13 #37 Pin14 DSS1322
lambda: |-
it.line(175, 40, 255, 40);
it.line(195, 0, 195, 63);
it.line(225, 0, 225, 63);
it.rectangle(175, 20, 255, 63);
it.line(0, 31, 174, 31);
it.line(31, 0, 31, 62);
it.rectangle(0, 0, 63, 63);
it.image(203, 2, id(ihome));
it.image(233, 2, id(isthermometer));
it.image(177, 22, id(ithermometer));
it.image(177, 42, id(ipercent));
it.printf(95, 50, id(font1),"%s", to_string(id(ip).state).c_str());
it.strftime(64, 0, id(font2),"%H %M", id(sntp_time).now());
static int i = 0;
i++;
if ((i % 2) == 0)
it.print(96, 0, id(font2),":");
if ((id(elevation).state) > 0)
it.image(150, 2, id(isun));
else
it.image(150, 2, id(imoon));
if (id(t_indor).state) {
it.printf(198, 25, id(font1), "%.1f", id(t_indor).state);
}
if (id(t_outdor).state) {
it.printf(228, 25, id(font1), " %.1f", id(t_outdor).state);
}
if (id(h_indor).state) {
it.printf(198, 45, id(font1), "%.1f", id(h_indor).state);
}
if (id(h_outdor).state) {
it.printf(228, 45, id(font1), " %.1f", id(h_outdor).state);
}
if (id(cool).state) {
it.image(4, 4, id(ifridge));
}
if (id(vent).state) {
id(gfan).next_frame();
it.image(4, 4, id(gfan));
}
if (id(open_vent).state) {
id(gopen).next_frame();
it.image(4, 35, id(gopen));
}
if (id(close_vent).state) {
id(gclosed).next_frame();
it.image(4, 35, id(gclosed));
}
if (id(water).state) {
id(gwater).next_frame();
it.image(35, 4, id(gwater));
}
uint16_t var = (id(WiFiP).state);
switch (var) {
case 0 ... 24: it.image(177, 2, id(i_wifi1)); break;
case 25 ... 49: it.image(177, 2, id(i_wifi2)); break;
case 50 ... 74: it.image(177, 2, id(i_wifi3)); break;
case 75 ... 100: it.image(177, 2, id(i_wifi4)); break;
default: it.image(177, 2, id(i_wifioff)); break;
}
if (id(pump).state) {
id(gpump).next_frame();
it.image(35, 35, id(gpump));
}
if ((id(grid_voltage).state) == 0) {
id(gtower).next_frame();
it.image(67, 35, id(gtower));
}
else
it.image(67, 35, id(iwave));
it.printf(95, 31, id(font3), "%.0fv%.0f%%" , id(grid_voltage).state, id(load).state);
time:
- platform: sntp
id: sntp_time
timezone: UTC-3 #Europe/Moscow
servers: !secret sntp
on_time:
- hours: 00
then:
- number.set:
id: counter
value: 0
- sensor.duty_time.reset: pump_work_time
web_server:
port: 80
auth:
username: !secret web_user
password: !secret web_pass