前書き
約1年前、私は引っ越しの準備を始め、スマートホームのプロトタイプを組み立て始めました。制御システムとして、私は最も人気があり、活発に開発されているソリューションであるHomeAssistantを選択しました。スマートホームがセンサーで大きくなりすぎると、セキュリティシステムについての質問が発生しました。何かが起こった場合、アラームが鳴り、招待されていないゲストについて私(隣人)に通知します。民間警備会社のシステムはまだ必要ないと思っていたので、自分でやろうと思いました。
仕組み:開口部センサーが正面玄関に配置され、Zigbeeプロトコルを使用して、誰かがアパートに入ったことをスマートホームサーバーに通知します。アラームは「クワイエットモード」でトリガーされます(組み込み統合では「トリガーされた」イベント。これはまったく現れませんが、サイレンが鳴るまでカウントダウンします)。設定で指定された時間内に(コードまたはNFCタグを入力して)ロックが解除されない場合、サイレンとライトの表示が開始されます。
収集対象:
ESP32 WROOM DevKit v1(理論的には、ESPの構成を変更することでESPを置き換えることができます)
RFID / NFCモジュールPN532
接続線(6本)
3Dプリントケース
Xiaomi Gateway 2(ローカル制御)スピーカーとインジケーターライトとして使用する予定です
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, . .
, - . , . , !
- , . .