globals: - id: ready_to_open type: bool initial_value: 'false' esphome: name: entregas-lock friendly_name: entregas-lock on_boot: then: - logger.log: "MUSICA INICIO" - rtttl.play: 'MUSICASTART:d=16,o=6,b=95:32d,32d#,32d,32d#,32d,32d#,32d,32d#,32d,32d,32d#,32e,32f,32f#,32g,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,g,8p' - script.execute: id: blinkme script: - id: blinkme then: - repeat: count: 12 then: - switch.toggle: led_color_red - delay: 250ms - switch.toggle: led_color_yellow - delay: 250ms - switch.toggle: led_color_green - delay: 250ms #Default to red (not OPEN and turn yellow off in case it just blinked) - switch.turn_on: led_color_red - switch.turn_off: led_color_yellow - switch.turn_off: led_color_green # A gente NAO PODE FECHAR A fechadura, so saber se alguem fechou - id: fechatudo then: #Apos 2 segundos se a luz ainda esta ligada, desliga ela - delay: 2s - if: condition: - switch.is_on: entregas_luz then: - script.execute: fechaluz - id: fechaluz then: - switch.turn_off: led_color_yellow - switch.turn_off: entregas_luz esp32: board: esp32dev framework: type: arduino # Enable logging logger: level: INFO # Enable Home Assistant API api: encryption: key: "fbVMcTv0SYXALJA9EH3nGGUdbq6qT3jHX13SwBFX5zY=" ota: - platform: esphome password: "7e81e3c2e64ece75a819c6e535781b27" button: - platform: "restart" name: "Restart Entregas lock" web_server: port: 80 interval: # Permanently blink Green Led - interval: 1s then: - if: condition: lambda: 'return id(ready_to_open) == false;' then: - switch.turn_on: led_color_yellow - delay: 100ms - switch.toggle: led_color_yellow - delay: 100ms - switch.toggle: led_color_yellow - delay: 100ms - switch.toggle: led_color_yellow else: - switch.turn_on: led_color_red - switch.turn_off: led_color_green - repeat: count: 9 then: - delay: 100ms - switch.toggle: led_color_red - switch.toggle: led_color_green #----------------------- # GPIO music thing #----------------------- output: - platform: ledc pin: GPIO14 id: rtttl_out rtttl: output: rtttl_out gain: 60% switch: #----------------------- # GPIO R, G, B Leds #----------------------- - platform: gpio internal: true name: "LED Red" id: led_color_red pin: number: GPIO25 inverted: False - platform: gpio internal: true name: "LED Yellow" id: led_color_yellow pin: number: GPIO32 inverted: False - platform: gpio internal: true name: "LED Green" id: led_color_green pin: number: GPIO33 inverted: False #----------------------- # GPIO PULSO FECHADURA (abrir 500 ms) #----------------------- - platform: gpio pin: number: GPIO26 inverted: True #mode: #output: True #open_drain: True #pullup: True id: entrega_lock_abrir name: "Caixa entregas abrir pulso" icon: "mdi:gate" restore_mode: RESTORE_DEFAULT_OFF on_turn_on: - logger.log: "PULSO DE ABERTURA" - switch.turn_on: led_color_yellow #Blink big green light once when sending unlock pulse - switch.turn_on: entregas_luz - globals.set: id: ready_to_open value: 'true' - delay: 500ms #SO ligar 0.5 segundos o pulso para abrir a fechadura soltar de novo #ela vai fechar mesmo fisicamente com o botao - switch.turn_off: entrega_lock_abrir - switch.turn_off: entregas_luz - delay: 1s #Blink light fast - switch.turn_on: entregas_luz - repeat: count: 20 then: - switch.toggle: entregas_luz - delay: 50ms - delay: 30s - script.execute: fechatudo #----------------------- # GPIO LUZ GRANDE VERDE RELE #----------------------- - platform: gpio pin: number: GPIO23 inverted: True #mode: # output: True # open_drain: True #pullup: True id: entregas_luz name: "Caixa entregas Luz" icon: "mdi:gate" restore_mode: RESTORE_DEFAULT_OFF - platform: gpio pin: number: GPIO22 inverted: true id: entregas_ventilador name: "Caixa entregas ventilador" icon: "mdi:fan" restore_mode: RESTORE_DEFAULT_OFF sensor: - platform: wifi_signal id: wifi_signal_db name: "WiFi Signal Realtime dB" update_interval: 5s entity_category: "diagnostic" - platform: copy # Reports the WiFi signal strength in % source_id: wifi_signal_db id: wifi_signal_percent name: "WiFi Signal Realtime" filters: - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0); unit_of_measurement: "%" entity_category: "diagnostic" binary_sensor: #----------------------- # SENSOR VIRTUAL, Se chamou o pulso uma vez, ready_to_open==true #----------------------- - platform: template id: fechadura_unlocked name: "Caixa entregas desbloqueada" device_class: LOCK lambda: |- if ( id(ready_to_open)==true) return true; else return false; on_press: then: - logger.log: "FECHADURA DESBLOQUEADA" - rtttl.play: "MUSICAABERTA:d=4,o=5,b=100:16e6,16e6,32p,8e6,16c6,8e6,8g6,8p,8g" on_release: then: - logger.log: "FECHADURA BLOQUEADA" #----------------------- # GPIO SENSOR PORTA IMã #----------------------- - platform: gpio id: fechadura_aberta pin: number: GPIO27 #same as D27 on Wroom-32 mode: input: true pullup: True filters: - delayed_on_off: 0.25s name: "Caixa entregas aberta" device_class: DOOR on_press: then: - switch.turn_on: led_color_green - switch.turn_off: led_color_red - logger.log: "PORTA ABERTA" - rtttl.play: 'MUSICA_ABERTA:d=16,o=6,b=95:32d,32d#,32d,32d#,32d,32d#,32d,32d#,32d,32d,32d#,32e,32f,32f#,32g,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,g,8p' - delay: 3s #DEIXAR MUSIC UNLOCK on_release: then: - logger.log: "PORTA FECHADA" #A PORTA FECHOU FISICAMENTE, A porta não esta mais em estado de abrir - globals.set: id: ready_to_open value: 'false' #either off and on, stop progress - switch.turn_off: entrega_lock_abrir #Make sure there is no more energy on the lock - switch.turn_on: led_color_red - switch.turn_off: led_color_green - rtttl.play: "MUSICAFECHADA:d=4,o=5,b=100:16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16d#6,8p,16d6,8p,16c6" - delay: 3s #DEIXAR MUSIC LOCK - script.execute: fechaluz text_sensor: - platform: wifi_info ip_address: name: ESP IP Address ssid: name: ESP Connected SSID bssid: name: ESP Connected BSSID mac_address: name: ESP Mac Wifi Address # scan_results: # name: ESP Latest Scan Results Realtime wifi: ssid: !secret wifi_ssid password: !secret wifi_password power_save_mode: none reboot_timeout: 300s domain: .canoa.lan # Enable fallback hotspot (captive portal) in case wifi connection fails # ap: # ssid: "Entregas-Lock Fallback Hotspot" # password: "hkTXpbcVbEv0" #captive_portal: