Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- substitutions:
- esp_devicename: Pad OLED Allarme
- deviceidname: pad-oled-allarme
- esphome:
- name: pad-oled-allarme
- friendly_name: Pad OLED Allarme
- esp32:
- board: esp32dev
- framework:
- type: arduino
- captive_portal:
- logger:
- baud_rate: 0
- ota:
- password: "24245800"
- web_server:
- port: 80
- wifi:
- ssid: "LAN SOLO"
- password: !secret wifi_password
- manual_ip:
- static_ip: 192.168.178.144
- gateway: 192.168.178.1
- subnet: 255.255.255.0
- ap:
- ssid: "${esp_devicename} Fallback AP"
- password: !secret wifi_password
- api:
- encryption:
- key: "2vY7511Y3laolOH/mo9Qx9I="
- services:
- - service: enroll
- variables:
- finger_id: int
- num_scans: int
- then:
- - fingerprint_grow.enroll:
- finger_id: !lambda 'return finger_id;'
- num_scans: !lambda 'return num_scans;'
- - service: cancel_enroll
- then:
- - fingerprint_grow.cancel_enroll:
- - service: delete
- variables:
- finger_id: int
- then:
- - fingerprint_grow.delete:
- finger_id: !lambda 'return finger_id;'
- - service: delete_all
- then:
- - fingerprint_grow.delete_all:
- ################################################################################
- ## FONT
- ################################################
- font:
- - file: 'arial.ttf'
- id: font1
- size: 18
- - file: 'arial_bold.ttf'
- id: font2
- size: 24
- - file: 'arial.ttf'
- id: font3
- size: 36
- - file: 'arial.ttf'
- id: font4
- size: 28
- image:
- - file: mdi:shield-lock-outline
- id: alert
- resize: 25x25
- - file: mdi:shield-home
- id: alert_off
- resize: 75x75
- - file: mdi:thumb-up
- id: ok
- resize: 30x30
- ################################################################################
- ## I2C
- ################################################
- i2c:
- sda: GPIO21
- scl: GPIO22
- ################################################################################
- ## UART
- ################################################
- uart:
- rx_pin: GPIO17
- tx_pin: GPIO16
- baud_rate: 57600
- ################################################################################
- ## FINGERPRINT
- ################################################
- fingerprint_grow:
- sensing_pin: GPIO12
- on_finger_scan_matched:
- - if:
- condition:
- lambda: 'return confidence > 89;'
- then:
- - homeassistant.tag_scanned: !lambda |-
- switch (finger_id) {
- case 1:
- return "Francesco";
- case 2:
- return "Simona";
- case 3:
- return "Gaia";
- default:
- return "Sconosciuto";
- }
- - display.page.show: page3
- - text_sensor.template.publish:
- id: fingerprint_state
- state: !lambda |-
- switch (finger_id) {
- case 1:
- return "Francesco";
- case 2:
- return "Simona";
- default:
- return "Autorizzato";
- }
- - fingerprint_grow.aura_led_control:
- state: BREATHING
- speed: 40
- color: GREEN
- count: 2
- - rtttl.play: 'two_short:d=32,o=8,b=100:32e6,40e6'
- - delay: 1000ms
- - text_sensor.template.publish:
- id: fingerprint_state
- state: "Attesa"
- - display.page.show: page1
- - if:
- condition:
- lambda: 'return confidence < 90;'
- then:
- - display.page.show: page5
- - fingerprint_grow.aura_led_control:
- state: FLASHING
- speed: 30
- color: PURPLE
- count: 4
- - rtttl.play: 'two_short:d=32,o=8,b=100:32e6'
- - delay: 1000ms
- - text_sensor.template.publish:
- id: fingerprint_state
- state: "Attesa"
- - display.page.show: page1
- on_finger_scan_unmatched:
- - text_sensor.template.publish:
- id: fingerprint_state
- state: "Impronta non autorizzata"
- - fingerprint_grow.aura_led_control:
- state: FLASHING
- speed: 25
- color: RED
- count: 3
- - switch.turn_on: buzzer_error
- - delay: 500ms
- - switch.turn_off: buzzer_error
- on_enrollment_scan:
- - text_sensor.template.publish:
- id: fingerprint_state
- state: "Impronta acquisita"
- - fingerprint_grow.aura_led_control:
- state: FLASHING
- speed: 25
- color: WHITE
- count: 2
- - fingerprint_grow.aura_led_control:
- state: ALWAYS_ON
- speed: 0
- color: YELLOW
- count: 0
- on_enrollment_failed:
- - text_sensor.template.publish:
- id: fingerprint_state
- state: "Acquisizione impronta fallita"
- - fingerprint_grow.aura_led_control:
- state: FLASHING
- speed: 25
- color: RED
- count: 4
- ################################################################################
- ## PAD
- ################################################
- matrix_keypad:
- id: mykeypad
- rows:
- - pin: GPIO19
- - pin: GPIO33
- - pin: GPIO25
- - pin: GPIO26
- columns:
- - pin: GPIO27
- - pin: GPIO13
- - pin: GPIO5
- keys: "123456789*0#"
- has_diodes: false
- ################################################################################
- ## Key Collector
- ################################################
- key_collector:
- - id: pincode_reader
- source_id: mykeypad
- min_length: 1
- max_length: 4
- back_keys: "*"
- end_key_required: false
- clear_keys: "#"
- allowed_keys: "0124578"
- timeout: 4s
- on_progress:
- - logger.log:
- format: "input progress: '%s', started by '%c'"
- args: [ 'x.c_str()', "(start == 0 ? '~' : start)" ]
- - text_sensor.template.publish:
- id: keypadp
- state: !lambda "return x.c_str();"
- on_result:
- then:
- - logger.log:
- format: "input result: '%s', started by '%c', ended by '%c''x.c_str()'"
- args: [ 'x.c_str()', "(start == 0 ? '~' : start)", "(end == 0 ? '~' : end)" ]
- - text_sensor.template.publish:
- id: keypad
- state: !lambda "return x.c_str();"
- - delay: 2s
- - text_sensor.template.publish:
- id: keypad
- state: ""
- - id: pincode_reader2
- source_id: mykeypad
- min_length: 1
- max_length: 4
- back_keys: "*"
- end_key_required: false
- clear_keys: "#"
- allowed_keys: "0124578"
- timeout: 4s
- on_progress:
- - script.stop: timer
- - script.execute: timer
- - if:
- condition:
- lambda: 'return id(page).state != "1";'
- then:
- - text_sensor.template.publish:
- id: page
- state: "2"
- - display.page.show: page2
- - text_sensor.template.publish:
- id: page
- state: "2"
- - switch.turn_on: buzzer
- - delay: 100ms
- - switch.turn_off: buzzer
- - logger.log:
- format: "input progress: '%s', started by '%c'"
- args: [ 'x.c_str()', "(start == 0 ? '~' : start)" ]
- - text_sensor.template.publish:
- id: kpad
- state: !lambda "return std::string(x.length(), 'x').c_str();"
- on_result:
- - script.stop: timer
- - text_sensor.template.publish:
- id: kpad
- state: ""
- - if:
- condition:
- lambda: 'return id(allarme_scattato).state == "on";'
- then:
- - display.page.show: page4
- else:
- - display.page.show: page1
- - text_sensor.template.publish:
- id: page
- state: "1"
- on_timeout:
- - script.stop: timer
- - logger.log:
- format: "input timeout: '%s', started by '%c'"
- args: [ 'x.c_str()', "(start == 0 ? '~' : start)" ]
- - text_sensor.template.publish:
- id: kpad
- state: !lambda "return x.c_str();"
- - if:
- condition:
- lambda: 'return id(allarme_scattato).state == "on";'
- then:
- - display.page.show: page4
- else:
- - display.page.show: page1
- - text_sensor.template.publish:
- id: page
- state: "1"
- ################################################################################
- ## Script
- ################################################
- script:
- id: timer
- then:
- - delay: 4s
- - if:
- condition:
- lambda: 'return id(allarme_scattato).state == "on";'
- then:
- - display.page.show: page4
- else:
- - display.page.show: page1
- ################################################################################
- ## Display
- ################################################
- display:
- - platform: ssd1306_i2c
- model: "SSD1306 128x64"
- reset_pin: GPIO23
- address: 0x3C
- id: my_display
- pages:
- - id: page1
- lambda: |-
- it.clear();
- it.printf(64, 3, id(font1), TextAlign::TOP_CENTER, "Allarme");
- it.image(2, 2, id(alert));
- it.line(1, 0, 124, 0);
- it.line(1, 63, 124, 63);
- it.line(0, 1, 0, 62);
- it.line(125, 1, 125, 62);
- if (id(alarm_state).state.length() == 0) {
- it.printf(64, 24, id(font2), TextAlign::TOP_CENTER, "Starting");
- } else if (id(alarm_state).state == "Attivo") {
- it.printf(64, 24, id(font2), TextAlign::TOP_CENTER, id(alarm_state).state.c_str());
- } else if (id(alarm_state).state == "...Avvio") {
- it.printf(64, 24, id(font2), TextAlign::TOP_CENTER, id(alarm_state).state.c_str());
- } else if (id(alarm_state).state == "Disattivato") {
- it.clear();
- } else {
- it.clear();
- }
- - id: page2
- lambda: |-
- it.printf(64, 10, id(font3), TextAlign::TOP_CENTER, id(kpad).state.c_str());
- - id: page3
- lambda: |-
- it.image(50, 2, id(ok));
- it.printf(64, 30, id(font4), TextAlign::TOP_CENTER, id(fingerprint_state).state.c_str());
- - id: page4
- lambda: |-
- it.clear();
- it.printf(64, 3, id(font1), TextAlign::TOP_CENTER, "Allarme");
- static bool flashText = false;
- flashText = !flashText;
- if (flashText) {
- it.printf(64, 24, id(font2), TextAlign::TOP_CENTER, "Scattato");
- }
- it.image(2, 2, id(alert));
- it.line(1, 0, 124, 0);
- it.line(1, 63, 124, 63);
- it.line(0, 1, 0, 62);
- it.line(125, 1, 125, 62);
- - id: page5
- lambda: |-
- it.printf(64, 3, id(font1), TextAlign::TOP_CENTER, "Poggia");
- it.printf(64, 30, id(font4), TextAlign::TOP_CENTER, "Meglio");
- ################################################################################
- ## Text Sensor
- ################################################
- text_sensor:
- - platform: homeassistant
- entity_id: sensor.stato_allarme_pad_oled
- name: "Stato Allarme"
- id: alarm_state
- - platform: homeassistant
- entity_id: sensor.stato_allarme
- name: "Stato Allarme"
- id: allarme
- - platform: homeassistant
- name: "Allarme Scattato"
- entity_id: input_boolean.allarme_scattato
- id: allarme_scattato
- internal: true
- - platform: homeassistant
- name: "input"
- id: input
- entity_id: sensor.pad_oled_allarme_keypad_code
- internal: true
- - platform: homeassistant
- name: "error"
- id: error
- entity_id: sensor.counter_code_error
- internal: true
- - platform: wifi_info
- ip_address:
- name: "${esp_devicename} IP"
- icon: "mdi:lan"
- - platform: template
- name: "Keypad code"
- id: keypad
- - platform: template # Visualizza i numeri sul display
- name: "Keypad OLED"
- id: kpad
- internal: true
- - platform: template
- name: "page"
- id: page
- internal: true
- - platform: template
- id: fingerprint_state
- name: "Stato impronta"
- - platform: template
- name: "Keypad code test"
- id: keypadp
- ################################################################################
- ## SENSOR
- ################################################
- sensor:
- - platform: wifi_signal
- name: "${esp_devicename} WiFi Signal"
- update_interval: 10s
- - platform: fingerprint_grow
- fingerprint_count:
- name: "Conta impronte"
- last_finger_id:
- name: "Ultimo ID impronta"
- last_confidence:
- name: "Affidabilità ultima impronta"
- status:
- name: "Stato impronta"
- capacity:
- name: "Capacità impronta"
- security_level:
- name: "Livello di sicurezza"
- ################################################################################
- ## Binary Sensor
- ################################################
- binary_sensor:
- - platform: fingerprint_grow
- id: fingerprint_enrolling
- name: "Acquisendo impronta"
- - platform: template # Allarme Disattivato
- name: "Allarme Disattivato"
- internal: true
- lambda: |-
- if (id(alarm_state).state == "Disattivato") {
- return true;
- } else {
- return false;
- }
- on_press:
- - while:
- condition:
- lambda: |-
- if (id(alarm_state).state == "Disattivato") {
- return true;
- } else {
- return false;
- }
- then:
- - output.turn_on: led_blu
- - delay: 50ms
- - output.turn_off: led_blu
- - delay: 3s
- - platform: template # Allarme Scattato LED
- name: "Allarme Scattato"
- internal: true
- lambda: |-
- if (id(allarme_scattato).state == "on") {
- return true;
- } else {
- return false;
- }
- on_press:
- - while:
- condition:
- lambda: |-
- if (id(allarme_scattato).state == "on") {
- return true;
- } else {
- return false;
- }
- then:
- - output.turn_on: led_blu
- - delay: 300ms
- - output.turn_off: led_blu
- - output.turn_on: led_rosso
- - delay: 300ms
- - output.turn_off: led_rosso
- - platform: template # Allarme Attivo
- name: "Allarme Attivo"
- internal: true
- lambda: |-
- if (id(alarm_state).state == "Attivo") {
- return true;
- } else {
- return false;
- }
- on_press:
- - while:
- condition:
- lambda: |-
- if (id(alarm_state).state == "Attivo") {
- return true;
- } else {
- return false;
- }
- then:
- - output.turn_on: led_rosso
- - delay: 80ms
- - output.turn_off: led_rosso
- - delay: 80ms
- - output.turn_on: led_rosso
- - delay: 80ms
- - output.turn_off: led_rosso
- - delay: 3s
- - platform: template # Allarme Pedding
- name: "Allarme Pedding"
- internal: true
- lambda: |-
- if (id(alarm_state).state == "...Avvio") {
- return true;
- } else {
- return false;
- }
- on_press:
- - while:
- condition:
- lambda: |-
- if (id(alarm_state).state == "...Avvio") {
- return true;
- } else {
- return false;
- }
- then:
- - output.turn_on: led_giallo
- - delay: 500ms
- - output.turn_off: led_giallo
- - delay: 500ms
- - platform: template # Allarme Scattato
- name: "Allarme Scat"
- internal: true
- lambda: |-
- if (id(allarme_scattato).state == "on") {
- return true;
- } else {
- return false;
- }
- on_press:
- then:
- - display.page.show: page4
- on_release:
- then:
- - display.page.show: page1
- ################################################################################
- ## OUTPUT
- ################################################
- output:
- - platform: ledc
- pin: GPIO15
- id: buzzer_output
- - platform: ledc
- id: led_verde
- pin: GPIO19
- - platform: ledc
- id: led_giallo
- pin: GPIO18
- - platform: ledc
- id: led_rosso
- pin: GPIO4
- - platform: ledc
- id: led_blu
- pin: GPIO2
- ################################################################################
- ## RTTTL
- ################################################
- rtttl:
- output: buzzer_output
- ################################################################################
- ## Switch
- ################################################
- switch:
- - platform: output
- internal: true
- name: 'buzzer'
- id: buzzer
- output: buzzer_output
- on_turn_on:
- then:
- - output.turn_on: buzzer_output
- - output.ledc.set_frequency:
- id: buzzer_output
- frequency: "2000Hz"
- - output.set_level:
- id: buzzer_output
- level: "90%"
- on_turn_off:
- then:
- - output.turn_off: buzzer_output
- - platform: output
- internal: true
- name: 'buzzer error'
- id: buzzer_error
- output: buzzer_output
- on_turn_on:
- then:
- - output.turn_on: buzzer_output
- - output.ledc.set_frequency:
- id: buzzer_output
- frequency: "200Hz"
- - output.set_level:
- id: buzzer_output
- level: "90%"
- on_turn_off:
- then:
- - output.turn_off: buzzer_output
- - platform: restart
- name: "Restart Pad"
- id: restart_switch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement