Advertisement
calas

Pad_OLED

Oct 7th, 2023 (edited)
1,550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 18.22 KB | None | 0 0
  1. substitutions:
  2.   esp_devicename: Pad OLED Allarme
  3.   deviceidname: pad-oled-allarme
  4.  
  5. esphome:
  6.   name: pad-oled-allarme
  7.   friendly_name: Pad OLED Allarme
  8.  
  9. esp32:
  10.   board: esp32dev
  11.   framework:
  12.     type: arduino
  13.  
  14. captive_portal:
  15. logger:
  16.   baud_rate: 0
  17.  
  18. ota:
  19.   password: "24245800"
  20.  
  21. web_server:
  22.   port: 80
  23.  
  24. wifi:
  25.   ssid: "LAN SOLO"
  26.   password: !secret wifi_password
  27.   manual_ip:
  28.     static_ip: 192.168.178.144
  29.     gateway: 192.168.178.1
  30.     subnet: 255.255.255.0
  31.  
  32.   ap:
  33.     ssid: "${esp_devicename} Fallback AP"
  34.     password: !secret wifi_password
  35.  
  36. api:
  37.   encryption:
  38.     key: "2vY7511Y3laolOH/mo9Qx9I="
  39.   services:
  40.   - service: enroll
  41.     variables:
  42.       finger_id: int
  43.       num_scans: int
  44.     then:
  45.       - fingerprint_grow.enroll:
  46.           finger_id: !lambda 'return finger_id;'
  47.           num_scans: !lambda 'return num_scans;'
  48.   - service: cancel_enroll
  49.     then:
  50.       - fingerprint_grow.cancel_enroll:
  51.   - service: delete
  52.     variables:
  53.       finger_id: int
  54.     then:
  55.       - fingerprint_grow.delete:
  56.           finger_id: !lambda 'return finger_id;'
  57.   - service: delete_all
  58.     then:
  59.       - fingerprint_grow.delete_all:
  60. ################################################################################
  61. ##                  FONT
  62. ################################################
  63. font:
  64.   - file: 'arial.ttf'
  65.     id: font1
  66.     size: 18
  67.  
  68.   - file: 'arial_bold.ttf'
  69.     id: font2
  70.     size: 24
  71.  
  72.   - file: 'arial.ttf'
  73.     id: font3
  74.     size: 36
  75.  
  76.   - file: 'arial.ttf'
  77.     id: font4
  78.     size: 28
  79.  
  80. image:
  81.   - file: mdi:shield-lock-outline
  82.     id: alert
  83.     resize: 25x25
  84.  
  85.   - file: mdi:shield-home
  86.     id: alert_off
  87.     resize: 75x75
  88.  
  89.   - file: mdi:thumb-up
  90.     id: ok
  91.     resize: 30x30
  92.  
  93. ################################################################################
  94. ##                  I2C
  95. ################################################
  96. i2c:
  97.   sda: GPIO21
  98.   scl: GPIO22
  99.  
  100. ################################################################################
  101. ##                  UART
  102. ################################################
  103. uart:
  104.   rx_pin: GPIO17
  105.   tx_pin: GPIO16
  106.   baud_rate: 57600
  107.  
  108. ################################################################################
  109. ##                  FINGERPRINT
  110. ################################################
  111. fingerprint_grow:
  112.   sensing_pin: GPIO12
  113.   on_finger_scan_matched:
  114.     - if:
  115.         condition:
  116.           lambda: 'return confidence > 89;'
  117.         then:
  118.           - homeassistant.tag_scanned: !lambda |-
  119.               switch (finger_id) {
  120.                 case 1:
  121.                  return "Francesco";
  122.                 case 2:
  123.                  return "Simona";
  124.                 case 3:
  125.                  return "Gaia";
  126.                 default:
  127.                  return "Sconosciuto";
  128.               }
  129.          
  130.           - display.page.show: page3
  131.          
  132.           - text_sensor.template.publish:
  133.               id: fingerprint_state
  134.               state: !lambda |-
  135.                 switch (finger_id) {
  136.                   case 1:
  137.                    return "Francesco";
  138.                   case 2:
  139.                    return "Simona";
  140.                   default:
  141.                    return "Autorizzato";
  142.                 }
  143.  
  144.           - fingerprint_grow.aura_led_control:
  145.               state: BREATHING
  146.               speed: 40
  147.               color: GREEN
  148.               count: 2
  149.  
  150.           - rtttl.play: 'two_short:d=32,o=8,b=100:32e6,40e6'
  151.           - delay: 1000ms
  152.          
  153.           - text_sensor.template.publish:
  154.               id: fingerprint_state
  155.               state: "Attesa"
  156.  
  157.           - display.page.show: page1
  158.  
  159.     - if:
  160.         condition:
  161.           lambda: 'return confidence < 90;'
  162.         then:
  163.           - display.page.show: page5
  164.          
  165.           - fingerprint_grow.aura_led_control:
  166.               state: FLASHING
  167.               speed: 30
  168.               color: PURPLE
  169.               count: 4
  170.  
  171.           - rtttl.play: 'two_short:d=32,o=8,b=100:32e6'
  172.           - delay: 1000ms
  173.          
  174.           - text_sensor.template.publish:
  175.               id: fingerprint_state
  176.               state: "Attesa"
  177.  
  178.           - display.page.show: page1
  179.  
  180.  
  181.   on_finger_scan_unmatched:
  182.     - text_sensor.template.publish:
  183.         id: fingerprint_state
  184.         state: "Impronta non autorizzata"
  185.    
  186.     - fingerprint_grow.aura_led_control:
  187.         state: FLASHING
  188.         speed: 25
  189.         color: RED
  190.         count: 3
  191.  
  192.     - switch.turn_on: buzzer_error
  193.     - delay: 500ms
  194.     - switch.turn_off: buzzer_error
  195.  
  196.   on_enrollment_scan:
  197.     - text_sensor.template.publish:
  198.         id: fingerprint_state
  199.         state: "Impronta acquisita"
  200.        
  201.     - fingerprint_grow.aura_led_control:
  202.         state: FLASHING
  203.         speed: 25
  204.         color: WHITE
  205.         count: 2
  206.     - fingerprint_grow.aura_led_control:
  207.         state: ALWAYS_ON
  208.         speed: 0
  209.         color: YELLOW
  210.         count: 0
  211.  
  212.   on_enrollment_failed:
  213.     - text_sensor.template.publish:
  214.         id: fingerprint_state
  215.         state: "Acquisizione impronta fallita"
  216.     - fingerprint_grow.aura_led_control:
  217.         state: FLASHING
  218.         speed: 25
  219.         color: RED
  220.         count: 4
  221.  
  222. ################################################################################
  223. ##                  PAD
  224. ################################################
  225. matrix_keypad:
  226.   id: mykeypad
  227.   rows:
  228.     - pin: GPIO19
  229.     - pin: GPIO33
  230.     - pin: GPIO25
  231.     - pin: GPIO26
  232.   columns:
  233.     - pin: GPIO27
  234.     - pin: GPIO13
  235.     - pin: GPIO5
  236.   keys: "123456789*0#"
  237.   has_diodes: false
  238.  
  239. ################################################################################
  240. ##                  Key Collector
  241. ################################################
  242. key_collector:
  243.   - id: pincode_reader
  244.     source_id: mykeypad
  245.     min_length: 1
  246.     max_length: 4
  247.     back_keys: "*"
  248.     end_key_required: false
  249.     clear_keys: "#"
  250.     allowed_keys: "0124578"
  251.     timeout: 4s
  252.     on_progress:
  253.       - logger.log:
  254.           format: "input progress: '%s', started by '%c'"
  255.           args: [ 'x.c_str()', "(start == 0 ? '~' : start)" ]
  256.  
  257.       - text_sensor.template.publish:
  258.           id: keypadp
  259.           state: !lambda "return x.c_str();"
  260.  
  261.     on_result:
  262.       then:
  263.        
  264.         - logger.log:
  265.             format: "input result: '%s', started by '%c', ended by '%c''x.c_str()'"
  266.             args: [ 'x.c_str()', "(start == 0 ? '~' : start)", "(end == 0 ? '~' : end)" ]
  267.  
  268.         - text_sensor.template.publish:
  269.             id: keypad
  270.             state: !lambda "return x.c_str();"  
  271.  
  272.         - delay: 2s
  273.        
  274.         - text_sensor.template.publish:
  275.             id: keypad
  276.             state: ""
  277.    
  278.   - id: pincode_reader2
  279.     source_id: mykeypad
  280.     min_length: 1
  281.     max_length: 4
  282.     back_keys: "*"
  283.     end_key_required: false
  284.     clear_keys: "#"
  285.     allowed_keys: "0124578"
  286.     timeout: 4s
  287.  
  288.     on_progress:
  289.       - script.stop: timer
  290.       - script.execute: timer
  291.  
  292.       - if:
  293.           condition:
  294.             lambda: 'return id(page).state != "1";'
  295.           then:
  296.             - text_sensor.template.publish:
  297.                 id: page
  298.                 state: "2"
  299.             - display.page.show: page2
  300.  
  301.       - text_sensor.template.publish:
  302.           id: page
  303.           state: "2"
  304.  
  305.       - switch.turn_on: buzzer
  306.       - delay: 100ms
  307.       - switch.turn_off: buzzer
  308.      
  309.       - logger.log:
  310.           format: "input progress: '%s', started by '%c'"
  311.           args: [ 'x.c_str()', "(start == 0 ? '~' : start)" ]
  312.  
  313.       - text_sensor.template.publish:
  314.           id: kpad
  315.           state: !lambda "return std::string(x.length(), 'x').c_str();"
  316.  
  317.     on_result:
  318.       - script.stop: timer
  319.       - text_sensor.template.publish:
  320.           id: kpad
  321.           state: ""
  322.  
  323.       - if:
  324.           condition:
  325.             lambda: 'return id(allarme_scattato).state == "on";'
  326.           then:
  327.             - display.page.show: page4
  328.           else:
  329.             - display.page.show: page1
  330.  
  331.       - text_sensor.template.publish:
  332.           id: page
  333.           state: "1"
  334.  
  335.     on_timeout:
  336.       - script.stop: timer
  337.       - logger.log:
  338.           format: "input timeout: '%s', started by '%c'"
  339.           args: [ 'x.c_str()', "(start == 0 ? '~' : start)" ]
  340.  
  341.       - text_sensor.template.publish:
  342.           id: kpad
  343.           state: !lambda "return x.c_str();"
  344.  
  345.       - if:
  346.           condition:
  347.             lambda: 'return id(allarme_scattato).state == "on";'
  348.           then:
  349.             - display.page.show: page4
  350.           else:
  351.             - display.page.show: page1
  352.  
  353.       - text_sensor.template.publish:
  354.           id: page
  355.           state: "1"
  356.  
  357. ################################################################################
  358. ##                  Script
  359. ################################################
  360. script:
  361.   id: timer
  362.   then:
  363.     - delay: 4s
  364.     - if:
  365.         condition:
  366.           lambda: 'return id(allarme_scattato).state == "on";'
  367.         then:
  368.           - display.page.show: page4
  369.         else:
  370.           - display.page.show: page1
  371.  
  372. ################################################################################
  373. ##                  Display
  374. ################################################
  375. display:
  376.   - platform: ssd1306_i2c
  377.     model: "SSD1306 128x64"
  378.     reset_pin: GPIO23
  379.     address: 0x3C
  380.     id: my_display
  381.     pages:
  382.       - id: page1
  383.         lambda: |-
  384.           it.clear();
  385.           it.printf(64, 3, id(font1), TextAlign::TOP_CENTER, "Allarme");
  386.           it.image(2, 2, id(alert));
  387.           it.line(1, 0, 124, 0);
  388.           it.line(1, 63, 124, 63);
  389.           it.line(0, 1, 0, 62);
  390.           it.line(125, 1, 125, 62);
  391.  
  392.           if (id(alarm_state).state.length() == 0) {
  393.             it.printf(64, 24, id(font2), TextAlign::TOP_CENTER, "Starting");
  394.           } else if (id(alarm_state).state == "Attivo") {
  395.             it.printf(64, 24, id(font2), TextAlign::TOP_CENTER, id(alarm_state).state.c_str());
  396.           } else if (id(alarm_state).state == "...Avvio") {
  397.             it.printf(64, 24, id(font2), TextAlign::TOP_CENTER, id(alarm_state).state.c_str());
  398.           } else if (id(alarm_state).state == "Disattivato") {
  399.             it.clear();
  400.           } else {
  401.             it.clear();
  402.           }
  403.  
  404.       - id: page2
  405.         lambda: |-
  406.           it.printf(64, 10, id(font3), TextAlign::TOP_CENTER, id(kpad).state.c_str());
  407.          
  408.       - id: page3
  409.         lambda: |-
  410.           it.image(50, 2, id(ok));
  411.           it.printf(64, 30, id(font4), TextAlign::TOP_CENTER, id(fingerprint_state).state.c_str());
  412.  
  413.       - id: page4
  414.         lambda: |-
  415.           it.clear();
  416.           it.printf(64, 3, id(font1), TextAlign::TOP_CENTER, "Allarme");
  417.          
  418.           static bool flashText = false;
  419.           flashText = !flashText;
  420.           if (flashText) {
  421.             it.printf(64, 24, id(font2), TextAlign::TOP_CENTER, "Scattato");
  422.           }
  423.          
  424.           it.image(2, 2, id(alert));
  425.           it.line(1, 0, 124, 0);
  426.           it.line(1, 63, 124, 63);
  427.           it.line(0, 1, 0, 62);
  428.           it.line(125, 1, 125, 62);
  429.  
  430.       - id: page5
  431.         lambda: |-
  432.           it.printf(64, 3, id(font1), TextAlign::TOP_CENTER, "Poggia");
  433.           it.printf(64, 30, id(font4), TextAlign::TOP_CENTER, "Meglio");
  434.  
  435. ################################################################################
  436. ##                  Text Sensor
  437. ################################################
  438. text_sensor:
  439.   - platform: homeassistant
  440.     entity_id: sensor.stato_allarme_pad_oled
  441.     name: "Stato Allarme"
  442.     id: alarm_state
  443.  
  444.   - platform: homeassistant
  445.     entity_id: sensor.stato_allarme
  446.     name: "Stato Allarme"
  447.     id: allarme
  448.  
  449.   - platform: homeassistant
  450.     name: "Allarme Scattato"
  451.     entity_id: input_boolean.allarme_scattato
  452.     id: allarme_scattato
  453.     internal: true
  454.  
  455.   - platform: homeassistant
  456.     name: "input"
  457.     id: input
  458.     entity_id: sensor.pad_oled_allarme_keypad_code
  459.     internal: true
  460.              
  461.   - platform: homeassistant
  462.     name: "error"
  463.     id: error
  464.     entity_id: sensor.counter_code_error
  465.     internal: true
  466.  
  467.   - platform: wifi_info
  468.     ip_address:
  469.       name: "${esp_devicename} IP"
  470.       icon: "mdi:lan"
  471.  
  472.   - platform: template
  473.     name: "Keypad code"
  474.     id: keypad
  475.    
  476.   - platform: template # Visualizza i numeri sul display
  477.     name: "Keypad OLED"
  478.     id: kpad
  479.     internal: true
  480.    
  481.   - platform: template
  482.     name: "page"
  483.     id: page
  484.     internal: true
  485.  
  486.   - platform: template
  487.     id: fingerprint_state
  488.     name: "Stato impronta"
  489.  
  490.   - platform: template
  491.     name: "Keypad code test"
  492.     id: keypadp
  493.  
  494. ################################################################################
  495. ##                  SENSOR
  496. ################################################
  497. sensor:
  498.   - platform: wifi_signal
  499.     name: "${esp_devicename} WiFi Signal"
  500.     update_interval: 10s
  501.  
  502.   - platform: fingerprint_grow
  503.     fingerprint_count:
  504.       name: "Conta impronte"
  505.     last_finger_id:
  506.       name: "Ultimo ID impronta"
  507.     last_confidence:
  508.       name: "Affidabilità ultima impronta"
  509.     status:
  510.       name: "Stato impronta"
  511.     capacity:
  512.       name: "Capacità impronta"
  513.     security_level:
  514.       name: "Livello di sicurezza"
  515.  
  516. ################################################################################
  517. ##                  Binary Sensor
  518. ################################################
  519. binary_sensor:
  520.   - platform: fingerprint_grow
  521.     id: fingerprint_enrolling
  522.     name: "Acquisendo impronta"
  523.  
  524.   - platform: template # Allarme Disattivato
  525.     name: "Allarme Disattivato"
  526.     internal: true
  527.     lambda: |-
  528.       if (id(alarm_state).state == "Disattivato") {
  529.         return true;
  530.       } else {
  531.         return false;
  532.       }
  533.     on_press:
  534.       - while:
  535.           condition:
  536.             lambda: |-
  537.               if (id(alarm_state).state == "Disattivato") {
  538.                 return true;
  539.               } else {
  540.                 return false;
  541.               }
  542.           then:
  543.             - output.turn_on: led_blu
  544.             - delay: 50ms
  545.             - output.turn_off: led_blu
  546.             - delay: 3s
  547.  
  548.   - platform: template # Allarme Scattato LED
  549.     name: "Allarme Scattato"
  550.     internal: true
  551.     lambda: |-
  552.       if (id(allarme_scattato).state == "on") {
  553.         return true;
  554.       } else {
  555.         return false;
  556.       }
  557.     on_press:
  558.       - while:
  559.           condition:
  560.             lambda: |-
  561.               if (id(allarme_scattato).state == "on") {
  562.                 return true;
  563.               } else {
  564.                 return false;
  565.               }
  566.           then:
  567.             - output.turn_on: led_blu
  568.             - delay: 300ms
  569.             - output.turn_off: led_blu
  570.             - output.turn_on: led_rosso
  571.             - delay: 300ms
  572.             - output.turn_off: led_rosso
  573.  
  574.   - platform: template # Allarme Attivo
  575.     name: "Allarme Attivo"
  576.     internal: true
  577.     lambda: |-
  578.       if (id(alarm_state).state == "Attivo") {
  579.         return true;
  580.       } else {
  581.         return false;
  582.       }
  583.     on_press:
  584.       - while:
  585.           condition:
  586.             lambda: |-
  587.               if (id(alarm_state).state == "Attivo") {
  588.                 return true;
  589.               } else {
  590.                 return false;
  591.               }
  592.           then:
  593.             - output.turn_on: led_rosso
  594.             - delay: 80ms
  595.             - output.turn_off: led_rosso
  596.             - delay: 80ms
  597.             - output.turn_on: led_rosso
  598.             - delay: 80ms
  599.             - output.turn_off: led_rosso
  600.             - delay: 3s
  601.  
  602.   - platform: template # Allarme Pedding
  603.     name: "Allarme Pedding"
  604.     internal: true
  605.     lambda: |-
  606.       if (id(alarm_state).state == "...Avvio") {
  607.         return true;
  608.       } else {
  609.         return false;
  610.       }
  611.     on_press:
  612.       - while:
  613.           condition:
  614.             lambda: |-
  615.               if (id(alarm_state).state == "...Avvio") {
  616.                 return true;
  617.               } else {
  618.                 return false;
  619.               }
  620.           then:
  621.             - output.turn_on: led_giallo
  622.             - delay: 500ms
  623.             - output.turn_off: led_giallo
  624.             - delay: 500ms
  625.  
  626.   - platform: template # Allarme Scattato
  627.     name: "Allarme Scat"
  628.     internal: true
  629.     lambda: |-
  630.       if (id(allarme_scattato).state == "on") {
  631.         return true;
  632.       } else {
  633.         return false;
  634.       }
  635.     on_press:
  636.       then:
  637.         - display.page.show: page4
  638.     on_release:
  639.       then:
  640.         - display.page.show: page1
  641.  
  642. ################################################################################
  643. ##                  OUTPUT
  644. ################################################
  645. output:
  646.   - platform: ledc
  647.     pin: GPIO15
  648.     id: buzzer_output
  649.  
  650.   - platform: ledc
  651.     id: led_verde
  652.     pin: GPIO19
  653.  
  654.   - platform: ledc
  655.     id: led_giallo
  656.     pin: GPIO18  
  657.  
  658.   - platform: ledc
  659.     id: led_rosso
  660.     pin: GPIO4
  661.  
  662.   - platform: ledc
  663.     id: led_blu
  664.     pin: GPIO2
  665.  
  666. ################################################################################
  667. ##                  RTTTL
  668. ################################################
  669. rtttl:
  670.   output: buzzer_output
  671.  
  672. ################################################################################
  673. ##                  Switch
  674. ################################################
  675. switch:
  676.   - platform: output
  677.     internal: true
  678.     name: 'buzzer'
  679.     id: buzzer
  680.     output: buzzer_output
  681.     on_turn_on:
  682.       then:
  683.         - output.turn_on: buzzer_output
  684.         - output.ledc.set_frequency:
  685.             id: buzzer_output
  686.             frequency: "2000Hz"
  687.         - output.set_level:
  688.             id: buzzer_output
  689.             level: "90%"
  690.  
  691.     on_turn_off:
  692.       then:
  693.         - output.turn_off: buzzer_output
  694.  
  695.   - platform: output
  696.     internal: true
  697.     name: 'buzzer error'
  698.     id: buzzer_error
  699.     output: buzzer_output
  700.     on_turn_on:
  701.       then:
  702.         - output.turn_on: buzzer_output
  703.         - output.ledc.set_frequency:
  704.             id: buzzer_output
  705.             frequency: "200Hz"
  706.         - output.set_level:
  707.             id: buzzer_output
  708.             level: "90%"
  709.  
  710.     on_turn_off:
  711.       then:
  712.         - output.turn_off: buzzer_output
  713.  
  714.   - platform: restart
  715.     name: "Restart Pad"
  716.     id: restart_switch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement