introduction
Il y a environ un an, j'ai commencé à préparer le déménagement et à assembler un prototype de maison intelligente. En tant que système de contrôle, j'ai choisi la solution la plus populaire et la plus en développement - Home Assistant. Alors que la maison intelligente devenait envahie par les capteurs, la question s'est posée du système de sécurité qui, si quelque chose se produisait, sonnerait l'alarme et m'informerait (les voisins) des invités non invités. Je ne vois pas encore la nécessité d'un système de sociétés de sécurité privées, alors j'ai décidé de tout faire moi-même.
Comment ça marche: un capteur d'ouverture est placé sur la porte d'entrée, qui, en utilisant le protocole Zigbee, informe le serveur smart home qu'une personne est entrée dans l'appartement. Une alarme est déclenchée en "mode silencieux" (événement "déclenché" en intégration embarquée ; cela ne se manifeste en aucune façon, mais il décompte jusqu'à ce que la sirène démarre). Si le verrou n'est pas retiré dans le délai spécifié dans les paramètres (en saisissant un code ou une étiquette NFC), la sirène et l'indication lumineuse démarrent.
Ce qui est collecté sur:
ESP32 WROOM DevKit v1 (en théorie, vous pouvez remplacer n'importe quel ESP en changeant sa configuration)
Module RFID / NFC PN532
Fils de connexion (6 pièces)
Boîtier imprimé en 3D
Xiaomi Gateway 2 (qui est contrôlée localement) Je prévois de l'utiliser comme haut-parleur et voyant lumineux
Capteur d'ouverture de porte d'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, . .
, - . , . , !
- , . .