Wir stellen ein Zugangskontroll- und -verwaltungssystem (ACS) für ein Smart Home her

Einführung

Vor ungefähr einem Jahr begann ich mich auf den Umzug vorzubereiten und einen Prototyp eines Smart Homes zusammenzustellen. Als Steuerungssystem habe ich die beliebteste und aktivste Lösung gewählt - Home Assistant. Als das Smart Home mit Sensoren bewachsen war, stellte sich die Frage nach dem Sicherheitssystem, das im Falle eines Ereignisses den Alarm auslösen und mich (Nachbarn) über ungebetene Gäste informieren würde. Ich sehe noch keine Notwendigkeit für ein System von privaten Sicherheitsfirmen, deshalb habe ich beschlossen, alles selbst zu tun.





So funktioniert es: An der Vordertür befindet sich ein Öffnungssensor, der mithilfe des ZigBee-Protokolls den Smart-Home-Server darüber informiert, dass jemand die Wohnung betreten hat. Ein Alarm wird im "leisen Modus" ausgelöst ( "ausgelöstes" Ereignis bei der eingebetteten Integration ; dies manifestiert sich in keiner Weise, zählt jedoch herunter, bis die Sirene startet). Wenn das Schloss nicht innerhalb der in den Einstellungen angegebenen Zeit entfernt wird (durch Eingabe eines Codes oder eines NFC-Tags), werden die Sirenen- und Lichtanzeige gestartet.





Was wird gesammelt von:





  • ESP32 WROOM DevKit v1 (theoretisch können Sie jedes ESP ersetzen, indem Sie die Konfiguration dafür ändern)





  • RFID / NFC-Modul PN532





  • Verbindungsdrähte (6 Stück)





  • 3D gedrucktes Gehäuse





  • Xiaomi Gateway 2 (das lokal gesteuert wird) Ich plane, es als Lautsprecher und Anzeigelampe zu verwenden





  • Türöffnungssensor von Aqara





  • , LED-, , Home Assistant.





ESP32 WROOM DevKit v1 (30 Pins)
ESP32 WROOM DevKit v1 (30 )
RFID / NFC PN532-Modul.  Die Chinesen haben die Version von Elechouse kopiert.
RFID/NFC PN532. Elechouse.

, 3D-. Xiaomi . Aliexpress 600 .





ESP

NFC- SPI. ( 1), - ( ). 8 .





I2C-Modus aktiviert und Verbindungskabel angeschlossen
I2C

, NFC- ESP-32: . , - , .





Pinbelegung für 30-poliges ESP-32
30- ESP-32

( ESP, PN532):





  • GPIO18 - SKC





  • GPIO19 - MSO





  • GPIO23 - MOSI





  • GPIO5 - SS





  • 3V3 - VCC





  • GND - GND





PN532 an ESP-32 angeschlossen
PN532 ESP-32

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
      
      



secrets.yaml. , , .





, 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, . .





Die Basis, auf der die Bretter liegen, und eine Wäscheklammer (links), um den PN532 zu sichern
, , () , PN532
Das Netzkabel ist an das ESP angeschlossen, damit es nicht im Gehäuse baumelt.
ESP , .

, - . , . , !





- , . .








All Articles