-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathsmartintercom-esp32.yaml
More file actions
844 lines (807 loc) · 24.9 KB
/
smartintercom-esp32.yaml
File metadata and controls
844 lines (807 loc) · 24.9 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
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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
substitutions:
dev_name: smartintercom
#ESP32 Определение нужных GPIO
base: esp32dev
led_status: GPIO16 # Индикатор статуса API, GPIO2 - это встроенный синий светодиод на ESP12
led_indicator: GPIO13 # Дополнительный индикатор, который будет показывать режимы и прочее.
detect_line: GPIO12 # Пин детектора вызова
button_boot: GPIO0 # Кнопка управления платой и перевода в режим прошивки
relay_line: GPIO14 # Пин "Отключения динамика"
switch_open: GPIO17 # Пин "Открытие двери"
switch_phone: GPIO4 # Пин "Трубка положена/поднята"
#input_select_mode_value
input_select_disable: "Не активен"
input_select_reject: "Сброс вызова"
input_select_accept: "Открывать всегда"
#line_status_text
line_status_call: "Вызов"
line_status_answer: "Ответ"
line_status_open: "Открытие двери"
line_status_reject: "Сброс вызова"
line_status_close: "Закрыто"
#delay
call_end_detect_delay: "4000" # Интервал между детектированием вызова
delay_before_answer: "1000" # (default) Отпределили вызов, *** подождали ***... Передаем управление на плату,
# отключаем трубку, *** подождали *** ... воспроизводим аудио, если надо. (Number компонент before_answer)
delay_before_open_door: 100ms # Воспроизведение аудио закончилось, *** подождали *** ... нажимаем кнопку открытия двери.
delay_open_on_time: "600" # (default) Кнопка открытия двери нажата, *** подождали *** ... отпустили кнопку. (Number компонент open_time)
delay_after_close_greeting: "1000" # (default) После открытия двери ждем пока закончится воспроизведение сигнала открытия двери на блоке вызова, чтобы не начать воспроизводить аудио в этот звук. (Number компонент delay_greeting)
delay_after_close_door: "2000" # (default) Отпустили кнопку открытия двери, *** подождали *** ... Возвращаем управление на трубку (Number компонент after_close)
#audio_support
play_user_greeting: playFile(audio_player, "/user_greeting.mp3")
play_user_access_allowed: playFile(audio_player, "/user_access_allowed.mp3")
play_delivery_access_allowed: playFile(audio_player, "/delivery_access_allowed.mp3")
play_access_denied: playFile(audio_player, "/access_denied.mp3")
esp32:
board: ${base}
framework:
type: arduino
esphome:
name: ${dev_name}
comment: "SmartIntercom Nelma 4E"
libraries:
- SPI
- FS
- WiFi
- WiFiClientSecure
- NetworkClientSecure
- LittleFS
- Improv=https://github.com/SCratORS/FTPClientServer
- ESP8266Audio
includes:
- lib/ESPUtils.h
- lib/ESPAudio.h
platformio_options:
board_build.filesystem: littlefs
board_build.partitions: ../../../config/esphome/partitions_esp32.csv
# build_flags:
# - "-DSDCARD" # Поддержка SD карты
on_boot:
priority: -100
then:
- script.execute: boot_script
# Enable logging
logger:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
captive_portal:
# Глобальные переменные
globals:
- id: current_mode
type: int
initial_value: '0'
restore_value: true
- id: status_line
type: bool
initial_value: 'false'
- id: status_mute
type: bool
initial_value: 'false'
restore_value: true
- id: status_phone_disable
type: bool
initial_value: 'false'
restore_value: true
- id: status_leding
type: bool
initial_value: 'true'
restore_value: true
- id: status_sound
type: bool
initial_value: 'true'
restore_value: true
- id: status_greeting
type: bool
initial_value: 'false'
restore_value: true
- id: status_once_mode
type: int
initial_value: '0'
restore_value: true
# MQTT и API вместе работать не могут. Выбери что надо.
# +---------------------------------------------+
# Активируем работу по протоколу MQTT
# +---------------------------------------------+
#mqtt:
#broker: 192.168.0.254
#username: "mqtt-client"
#password: "j3qq4h7h2v2hch4m3hk86m8vw"
# +---------------------------------------------+
# Активируем работу с API HomeAssistans через интеграцию ESPHome
# +---------------------------------------------+
api:
# +---------------------------------------------+
# Возможность обновляться по воздуху
ota:
platform: esphome
password: "12345678"
external_components: # fix for removal of custom component in esphome 2025.xx and up
- source: github://esphome/esphome@2024.12.4
components: [ custom, custom_component ]
custom_component:
- id: ftp_server
lambda: 'return {new FTPSrv("","")};' # (Логин, Пароль). По умолчанию anonymous
- id: audio_player
lambda: 'return {new ESPAudio()};'
# Пошла мазута
light:
- platform: status_led
id: led_status
pin: $led_status
effects:
- strobe:
name: blink
colors:
- state: true
duration: 100ms
- state: false
duration: 1900ms
- platform: monochromatic
id: led_action
output: indicator
internal: true
restore_mode: ALWAYS_OFF
default_transition_length: 0ms
effects:
- pulse:
name: pulse
update_interval: 2s
- strobe:
name: blink
colors:
- state: true
duration: 100ms
- state: false
duration: 1900ms
- strobe:
name: calling
colors:
- state: true
duration: 50ms
- state: false
duration: 50ms
script:
- id: boot_script
then:
- logger.log: "Boot config"
- if:
condition:
lambda: 'return id(current_mode) == 0;'
then:
- select.set:
id: mode_select
option: ${input_select_disable}
- logger.log: ${input_select_disable}
else:
if:
condition:
lambda: 'return id(current_mode) == 1;'
then:
- select.set:
id: mode_select
option: ${input_select_reject}
- logger.log: ${input_select_reject}
else:
- select.set:
id: mode_select
option: ${input_select_accept}
- logger.log: ${input_select_accept}
- if:
condition:
lambda: 'return id(status_leding);'
then:
switch.turn_on: led
- if:
condition:
lambda: 'return id(status_sound);'
then:
switch.turn_on: sound
- if:
condition:
lambda: 'return id(status_greeting);'
then:
switch.turn_on: greeting
- if:
condition:
lambda: 'return id(status_mute);'
then:
switch.turn_on: mute
- if:
condition:
lambda: 'return id(status_phone_disable);'
then:
switch.turn_on: phone_disable
- if:
condition:
lambda: 'return id(status_once_mode) == 1;'
then:
switch.turn_on: accept_call
else:
if:
condition:
lambda: 'return id(status_once_mode) == 2;'
then:
switch.turn_on: delivery
else:
if:
condition:
lambda: 'return id(status_once_mode) == 3;'
then:
switch.turn_on: reject_call
- id: led_check
then:
- light.turn_off:
id: led_action
- light.turn_off:
id: led_status
- if:
condition:
lambda: 'return id(status_leding);'
then:
- if:
condition:
lambda: 'return id(status_mute);'
then:
light.turn_on:
id: led_action
effect: pulse
- if:
condition:
lambda: 'return id(status_once_mode) > 0;'
then:
if:
condition:
lambda: 'return id(status_once_mode) < 3;'
then:
light.turn_on:
id: led_action
effect: blink
else:
light.turn_on:
id: led_status
effect: blink
- if:
condition:
lambda: 'return id(status_line);'
then:
light.turn_on:
id: led_action
effect: calling
# Accept incoming call
- id: accepting
then:
if:
condition:
lambda: 'return id(status_line);'
then:
- output.turn_on: relay_switch_line
- output.turn_on: phone_up
- lambda: 'id(line_status).publish_state("${line_status_answer}");'
- delay: !lambda "return id(delay_before_answer).state;"
- if:
condition:
switch.is_on: greeting
then:
if:
condition:
or:
- lambda: 'return id(status_sound);'
- switch.is_on: delivery
then:
lambda: ${play_user_greeting};
else:
if:
condition:
switch.is_on: delivery
then:
lambda: ${play_delivery_access_allowed};
else:
if:
condition:
lambda: 'return id(status_sound);'
then:
lambda: ${play_user_access_allowed};
- wait_until:
lambda: 'return !isPlaying(audio_player);'
- delay: $delay_before_open_door
- output.turn_on: open_door
- lambda: 'id(line_status).publish_state("${line_status_open}");'
- delay: !lambda "return id(delay_open_time).state;"
- output.turn_off: open_door
- if:
condition:
switch.is_on: greeting
then:
- delay: !lambda "return id(delay_greeting).state;"
- if:
condition:
switch.is_on: delivery
then:
lambda: ${play_delivery_access_allowed};
else:
if:
condition:
lambda: 'return id(status_sound);'
then:
lambda: ${play_user_access_allowed};
- wait_until:
lambda: 'return !isPlaying(audio_player);'
- lambda: 'id(line_status).publish_state("${line_status_reject}");'
- delay: !lambda "return id(delay_after_close).state;"
- output.turn_off: phone_up
- lambda: 'id(line_status).publish_state("${line_status_close}");'
- if:
condition:
switch.is_on: accept_call
then:
switch.turn_off: accept_call
# Reject incoming call
- id: rejecting
then:
if:
condition:
lambda: 'return id(status_line);'
then:
- output.turn_on: relay_switch_line
- output.turn_on: phone_up
- lambda: 'id(line_status).publish_state("${line_status_answer}");'
- delay: !lambda "return id(delay_before_answer).state;"
- if:
condition:
lambda: 'return id(status_sound);'
then:
- lambda: ${play_access_denied};
- wait_until:
lambda: 'return !isPlaying(audio_player);'
- delay: !lambda "return id(delay_open_time).state;"
- lambda: 'id(line_status).publish_state("${line_status_reject}");'
- output.turn_off: phone_up
- lambda: 'id(line_status).publish_state("${line_status_close}");'
- delay: !lambda "return id(delay_after_close).state;"
- if:
condition:
switch.is_on: reject_call
then:
switch.turn_off: reject_call
- id: state_call
then:
if:
condition:
switch.is_on: accept_call
then:
script.execute: accepting
else:
if:
condition:
switch.is_on: reject_call
then:
script.execute: rejecting
else:
if:
condition:
lambda: 'return id(current_mode) == 2;'
then:
script.execute: accepting
else:
if:
condition:
lambda: 'return id(current_mode) == 1;'
then:
script.execute: rejecting
else:
lambda: 'id(line_status).publish_state("${line_status_close}");'
number:
- platform: template
name: ${dev_name}_call_end_delay
icon: "mdi:clock"
id: call_end_delay
optimistic: true
mode: box
unit_of_measurement: "мс"
entity_category: "config"
restore_value: true
initial_value: ${call_end_detect_delay}
min_value: 1000
max_value: 10000
step: 100
- platform: template
name: ${dev_name}_before_answer
icon: "mdi:clock"
id: delay_before_answer
optimistic: true
mode: box
unit_of_measurement: "мс"
entity_category: "config"
restore_value: true
initial_value: ${delay_before_answer}
min_value: 100
max_value: 5000
step: 100
- platform: template
name: ${dev_name}_open_time
icon: "mdi:clock"
id: delay_open_time
optimistic: true
mode: box
unit_of_measurement: "мс"
entity_category: "config"
restore_value: true
initial_value: ${delay_open_on_time}
min_value: 100
max_value: 2000
step: 50
- platform: template
name: ${dev_name}_after_close
icon: "mdi:clock"
id: delay_after_close
optimistic: true
mode: box
unit_of_measurement: "мс"
entity_category: "config"
restore_value: true
initial_value: ${delay_after_close_door}
min_value: 100
max_value: 5000
step: 100
- platform: template
name: ${dev_name}_greeting_delay
icon: "mdi:clock"
id: delay_greeting
optimistic: true
mode: box
unit_of_measurement: "мс"
entity_category: "config"
restore_value: true
initial_value: ${delay_after_close_greeting}
min_value: 100
max_value: 5000
step: 100
select:
- platform: template
name: ${dev_name}_modes
icon: "mdi:deskphone"
optimistic: true
id: mode_select
options:
- ${input_select_disable}
- ${input_select_reject}
- ${input_select_accept}
initial_option: ${input_select_disable}
on_value:
lambda: |-
if (id(mode_select).state == "${input_select_disable}") {
id(current_mode) = 0;
} else if (id(mode_select).state == "${input_select_reject}") {
id(current_mode) = 1;
} else {
id(current_mode) = 2;
}
text_sensor:
- platform: template
id: line_status
icon: "mdi:bell"
name: ${dev_name}_line_status
lambda: 'return {"${line_status_close}"};'
- platform: wifi_info
ip_address:
name: ${dev_name}_ip
icon: "mdi:lan"
mac_address:
name: ${dev_name}_mac
icon: "mdi:lan"
- platform: custom
lambda: |-
auto fs_info_sensor_ = new FSInfoSensor();
App.register_component(fs_info_sensor_);
return {fs_info_sensor_->firmware_current_version, fs_info_sensor_->fs_info_sensor};
text_sensors:
- name: ${dev_name}_firmware
icon: "mdi:information"
entity_category: diagnostic
- name: ${dev_name}_fs_used
icon: "mdi:micro-sd"
entity_category: diagnostic
sensor:
- platform: wifi_signal
name: ${dev_name}_rssi
update_interval: 600s
binary_sensor:
- platform: gpio
id: line_detect
name: ${dev_name}_line_detect
pin:
number: $detect_line
mode: INPUT_PULLUP
inverted: True
filters:
- delayed_off: !lambda "return id(call_end_delay).state;"
on_press:
if:
condition:
lambda: 'return id(status_line) == false;'
then:
- lambda: 'id(status_line) = true;'
- output.turn_off: phone_up
- script.wait: led_check
- script.execute: led_check
- logger.log: "Incoming call detected"
- if:
condition:
lambda: 'return id(status_mute);'
then:
output.turn_on: relay_switch_line
- delay: !lambda "return id(delay_before_answer).state;"
- script.execute: state_call
on_release:
- if:
condition:
switch.is_on: phone_disable
then:
output.turn_on: relay_switch_line
else:
output.turn_off: relay_switch_line
- output.turn_off: phone_up
- lambda: 'id(status_line) = false;'
- logger.log: "Incoming call completed"
- script.wait: led_check
- script.execute: led_check
on_state:
lambda: |-
if (x) {
id(line_status).publish_state("${line_status_call}");
} else {
id(line_status).publish_state("${line_status_close}");
}
- platform: gpio
id: button_boot
pin:
number: $button_boot
mode: INPUT_PULLUP
inverted: True
on_press:
then:
switch.toggle: accept_call
on_multi_click:
- timing:
- ON for at least 5s
then:
lambda: |-
ESP_LOGW("DMF", "Erase settings and restart...");
wifi::global_wifi_component->save_wifi_sta("-----", "");
delay(500);
ESP.restart();
output:
- platform: gpio
id: relay_switch_line
pin:
number: $relay_line
mode: OUTPUT
- platform: gpio
id: open_door
pin:
number: $switch_open
mode: OUTPUT
- platform: ledc
id: indicator
pin:
number: $led_indicator
mode: OUTPUT
- platform: gpio
id: phone_up
pin:
number: $switch_phone
mode: OUTPUT
inverted: true
button:
- platform: restart
name: ${dev_name}_restart
- platform: template
name: ${dev_name}_save
id: save
icon: "mdi:content-save-cog"
entity_category: "config"
on_press:
- lambda: 'global_preferences->sync();'
switch:
- platform: template
name: ${dev_name}_delivery
id: delivery
icon: "mdi:package"
restore_mode: DISABLED
turn_on_action:
- switch.template.publish:
id: delivery
state: true
- if:
condition:
switch.is_off: accept_call
then:
switch.turn_on: accept_call
turn_off_action:
- switch.template.publish:
id: delivery
state: false
- if:
condition:
switch.is_on: accept_call
then:
lambda: 'id(status_once_mode) = 1;'
else:
lambda: 'id(status_once_mode) = 0;'
- script.wait: led_check
- script.execute: led_check
- platform: template
name: ${dev_name}_accept_call
id: accept_call
icon: "mdi:door-open"
restore_mode: DISABLED
turn_on_action:
- switch.template.publish:
id: accept_call
state: true
- if:
condition:
switch.is_on: reject_call
then:
switch.turn_off: reject_call
- logger.log: "Accept call switch is ON"
- if:
condition:
switch.is_on: delivery
then:
lambda: 'id(status_once_mode) = 2;'
else:
lambda: 'id(status_once_mode) = 1;'
- script.wait: led_check
- script.execute: led_check
- if:
condition:
lambda: 'return id(status_line);'
then:
- logger.log: "Execute action script"
- script.execute: state_call
else:
- logger.log: "No incoming call. One-time mode is set."
turn_off_action:
- switch.template.publish:
id: accept_call
state: false
- if:
condition:
switch.is_on: delivery
then:
switch.turn_off: delivery
- lambda: 'id(status_once_mode) = 0;'
- script.wait: led_check
- script.execute: led_check
- platform: template
name: ${dev_name}_reject_call
id: reject_call
icon: "mdi:phone-hangup"
restore_mode: DISABLED
turn_on_action:
- switch.template.publish:
id: reject_call
state: true
- if:
condition:
switch.is_on: accept_call
then:
- switch.turn_off: accept_call
- lambda: 'id(status_once_mode) = 3;'
- script.wait: led_check
- script.execute: led_check
- if:
condition:
lambda: 'return id(status_line);'
then:
- logger.log: "Execute action script"
- script.execute: state_call
else:
- logger.log: "No incoming call. One-time mode is set."
turn_off_action:
- switch.template.publish:
id: reject_call
state: false
- lambda: 'id(status_once_mode) = 0;'
- script.wait: led_check
- script.execute: led_check
- platform: template
name: ${dev_name}_mute
id: mute
icon: "mdi:bell-off"
entity_category: "config"
restore_mode: DISABLED
turn_on_action:
- switch.template.publish:
id: mute
state: true
- lambda: 'id(status_mute) = true;'
- script.wait: led_check
- script.execute: led_check
turn_off_action:
- switch.template.publish:
id: mute
state: false
- lambda: 'id(status_mute) = false;'
- script.wait: led_check
- script.execute: led_check
- platform: template
name: ${dev_name}_phone_disable
id: phone_disable
icon: "mdi:phone-off"
entity_category: "config"
restore_mode: DISABLED
turn_on_action:
- switch.template.publish:
id: phone_disable
state: true
- lambda: 'id(status_phone_disable) = true;'
- if:
condition:
lambda: 'return id(status_line) == false;'
then:
output.turn_on: relay_switch_line
turn_off_action:
- switch.template.publish:
id: phone_disable
state: false
- lambda: 'id(status_phone_disable) = false;'
- if:
condition:
lambda: 'return id(status_line) == false;'
then:
output.turn_off: relay_switch_line
- platform: template
name: ${dev_name}_led
id: led
icon: "mdi:led-on"
entity_category: "config"
restore_mode: DISABLED
turn_on_action:
- switch.template.publish:
id: led
state: true
- lambda: 'id(status_leding) = true;'
- script.wait: led_check
- script.execute: led_check
turn_off_action:
- switch.template.publish:
id: led
state: false
- lambda: 'id(status_leding) = false;'
- script.wait: led_check
- script.execute: led_check
- platform: template
name: ${dev_name}_sound
id: sound
icon: "mdi:volume-high"
entity_category: "config"
restore_mode: DISABLED
turn_on_action:
- switch.template.publish:
id: sound
state: true
- lambda: 'id(status_sound) = true;'
turn_off_action:
- switch.template.publish:
id: sound
state: false
- lambda: 'id(status_sound) = false;'
- platform: template
name: ${dev_name}_greeting
id: greeting
icon: "mdi:hand-wave"
entity_category: "config"
restore_mode: DISABLED
turn_on_action:
- switch.template.publish:
id: greeting
state: true
- lambda: 'id(status_greeting) = true;'
turn_off_action:
- switch.template.publish:
id: greeting
state: false
- lambda: 'id(status_greeting) = false;'