本帖最后由 shadowba 于 2023-6-1 14:15 编辑
材料如下:
韦根读卡器一个,双继电器模块,光耦,机电锁
实现功能:手机nfc刷卡入户开锁,开锁后门灯亮,关门后门灯熄灭。门铃按钮nodered小爱音箱播报询问,有客人来访是否打开智能锁。因nas就在门后故又通过两个光耦接入了nas电源状态和开关机。
代码如下:
esphome:
name: "door-dsm"
friendly_name: "door-dsm"
platformio_options:
board_build.flash_mode: dio
board_build.mcu: esp32c3
esp32:
board: esp32-c3-devkitm-1
variant: esp32c3
framework:
type: esp-idf
# Enable logging
logger:
hardware_uart: USB_SERIAL_JTAG
# Enable Home Assistant API
api:
ota:
password: "0000000000000000000000"
wifi:
networks:
- ssid: 000000000
password: 0000000000000
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esp32C3 Fallback Hotspot"
#韦根读卡器(建议增加电平转换电路)
wiegand:
- id: mykeypad
d0: GPIO4
d1: GPIO5
on_tag:
- text_sensor.template.publish:
id: rfid_tag
state: !lambda 'return x;'
- lambda: |-
if ( (id(rfid_tag).state == "0000000000") or (id(rfid_tag).state == "000000000")) {
id(relay).turn_on();
}
text_sensor:
- platform: template
name: "6 RFID Tag D5 D4"
icon: "mdi:smart-card-reader"
id: rfid_tag
lambda: |-
return {};
binary_sensor:
#门铃开关
- platform: gpio
pin:
number: GPIO2
mode:
input: true
pullup: true
inverted: true
filters:
- delayed_on: 10ms
- delayed_off: 2s
name: "6 Door Bell D2"
icon: "mdi:doorbell"
on_press:
- switch.turn_on: relay2
# 门磁状态检测
- platform: gpio
pin:
number: GPIO3
mode:
input: true
pullup: true
inverted: false
name: "6 Door Sensor D3"
icon: "mdi:door-open"
on_release:
- switch.turn_off: relay2
# DSM存储服务器状态检测
- platform: gpio
id: led
pin:
number: GPIO0
mode:
input: true
pullup: true
inverted: true
device_class: running
name: "6 DSM Power Led D0"
icon: "mdi:led-on"
switch:
# DSM存储服务器开关
- platform: template
name: "6 DSM Power Button D1"
icon: "mdi:power"
lambda: |-
if (id(led).state) {
return true;
} else {
return false;
}
turn_on_action:
- switch.turn_on: relay1
turn_off_action:
- switch.turn_on: relay1
- platform: gpio
pin: GPIO1
id: relay1
on_turn_on:
- delay: 500ms
- switch.turn_off: relay1
# 门口灯继电器控制
- platform: gpio
pin: GPIO6
id: relay2
name: "6 Door Light D6"
icon: "mdi:coach-lamp-variant"
on_turn_on:
- delay: 120s
- switch.turn_off: relay2
# 防盗门锁继电器控制
- platform: gpio
pin: GPIO7
id: relay
name: "6 Door Lock D7"
icon: "mdi:home-lock"
restore_mode: ALWAYS_OFF
on_turn_on:
- switch.turn_on: relay2
- delay: 300ms
- switch.turn_off: relay
- platform: restart
name: "Door-dsm Restart"
|