entregas_lock.yaml(檔案已創建)
| @@ -0,0 +1,340 @@ | |||
| 1 | + | globals: | |
| 2 | + | - id: ready_to_open | |
| 3 | + | type: bool | |
| 4 | + | initial_value: 'false' | |
| 5 | + | ||
| 6 | + | esphome: | |
| 7 | + | name: entregas-lock | |
| 8 | + | friendly_name: entregas-lock | |
| 9 | + | on_boot: | |
| 10 | + | then: | |
| 11 | + | - logger.log: "MUSICA INICIO" | |
| 12 | + | - 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' | |
| 13 | + | - script.execute: | |
| 14 | + | id: blinkme | |
| 15 | + | ||
| 16 | + | script: | |
| 17 | + | - id: blinkme | |
| 18 | + | then: | |
| 19 | + | - repeat: | |
| 20 | + | count: 12 | |
| 21 | + | then: | |
| 22 | + | ||
| 23 | + | - switch.toggle: led_color_red | |
| 24 | + | - delay: 250ms | |
| 25 | + | - switch.toggle: led_color_yellow | |
| 26 | + | - delay: 250ms | |
| 27 | + | - switch.toggle: led_color_green | |
| 28 | + | - delay: 250ms | |
| 29 | + | #Default to red (not OPEN and turn yellow off in case it just blinked) | |
| 30 | + | - switch.turn_on: led_color_red | |
| 31 | + | - switch.turn_off: led_color_yellow | |
| 32 | + | - switch.turn_off: led_color_green | |
| 33 | + | ||
| 34 | + | # A gente NAO PODE FECHAR A fechadura, so saber se alguem fechou | |
| 35 | + | - id: fechatudo | |
| 36 | + | then: | |
| 37 | + | ||
| 38 | + | #Apos 2 segundos se a luz ainda esta ligada, desliga ela | |
| 39 | + | - delay: 2s | |
| 40 | + | ||
| 41 | + | - if: | |
| 42 | + | condition: | |
| 43 | + | - switch.is_on: entregas_luz | |
| 44 | + | then: | |
| 45 | + | - script.execute: fechaluz | |
| 46 | + | ||
| 47 | + | ||
| 48 | + | - id: fechaluz | |
| 49 | + | then: | |
| 50 | + | ||
| 51 | + | - switch.turn_off: led_color_yellow | |
| 52 | + | - switch.turn_off: entregas_luz | |
| 53 | + | ||
| 54 | + | ||
| 55 | + | esp32: | |
| 56 | + | board: esp32dev | |
| 57 | + | framework: | |
| 58 | + | type: arduino | |
| 59 | + | ||
| 60 | + | # Enable logging | |
| 61 | + | logger: | |
| 62 | + | level: INFO | |
| 63 | + | ||
| 64 | + | # Enable Home Assistant API | |
| 65 | + | api: | |
| 66 | + | encryption: | |
| 67 | + | key: "fbVMcTv0SYXALJA9EH3nGGUdbq6qT3jHX13SwBFX5zY=" | |
| 68 | + | ||
| 69 | + | ota: | |
| 70 | + | - platform: esphome | |
| 71 | + | password: "7e81e3c2e64ece75a819c6e535781b27" | |
| 72 | + | ||
| 73 | + | button: | |
| 74 | + | - platform: "restart" | |
| 75 | + | name: "Restart Entregas lock" | |
| 76 | + | ||
| 77 | + | web_server: | |
| 78 | + | port: 80 | |
| 79 | + | ||
| 80 | + | ||
| 81 | + | interval: | |
| 82 | + | ||
| 83 | + | # Permanently blink Green Led | |
| 84 | + | - interval: 1s | |
| 85 | + | then: | |
| 86 | + | - if: | |
| 87 | + | condition: | |
| 88 | + | lambda: 'return id(ready_to_open) == false;' | |
| 89 | + | then: | |
| 90 | + | - switch.turn_on: led_color_yellow | |
| 91 | + | - delay: 100ms | |
| 92 | + | - switch.toggle: led_color_yellow | |
| 93 | + | - delay: 100ms | |
| 94 | + | - switch.toggle: led_color_yellow | |
| 95 | + | - delay: 100ms | |
| 96 | + | - switch.toggle: led_color_yellow | |
| 97 | + | else: | |
| 98 | + | - switch.turn_on: led_color_red | |
| 99 | + | - switch.turn_off: led_color_green | |
| 100 | + | - repeat: | |
| 101 | + | count: 9 | |
| 102 | + | then: | |
| 103 | + | - delay: 100ms | |
| 104 | + | - switch.toggle: led_color_red | |
| 105 | + | - switch.toggle: led_color_green | |
| 106 | + | ||
| 107 | + | ||
| 108 | + | #----------------------- | |
| 109 | + | # GPIO music thing | |
| 110 | + | #----------------------- | |
| 111 | + | output: | |
| 112 | + | - platform: ledc | |
| 113 | + | pin: GPIO14 | |
| 114 | + | id: rtttl_out | |
| 115 | + | ||
| 116 | + | rtttl: | |
| 117 | + | output: rtttl_out | |
| 118 | + | gain: 60% | |
| 119 | + | ||
| 120 | + | switch: | |
| 121 | + | ||
| 122 | + | #----------------------- | |
| 123 | + | # GPIO R, G, B Leds | |
| 124 | + | #----------------------- | |
| 125 | + | ||
| 126 | + | - platform: gpio | |
| 127 | + | internal: true | |
| 128 | + | name: "LED Red" | |
| 129 | + | id: led_color_red | |
| 130 | + | pin: | |
| 131 | + | number: GPIO25 | |
| 132 | + | inverted: False | |
| 133 | + | ||
| 134 | + | - platform: gpio | |
| 135 | + | internal: true | |
| 136 | + | name: "LED Yellow" | |
| 137 | + | id: led_color_yellow | |
| 138 | + | pin: | |
| 139 | + | number: GPIO32 | |
| 140 | + | inverted: False | |
| 141 | + | ||
| 142 | + | - platform: gpio | |
| 143 | + | internal: true | |
| 144 | + | name: "LED Green" | |
| 145 | + | id: led_color_green | |
| 146 | + | pin: | |
| 147 | + | number: GPIO33 | |
| 148 | + | inverted: False | |
| 149 | + | ||
| 150 | + | #----------------------- | |
| 151 | + | # GPIO PULSO FECHADURA (abrir 500 ms) | |
| 152 | + | #----------------------- | |
| 153 | + | - platform: gpio | |
| 154 | + | pin: | |
| 155 | + | number: GPIO26 | |
| 156 | + | inverted: True | |
| 157 | + | #mode: | |
| 158 | + | #output: True | |
| 159 | + | #open_drain: True | |
| 160 | + | #pullup: True | |
| 161 | + | ||
| 162 | + | ||
| 163 | + | id: entrega_lock_abrir | |
| 164 | + | name: "Caixa entregas abrir pulso" | |
| 165 | + | icon: "mdi:gate" | |
| 166 | + | ||
| 167 | + | restore_mode: RESTORE_DEFAULT_OFF | |
| 168 | + | ||
| 169 | + | on_turn_on: | |
| 170 | + | - logger.log: "PULSO DE ABERTURA" | |
| 171 | + | ||
| 172 | + | - switch.turn_on: led_color_yellow | |
| 173 | + | ||
| 174 | + | #Blink big green light once when sending unlock pulse | |
| 175 | + | - switch.turn_on: entregas_luz | |
| 176 | + | - globals.set: | |
| 177 | + | id: ready_to_open | |
| 178 | + | value: 'true' | |
| 179 | + | - delay: 500ms | |
| 180 | + | #SO ligar 0.5 segundos o pulso para abrir a fechadura soltar de novo | |
| 181 | + | #ela vai fechar mesmo fisicamente com o botao | |
| 182 | + | - switch.turn_off: entrega_lock_abrir | |
| 183 | + | - switch.turn_off: entregas_luz | |
| 184 | + | - delay: 1s | |
| 185 | + | ||
| 186 | + | #Blink light fast | |
| 187 | + | - switch.turn_on: entregas_luz | |
| 188 | + | - repeat: | |
| 189 | + | count: 20 | |
| 190 | + | then: | |
| 191 | + | - switch.toggle: entregas_luz | |
| 192 | + | - delay: 50ms | |
| 193 | + | ||
| 194 | + | - delay: 30s | |
| 195 | + | - script.execute: fechatudo | |
| 196 | + | ||
| 197 | + | ||
| 198 | + | ||
| 199 | + | ||
| 200 | + | #----------------------- | |
| 201 | + | # GPIO LUZ GRANDE VERDE RELE | |
| 202 | + | #----------------------- | |
| 203 | + | - platform: gpio | |
| 204 | + | pin: | |
| 205 | + | number: GPIO23 | |
| 206 | + | inverted: True | |
| 207 | + | #mode: | |
| 208 | + | # output: True | |
| 209 | + | # open_drain: True | |
| 210 | + | #pullup: True | |
| 211 | + | ||
| 212 | + | id: entregas_luz | |
| 213 | + | name: "Caixa entregas Luz" | |
| 214 | + | icon: "mdi:gate" | |
| 215 | + | restore_mode: RESTORE_DEFAULT_OFF | |
| 216 | + | ||
| 217 | + | - platform: gpio | |
| 218 | + | ||
| 219 | + | pin: | |
| 220 | + | number: GPIO22 | |
| 221 | + | inverted: true | |
| 222 | + | id: entregas_ventilador | |
| 223 | + | name: "Caixa entregas ventilador" | |
| 224 | + | icon: "mdi:fan" | |
| 225 | + | restore_mode: RESTORE_DEFAULT_OFF | |
| 226 | + | ||
| 227 | + | ||
| 228 | + | ||
| 229 | + | ||
| 230 | + | sensor: | |
| 231 | + | ||
| 232 | + | - platform: wifi_signal | |
| 233 | + | id: wifi_signal_db | |
| 234 | + | name: "WiFi Signal Realtime dB" | |
| 235 | + | update_interval: 5s | |
| 236 | + | entity_category: "diagnostic" | |
| 237 | + | ||
| 238 | + | - platform: copy # Reports the WiFi signal strength in % | |
| 239 | + | source_id: wifi_signal_db | |
| 240 | + | id: wifi_signal_percent | |
| 241 | + | name: "WiFi Signal Realtime" | |
| 242 | + | filters: | |
| 243 | + | - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0); | |
| 244 | + | unit_of_measurement: "%" | |
| 245 | + | entity_category: "diagnostic" | |
| 246 | + | ||
| 247 | + | ||
| 248 | + | binary_sensor: | |
| 249 | + | ||
| 250 | + | #----------------------- | |
| 251 | + | # SENSOR VIRTUAL, Se chamou o pulso uma vez, ready_to_open==true | |
| 252 | + | #----------------------- | |
| 253 | + | ||
| 254 | + | - platform: template | |
| 255 | + | id: fechadura_unlocked | |
| 256 | + | name: "Caixa entregas desbloqueada" | |
| 257 | + | device_class: LOCK | |
| 258 | + | lambda: |- | |
| 259 | + | if ( id(ready_to_open)==true) | |
| 260 | + | return true; | |
| 261 | + | else | |
| 262 | + | return false; | |
| 263 | + | on_press: | |
| 264 | + | then: | |
| 265 | + | - logger.log: "FECHADURA DESBLOQUEADA" | |
| 266 | + | - rtttl.play: "MUSICAABERTA:d=4,o=5,b=100:16e6,16e6,32p,8e6,16c6,8e6,8g6,8p,8g" | |
| 267 | + | on_release: | |
| 268 | + | then: | |
| 269 | + | - logger.log: "FECHADURA BLOQUEADA" | |
| 270 | + | ||
| 271 | + | #----------------------- | |
| 272 | + | # GPIO SENSOR PORTA IMã | |
| 273 | + | #----------------------- | |
| 274 | + | - platform: gpio | |
| 275 | + | id: fechadura_aberta | |
| 276 | + | ||
| 277 | + | pin: | |
| 278 | + | number: GPIO27 #same as D27 on Wroom-32 | |
| 279 | + | mode: | |
| 280 | + | input: true | |
| 281 | + | pullup: True | |
| 282 | + | filters: | |
| 283 | + | - delayed_on_off: 0.25s | |
| 284 | + | name: "Caixa entregas aberta" | |
| 285 | + | device_class: DOOR | |
| 286 | + | on_press: | |
| 287 | + | then: | |
| 288 | + | - switch.turn_on: led_color_green | |
| 289 | + | - switch.turn_off: led_color_red | |
| 290 | + | - logger.log: "PORTA ABERTA" | |
| 291 | + | - 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' | |
| 292 | + | - delay: 3s #DEIXAR MUSIC UNLOCK | |
| 293 | + | ||
| 294 | + | on_release: | |
| 295 | + | then: | |
| 296 | + | - logger.log: "PORTA FECHADA" | |
| 297 | + | ||
| 298 | + | #A PORTA FECHOU FISICAMENTE, A porta não esta mais em estado de abrir | |
| 299 | + | - globals.set: | |
| 300 | + | id: ready_to_open | |
| 301 | + | value: 'false' #either off and on, stop progress | |
| 302 | + | ||
| 303 | + | - switch.turn_off: entrega_lock_abrir #Make sure there is no more energy on the lock | |
| 304 | + | - switch.turn_on: led_color_red | |
| 305 | + | - switch.turn_off: led_color_green | |
| 306 | + | - rtttl.play: "MUSICAFECHADA:d=4,o=5,b=100:16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16d#6,8p,16d6,8p,16c6" | |
| 307 | + | - delay: 3s #DEIXAR MUSIC LOCK | |
| 308 | + | - script.execute: fechaluz | |
| 309 | + | ||
| 310 | + | ||
| 311 | + | text_sensor: | |
| 312 | + | - platform: wifi_info | |
| 313 | + | ip_address: | |
| 314 | + | name: ESP IP Address | |
| 315 | + | ssid: | |
| 316 | + | name: ESP Connected SSID | |
| 317 | + | bssid: | |
| 318 | + | name: ESP Connected BSSID | |
| 319 | + | mac_address: | |
| 320 | + | name: ESP Mac Wifi Address | |
| 321 | + | # scan_results: | |
| 322 | + | # name: ESP Latest Scan Results Realtime | |
| 323 | + | ||
| 324 | + | wifi: | |
| 325 | + | ssid: !secret wifi_ssid | |
| 326 | + | password: !secret wifi_password | |
| 327 | + | power_save_mode: none | |
| 328 | + | reboot_timeout: 300s | |
| 329 | + | domain: .canoa.lan | |
| 330 | + | ||
| 331 | + | # Enable fallback hotspot (captive portal) in case wifi connection fails | |
| 332 | + | # ap: | |
| 333 | + | # ssid: "Entregas-Lock Fallback Hotspot" | |
| 334 | + | # password: "hkTXpbcVbEv0" | |
| 335 | + | ||
| 336 | + | #captive_portal: | |
| 337 | + | ||
| 338 | + | ||
| 339 | + | ||
| 340 | + | ||
上一頁
下一頁