Introducción
Hace aproximadamente un año, comencé a prepararme para la mudanza y a armar un prototipo de casa inteligente. Como sistema de control, elegí la solución más popular y en desarrollo activo: Home Assistant. A medida que la casa inteligente crecía con sensores, surgió la pregunta sobre el sistema de seguridad, que, si algo sucedía, daría la alarma y me informaría (a los vecinos) sobre los invitados no invitados. Todavía no veo la necesidad de un sistema de empresas de seguridad privada, así que decidí hacer todo yo mismo.
Cómo funciona: se coloca un sensor de apertura en la puerta de entrada que, mediante el protocolo Zigbee, informa al servidor doméstico inteligente que alguien ha entrado en el apartamento. Una alarma se dispara en "modo silencioso" (evento "disparado" en la integración integrada ; esto no se manifiesta de ninguna manera, pero cuenta hacia atrás hasta que se inicia la sirena). Si el candado no se quita dentro del tiempo especificado en la configuración (ingresando un código o etiqueta NFC), la sirena y la indicación de luz comenzarán.
Qué se obtiene de:
ESP32 WROOM DevKit v1 (en teoría, puede reemplazar cualquier ESP cambiando la configuración)
Módulo RFID / NFC PN532
Cables de conexión (6 piezas)
Estuche impreso en 3D
Xiaomi Gateway 2 (que se controla localmente) que planeo usar como altavoz y luz indicadora
Sensor de apertura de puerta de Aqara
, LED-, , Home Assistant.
, 3D-. Xiaomi . Aliexpress 600 .
ESP
NFC- SPI. ( 1), - ( ). 8 .
, NFC- ESP-32: . , - , .
( ESP, PN532):
GPIO18 - SKC
GPIO19 - MSO
GPIO23 - MOSI
GPIO5 - SS
3V3 - VCC
GND - GND
ESPHome ESP-32. , :
:
esphome:
name: esp32
platform: ESP32
board: nodemcu-32s
wifi:
ssid: "My Wi-Fi"
password: "mypassword"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esp32 Fallback Hotspot"
password: "mypassword"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
password: "mypassword"
ota:
password: "mypassword"
web_server:
port: 80
spi:
clk_pin: GPIO18
miso_pin: GPIO19
mosi_pin: GPIO23
pn532_spi:
cs_pin: GPIO5
update_interval: 1s
esp32_ble_tracker:
switch:
- platform: gpio
name: "ESP LED"
pin:
number: GPIO2
mode: OUTPUT
binary_sensor:
- platform: pn532
uid: 79-EB-08-B4
name: "NFC Card"
spi pn532_spi, . switch ( , , ), binary_sensor Home Assistant ( uid true; uid ESP ESPHome). , RFID-, . NFC , .
ESP. , , RFID-. uid :
[17:42:35][D][pn532:149]: Found new tag '79-EB-08-B4'
ESP , Home Assistan
Home Assistant
Home Assistant Lovelace. - , configuration.yaml :
alarm_control_panel:
- platform: manual
code: !secret alarm_pin
code_arm_required: false
#
arming_time: 5
#
delay_time: 10
#
trigger_time: 600
, arming_time ( , ) delay_time ( , ) 5 10 . , Home Assistant.
Lovelace, ui-lovelace.yaml
- type: alarm-panel
name:
entity: alarm_control_panel.ha_alarm
states:
- arm_away
entity , alarm_control_panel. states , : " ( )".
NFC- , 5 :
(, )
( )
( , )
. , , . Xiaomi ESP-32. .
- id: '3-0001'
alias: ' '
trigger:
platform: state
entity_id: binary_sensor.158d000446f3fe_contact
to: 'on'
condition:
- condition: state
entity_id: alarm_control_panel.ha_alarm
state: armed_away
action:
- service: alarm_control_panel.alarm_trigger
entity_id: alarm_control_panel.ha_alarm
- repeat:
sequence:
- service: light.turn_on
data:
entity_id: light.gateway_light_44237c82f751
color_name: red
brightness: 255
- service: switch.turn_on
entity_id: switch.esp_led
- delay:
milliseconds: 500
- service: light.turn_off
entity_id: light.gateway_light_44237c82f751
- service: switch.turn_off
entity_id: switch.esp_led
- delay:
milliseconds: 500
until:
condition: or
conditions:
- condition: state
entity_id: alarm_control_panel.ha_alarm
state: armed_away
- condition: state
entity_id: alarm_control_panel.ha_alarm
state: disarmed
- ESP uid. , . , , ESP, 3 .
- id: '3-0002'
alias: ' '
trigger:
platform: state
entity_id: binary_sensor.nfc_card
to: 'on'
condition:
- condition: state
entity_id: alarm_control_panel.ha_alarm
state: disarmed
action:
- service: alarm_control_panel.alarm_arm_away
entity_id: alarm_control_panel.ha_alarm
- repeat:
sequence:
- service: light.turn_on
data:
entity_id: light.gateway_light_44237c82f751
color_name: orange
brightness: 255
- service: switch.turn_on
entity_id: switch.esp_led
- delay:
milliseconds: 500
- service: light.turn_off
entity_id: light.gateway_light_44237c82f751
- service: switch.turn_off
entity_id: switch.esp_led
- delay:
milliseconds: 500
until:
- condition: state
entity_id: alarm_control_panel.ha_alarm
state: armed_away
- service: switch.turn_on
entity_id: switch.esp_led
- service: light.turn_on
data:
entity_id: light.gateway_light_44237c82f751
color_name: red
brightness: 255
- delay:
seconds: 3
- service: light.turn_off
entity_id: light.gateway_light_44237c82f751
RFID-. . , , . ESP .
- id: '3-0003'
alias: ' '
trigger:
platform: state
entity_id: binary_sensor.nfc_card
to: 'on'
condition:
condition: or
conditions:
- condition: state
entity_id: alarm_control_panel.ha_alarm
state: armed_away
- condition: state
entity_id: alarm_control_panel.ha_alarm
state: pending
action:
- service: alarm_control_panel.alarm_disarm
data:
entity_id: alarm_control_panel.ha_alarm
code: !secret alarm_pin
- delay:
milliseconds: 100
- service: switch.turn_off
entity_id: switch.esp_led
- service: light.turn_on
data:
entity_id: light.gateway_light_44237c82f751
color_name: green
brightness: 255
- delay:
seconds: 3
- service: light.turn_off
entity_id: light.gateway_light_44237c82f751
, . .
- id: '3-0004'
alias: ' '
trigger:
- platform: state
entity_id: alarm_control_panel.ha_alarm
to: 'triggered'
action:
- service: xiaomi_aqara.play_ringtone
data:
gw_mac: 44237C82F751
ringtone_id: 0
ringtone_vol: 3
" " alarm_control_panel.ha_alarm ( triggered) .
- id: '3-0005'
alias: ' '
trigger:
platform: state
entity_id: binary_sensor.nfc_card
to: 'on'
condition:
- condition: state
entity_id: alarm_control_panel.ha_alarm
state: triggered
action:
- service: alarm_control_panel.alarm_disarm
data:
entity_id: alarm_control_panel.ha_alarm
code: !secret alarm_pin
- service: xiaomi_aqara.stop_ringtone
data:
gw_mac: 44237C82F751
- delay:
milliseconds: 500
- service: switch.turn_off
entity_id: switch.esp_led
- service: light.turn_on
data:
entity_id: light.gateway_light_44237c82f751
color_name: green
brightness: 255
- delay:
seconds: 3
- service: light.turn_off
entity_id: light.gateway_light_44237c82f751
, , - . . , . , ESP, . .
, - . , . , !
- , . .