-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlock_321_notrun.yaml
731 lines (691 loc) · 21.4 KB
/
lock_321_notrun.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
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
substitutions:
device_name: test-lock32
entity_name: test_lock32
friendly_name: test lock32
device_name_wifi: testlock32
#========================================================================================================================
#pinout_mapping ESP32
i2c_sda_pin: GPIO21 # Пин sda для работы с шиной I2C магнитного энкодера AS560
i2c_scl_pin: GPIO22 # Пин scl для работы с шиной I2C магнитного энкодера AS560
as5600_dir_pin: GPIO23 # Пин dir магнитного энкодера AS5600
a4988_step_pin: GPIO14 # Пин step драйвера шагового двигателя a4988 (TMC2209 V3.0)
a4988_dir_pin: GPIO27 # Пин dir драйвера шагового двигателя a4988 (TMC2209 V3.0)
a4988_sleep_pin: GPIO4 # Пин sleep драйвера шагового двигателя a4988 (TMC2209 V3.0)
grow_sensing_pin: GPIO18 # пин wakeup сканера отпечатков
door_pos_pin: GPIO32 # пин датчика (геркона) положения двери открыто/закрыто
key_out_pin: GPIO33 # пин сенсорной кнопки открытия замка
dfplayer_tx_pin: GPIO17 # пин RX DF-плеера
dfplayer_rx_pin: GPIO16 # пин TX DF-плеера
finger_grow_tx_pin: GPIO1 # пин RX сканера отпечатков
finger_grow_rx_pin: GPIO3 # пин TX сканера отпечатков
#========================================================================================================================
uart:
- id: player
tx_pin: $dfplayer_tx_pin # пин RX DF-плеера
rx_pin: $dfplayer_rx_pin: # пин TX DF-плеера
baud_rate: 9600
- id: finger_grow
tx_pin: $finger_grow_tx_pin # пин RX сканера отпечатков
rx_pin: $finger_grow_rx_pin # пин TX сканера отпечатков
baud_rate: 57600
#========================================================================================================================
esphome:
name: ${device_name}
name_add_mac_suffix: false
esp32:
board: esp32dev
framework:
type: esp-idf
version: recommended
logger:
api:
reboot_timeout: 50min
#encryption:
# key: !secret api_password
#===============================================================================
actions:
- action: dfplayer_play_mp3
variables:
file: int
then:
- dfplayer.play_mp3:
file: !lambda 'return file;'
- action: dfplayer_set_volume
variables:
volume: int
then:
- dfplayer.set_volume: !lambda 'return volume;'
- action: dfplayer_set_eq
variables:
preset: int
then:
- dfplayer.set_eq: !lambda 'return static_cast<dfplayer::EqPreset>(preset);'
- action: dfplayer_reset
then:
- dfplayer.reset
- action: dfplayer_volume_up
then:
- dfplayer.volume_up
- action: dfplayer_volume_down
then:
- dfplayer.volume_down
#===============================================================================
# API for fingerprint GROW
- action: enroll
variables:
finger_id: int
num_scans: int
then:
- dfplayer.play_mp3:
file: 5
- delay: 3s
- dfplayer.play_mp3:
file: 3
- fingerprint_grow.enroll:
finger_id: !lambda 'return finger_id;'
num_scans: !lambda 'return num_scans;'
- action: cancel_enroll
then:
- fingerprint_grow.cancel_enroll:
- action: delete
variables:
finger_id: int
then:
- fingerprint_grow.delete:
finger_id: !lambda 'return finger_id;'
- action: delete_all
then:
- fingerprint_grow.delete_all:
ota:
platform: esphome
password: !secret ota_password
safe_mode:
reboot_timeout: 50min
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: on
reboot_timeout: 50min
ap:
ssid: ${device_name_wifi}
#password: !secret wifi_ap_password
#========================================================================================================================
i2c:
sda: $i2c_sda_pin
scl: $i2c_scl_pin
scan: true
id: bus_a
as5600:
id: my_as5600
dir_pin: $as5600_dir_pin
start_position: 0deg
range: 360deg
globals:
- id: full_cycle
type: int
restore_value: yes
initial_value: '0'
- id: prev_angle
type: int
restore_value: yes
initial_value: '0'
- id: press_button_out
type: bool
restore_value: no
initial_value: 'false'
button:
- platform: template
name: "Full Cycle Reset"
id: full_cycle_reset
on_press:
- lambda: |-
id(full_cycle) = 0;
#===============================================================================
captive_portal:
stepper:
- platform: a4988
id: my_stepper
step_pin:
number: $a4988_step_pin
# ignore_strapping_warning: true
dir_pin:
number: $a4988_dir_pin
inverted: true
allow_other_uses: true
sleep_pin:
number: $a4988_sleep_pin
inverted: true
# ignore_strapping_warning: true
max_speed: 2550 steps/s
number:
- platform: template
name: Position stepper
optimistic: true
min_value: 0
id: number_pos
max_value: 9000
step: 0.5
set_action:
then:
- stepper.set_target:
id: my_stepper
target: !lambda return x;
#===============================================================================
time: # Время берем из Home Assistant
- platform: homeassistant
id: homeassistant_time
#===============================================================================
#===============================================================================
# DFPLAYER
#===============================================================================
dfplayer:
uart_id: player
id: player_lock
# on_finished_playback:
# then:
# logger.log: 'Somebody press play!'
#===============================================================================
# FINGER GROW
#===============================================================================
fingerprint_grow:
sensing_pin:
number: $grow_sensing_pin
allow_other_uses: true
uart_id: finger_grow
on_finger_scan_matched: # палец распознан
- fingerprint_grow.aura_led_control:
state: FLASHING
speed: 25
color: GREEN
count: 5
- delay: 1s
- lock.unlock: Gimdow #открываем замок
- delay: 1s
- text_sensor.template.publish:
id: fingerprint_state
state: !lambda 'return "Finger " + to_string(finger_id) + ", confidence " + to_string(confidence);'
- if:
condition:
lambda: 'return confidence > 50;'
then:
- homeassistant.tag_scanned: !lambda |-
switch (finger_id) {
case 0:
return "Person 1";
case 1:
return "Person 2";
default:
return "person_unknown";
}
- binary_sensor.template.publish: # включаем сеснор о правильном распозновании
id: success_scanned
state: ON
# - delay: 2s
- script.execute: breathing_light
on_finger_scan_unmatched: # палец не распознан
- text_sensor.template.publish:
id: fingerprint_state
state: "Unauthorized finger"
# - dfplayer.play_mp3:
# file: 2
- fingerprint_grow.aura_led_control:
state: FLASHING
speed: 25
color: RED
count: 5
- delay: 1s
- script.execute: breathing_light
on_enrollment_scan: # запись пальца в память
- text_sensor.template.publish:
id: fingerprint_state
state: "Finger scanned"
- fingerprint_grow.aura_led_control:
state: FLASHING
speed: 25
color: Green
count: 3
- fingerprint_grow.aura_led_control:
state: ALWAYS_ON
speed: 0
color: PURPLE
count: 0
- if:
condition:
lambda: 'return scan_num < 5;'
then:
- dfplayer.play_mp3:
file: 7
on_enrollment_done: # запись пальца прошла успешно
- text_sensor.template.publish:
id: fingerprint_state
state: "Enrolled fingerprint"
- dfplayer.play_mp3:
file: 4
- fingerprint_grow.aura_led_control:
state: FLASHING
speed: 15
color: GREEN
count: 3
- delay: 2s
- script.execute: breathing_light
on_enrollment_failed: # неудачная запись пальца
- text_sensor.template.publish:
id: fingerprint_state
state: "Failed to enroll fingerprint"
- fingerprint_grow.aura_led_control:
state: FLASHING
speed: 25
color: RED
count: 4
- dfplayer.play_mp3:
file: 6
- delay: 2s
- script.execute: breathing_light
#===============================================================================
# SENSOR
#===============================================================================
#-------------------------------------------------------------------------------
# Optional template text sensor for visual feedback
text_sensor:
- platform: template
id: fingerprint_state
name: "Fingerprint State"
#-------------------------------------------------------------------------------
sensor:
- platform: uptime # Время работы после последней перезагрузки
name: "uptime_${device_name}"
#===============================================================================
- platform: as5600
update_interval: 100ms
name: Angle
id: angle
unit_of_measurement: °
accuracy_decimals: 0
icon: mdi:rotate-right
out_of_range_mode: nan
filters:
- delta: 1
- lambda:
uint16_t deg = (uint16_t)floor(x * as5600::RAW_TO_DEGREES * id(my_as5600).get_range_scale());
return deg % 360;
on_value:
then:
- lambda: |-
if (((id(prev_angle) > 310 && x < 50) || (id(prev_angle) < x)) && !(id(prev_angle) < 50 && x > 310))
id(full_cycle) += (id(prev_angle) > x ? 359 - id(prev_angle) + x : x - id(prev_angle));
else if ((id(prev_angle) < 50 && x > 310) || (id(prev_angle) > x))
id(full_cycle) -= (id(prev_angle) < x ? 359 - x + id(prev_angle) : id(prev_angle) - x);
id(prev_angle) = x;
- platform: template
update_interval: 100ms
name: "Full cycle"
lambda: |-
return id(full_cycle);
- platform: template
update_interval: 100ms
name: "Position MAP"
id: position_map
lambda: |-
return 9000 - min(9000, max(0, (int)remap(id(full_cycle), 0, 2018, 0, 9000)));
#===============================================================================
- platform: as5600
update_interval: 100ms
name: Position
filters:
- delta: 1
raw_position:
name: Raw Position
filters:
- delta: 1
gain:
name: Gain
filters:
- delta: 1
magnitude:
name: Magnitude
filters:
- delta: 1
status:
name: Status
filters:
- delta: 1
#===============================================================================
binary_sensor:
# ----------------------------
# sensors fingerprint
- platform: fingerprint_grow
id: fingerprint_enrolling
name: "Fingerprint Enrolling"
on_state:
then:
- fingerprint_grow.aura_led_control:
state: ALWAYS_ON
speed: 0
color: PURPLE
count: 0
# ----------------------------
- platform: template # сенсор удачного распознавания пальца
name: success_scanned
id: success_scanned
icon: mdi:line-scan
on_state:
then:
- delay: 5 s
- binary_sensor.template.publish:
id: success_scanned
state: OFF
# - platform: template # звонок
# name: zvonok
# id: zvonok
# icon: mdi:bell-ring
# on_state:
# then:
# - delay: 5 s
# - binary_sensor.template.publish:
# id: zvonok
# state: OFF
- platform: status
name: "${device_name}_status"
- platform: gpio # сенсор прикосновения к сканеру
filters:
- delayed_on: 10ms
- invert:
pin:
number: $grow_sensing_pin
allow_other_uses: true
id: Finger_touch
name: "Finger touch"
icon: mdi:gesture-tap
on_press:
then:
- if: # включаем звонок
condition:
- binary_sensor.is_off: fingerprint_enrolling
then:
- fingerprint_grow.aura_led_control:
state: ALWAYS_ON
speed: 0
color: YELLOW
count: 0
on_release:
then:
- script.execute: breathing_light
- platform: gpio # геркон закрытия двери
name: "Door sensor"
id: Door_sensor
device_class: door
filters:
- delayed_on: 200ms
- delayed_off: 500ms
pin:
number: $door_pos_pin
mode: INPUT_PULLUP
on_state:
then:
- script.execute: breathing_light
- if:
condition:
and:
- binary_sensor.is_off: Door_sensor
- lambda: 'return id(press_button_out);'
then:
- delay: 0.5s
- lock.lock: Gimdow #закрываем замок
- delay: 0.5s
- globals.set:
id: press_button_out
value: "false"
# ------------------
# - platform: gpio
# pin:
# number: GPIO27
# mode:
# input: true
# pulldown: true
# pullup: True
# id: button_out
# name: "button_out"
# filters:
# - delayed_on: 200ms
# on_state:
# then:
# - if:
# condition:
# - binary_sensor.is_on: button_out
# then:
# - script.execute: locking_door_button
# - dfplayer.play_mp3:
# file: 8
- platform: gpio
pin:
number: $key_out_pin
allow_other_uses: true
mode:
input: true
pulldown: true
id: button_out_light
name: "button_out_light"
filters:
- delayed_on: 200ms
on_state:
then:
- if:
condition:
- binary_sensor.is_on: button_out_light
then:
- script.execute: locking_door_button
- dfplayer.play_mp3:
file: 8
# - platform: gpio
# pin:
# number: GPIO27
# mode:
# input: true
# pulldown: true
# pullup: True
# id: button_out
# name: "button_out"
# filters:
# - delayed_on: 200ms
# on_state:
# then:
# - if:
# condition:
# - binary_sensor.is_on: button_out
# then:
# - script.execute: locking_door_button
# - dfplayer.play_mp3:
# file: 8
#- platform: gpio
# pin:
# number: GPIO12
# allow_other_uses: true
# mode:
# input: true
# pulldown: true
# id: button_out_light_new
# name: "button_out_light_new"
# filters:
# - delayed_on: 200ms
# on_state:
# then:
# - if:
# condition:
# - binary_sensor.is_on: button_out_light_new
# then:
# - script.execute: locking_door_button
# - dfplayer.play_mp3:
# file: 8
#- platform: gpio # вход бинарного датчика открытия замка
# id: Lock_sensor
# name: "Lock sensor"
# filters:
# - delayed_on: 200ms
# pin:
# number: 33
# mode: INPUT_PULLUP
# allow_other_uses: true
# on_state:
# then:
# - script.execute: breathing_light_zamok
# ----------------------------
#===============================================================================
lock:
- platform: template
name: Lock
optimistic: true
lambda: |-
if (id(position_map).state < 1)
{
return LOCK_STATE_UNLOCKED;
}
else
{
return LOCK_STATE_LOCKED;
}
lock_action:
- stepper.report_position:
id: my_stepper
position: !lambda |-
return id(position_map).state;
- stepper.set_target:
id: my_stepper
target: 9000
unlock_action:
- stepper.report_position:
id: my_stepper
position: !lambda |-
return id(position_map).state;
- stepper.set_target:
id: my_stepper
target: 0
# lock: # кнопки открытия/закрытия Gimdow с датчиком замка двери из ХА
- platform: template
name: Gimdow
id: Gimdow
optimistic: true
assumed_state: false
lock_action:
- switch.turn_on: gate
- delay: 300ms
- switch.turn_off: gate
unlock_action:
- switch.turn_on: gate
- delay: 200ms
- switch.turn_off: gate
- delay: 100ms
- switch.turn_on: gate
- delay: 200ms
- switch.turn_off: gate
lambda: |-
if (id(Lock_sensor).state) {
return LOCK_STATE_UNLOCKED;
} else {
return LOCK_STATE_LOCKED;
}
#===============================================================================
# SCRIPT
#===============================================================================
script: #режим светодиода в зависимости от замка двери для возвращения значения после операций
- id: breathing_light
mode: restart
then:
- if:
condition:
- binary_sensor.is_off: Lock_sensor
then:
- fingerprint_grow.aura_led_control:
state: BREATHING
speed: 255
color: BLUE
count: 0
- if:
condition:
and:
- binary_sensor.is_on: Lock_sensor
- binary_sensor.is_off: Door_sensor
then:
- fingerprint_grow.aura_led_control:
state: BREATHING
speed: 255
color: GREEN
count: 0
- if:
condition:
- binary_sensor.is_on: Door_sensor
then:
- fingerprint_grow.aura_led_control:
state: BREATHING
speed: 255
color: WHITE
count: 0
#действие после нажатия кнопки на панели
- id: locking_door_button
mode: restart
then:
- globals.set:
id: press_button_out
value: "true"
- if:
condition:
- binary_sensor.is_off: Lock_sensor
then:
- lock.unlock: Gimdow #открываем замок
- delay: 1s
- if:
condition:
and:
- binary_sensor.is_on: Lock_sensor
- binary_sensor.is_off: Door_sensor
then:
- lock.lock: Gimdow #закрываем замок
- delay: 0.5s
- wait_until:
condition:
not:
- lambda: 'return id(press_button_out);'
timeout: 5min
- if:
condition:
and:
- lambda: 'return id(press_button_out);'
- binary_sensor.is_off: Door_sensor
then:
- lock.lock: Gimdow #закрываем замок
- delay: 0.5s
- globals.set:
id: press_button_out
value: "false"
- id: breathing_light_zamok #режим светодиода в зависимости от замка двери только для самого замка
then:
if:
condition:
- binary_sensor.is_off: Lock_sensor
then:
- fingerprint_grow.aura_led_control:
state: FLASHING
speed: 35
color: GREEN
count: 1
- fingerprint_grow.aura_led_control:
state: BREATHING
speed: 255
color: CYAN
count: 0
else:
- fingerprint_grow.aura_led_control:
state: FLASHING
speed: 35
color: GREEN
count: 1
- fingerprint_grow.aura_led_control:
state: BREATHING
speed: 85
color: CYAN
count: 0
#switch: # выход на управление брелком замка
# - platform: gpio
# pin: GPIO27
# inverted: true
# id: gate
# name: "Switch gate close"