Skip to content

Instantly share code, notes, and snippets.

@blackjack75
Last active May 6, 2023 19:21
Show Gist options
  • Save blackjack75/65b58a853bad095bca3518e552d862b0 to your computer and use it in GitHub Desktop.
Save blackjack75/65b58a853bad095bca3518e552d862b0 to your computer and use it in GitHub Desktop.
ESPHome YAML for delivery box
globals:
- id: ready_to_open
type: bool
initial_value: 'false'
esphome:
name: entregas-lock
friendly_name: entregas-lock
on_boot:
then:
- rtttl.play: 'MissionImp: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
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "XX"
ota:
password: "XX"
button:
- platform: "restart"
name: "Restart Entregas lock"
web_server:
port: 80
# Permanently blink Green Led
interval:
- 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
# Example configuration entry
output:
- platform: ledc
pin: GPIO14
id: rtttl_out
rtttl:
output: rtttl_out
#RELAY Solenoide
switch:
- 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
#O anuncio diz maximo 1 a 2 segundos para não aquecer a fechadura
- platform: gpio
pin: GPIO26
id: entrega_lock_abrir
name: "Caixa entregas abrir pulso"
icon: "mdi:gate"
inverted: True
restore_mode: RESTORE_DEFAULT_OFF
on_turn_on:
- switch.turn_on: led_color_yellow
- globals.set:
id: ready_to_open
value: 'true'
- rtttl.play: 'MissionImp: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: 1s
- switch.turn_off: entrega_lock_abrir
#Maintain yellow one for 1 sec when turning on
#Green will be indicated by binary sensor detecting that yes it is open
#this only shows we pressed
- delay: 1s #One more second, we already wait for one second to turn off pulse relay
- switch.turn_off: led_color_yellow
binary_sensor:
- platform: template
id: fechadura_unlocked
name: "Caixa entregas desbloqueada"
lambda: |-
if ( id(ready_to_open)==true)
return true;
else
return false;
# SENSOR fechadudra
- platform: gpio
id: fechadura_aberta
pin:
number: GPIO27 #same as D27 on Wroom-32
mode:
input: true
pullup: true
name: "Caixa entregas aberta"
on_press:
then:
- globals.set:
id: ready_to_open
value: 'false' #either off and on, stop progress
- switch.turn_on: led_color_green
- switch.turn_off: led_color_red
- rtttl.play: "mario:d=4,o=5,b=100:16e6,16e6,32p,8e6,16c6,8e6,8g6,8p,8g"
on_release:
then:
- globals.set:
id: ready_to_open
value: 'false' #either off and on, stop progress
- switch.turn_on: led_color_red
- switch.turn_off: led_color_green
- rtttl.play: "mario:d=4,o=5,b=100:16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16d#6,8p,16d6,8p,16c6"
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: "XX"
#captive_portal:
@blackjack75
Copy link
Author

link to mastodon post about it
See on Mastodon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment