I can post wiegand_device.h if you wish, but I plan to toss that to use the new esphome wiegand integration. I’d recommend that over my older custom version. The reader I’m using here is an HID Signo 40.
substitutions:
device_name: door
friendly_name: "Door"
esphome:
name: ${device_name}
platform: ESP8266
board: d1_mini
includes:
- wiegand_device.h
on_boot:
then:
- switch.turn_off: green
- switch.turn_off: red
- lock.lock: maglock
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 10.0.0.100
gateway: 10.0.0.1
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${friendly_name} Hotspot"
password: "PASSWEEERD"
captive_portal:
# Enable logging
logger:
ota:
password: !secret ota_password
api:
encryption:
key: "KEY"
services:
- service: unlock
then:
if:
condition:
lock.is_locked: maglock
then:
- lock.unlock: maglock
- service: unlock_temporary
then:
if:
condition:
lock.is_locked: maglock
then:
- lock.unlock: maglock
- delay: 10s
- lock.lock: maglock
else:
- switch.turn_on: green
- switch.turn_on: beeper
- logger.log: Lock already unlocked. Showing card valid.
- delay: 200ms
- switch.turn_off: beeper
- switch.turn_off: green
- delay: 100ms
- switch.turn_on: beeper
- delay: 200ms
- switch.turn_off: beeper
- switch.turn_off: green
- delay: 100ms
- switch.turn_on: green
- service: card_not_found
then:
if:
condition:
switch.is_on: green
then:
- switch.turn_off: green
- switch.turn_on: red
- switch.turn_on: beeper
- logger.log: Card not found.
- delay: 400ms
- switch.turn_off: beeper
- switch.turn_off: red
- delay: 100ms
- switch.turn_on: red
- switch.turn_on: beeper
- delay: 400ms
- switch.turn_off: beeper
- switch.turn_off: red
- delay: 100ms
- switch.turn_on: red
- switch.turn_on: beeper
- delay: 400ms
- switch.turn_off: beeper
- switch.turn_off: red
- switch.turn_on: green
else:
- switch.turn_off: red
- switch.turn_on: beeper
- logger.log: Card not found.
- delay: 400ms
- switch.turn_off: beeper
- switch.turn_on: red
- delay: 100ms
- switch.turn_off: red
- switch.turn_on: beeper
- delay: 400ms
- switch.turn_off: beeper
- switch.turn_off: red
- delay: 100ms
- switch.turn_off: red
- switch.turn_on: beeper
- delay: 400ms
- switch.turn_off: beeper
- switch.turn_on: red
- service: test_led
then:
- switch.turn_off: green
- switch.turn_off: red
- switch.turn_on: beeper
- switch.turn_on: red
- delay: 500ms
- switch.turn_off: beeper
- switch.turn_on: green
- delay: 500ms
- switch.turn_off: red
- delay: 500ms
- switch.turn_off: green
- delay: 500ms
- switch.turn_on: beeper
- switch.turn_on: red
- delay: 500ms
- switch.turn_off: beeper
- switch.turn_on: green
- delay: 500ms
- switch.turn_off: red
- delay: 500ms
- switch.turn_off: green
- delay: 500ms
- service: beep
then:
- switch.turn_on: beeper
- delay: 200ms
- switch.turn_off: beeper
- delay: 100ms
- switch.turn_on: beeper
- delay: 200ms
- switch.turn_off: beeper
script:
- id: alive
then:
if:
condition:
- lock.is_unlocked: maglock
then:
- logger.log: Lock is unlocked
- switch.turn_on: red
- delay: 50ms
- switch.turn_off: red
- switch.turn_on: green
else:
- logger.log: Lock is locked
- switch.turn_on: green
- delay: 50ms
- switch.turn_off: green
- switch.turn_on: red
- id: dead
then:
if:
condition:
- lock.is_unlocked: maglock
then:
- switch.turn_off: green
- switch.turn_on: red
- delay: 10ms
- switch.turn_off: red
- switch.turn_on: green
- delay: 30ms
- switch.turn_off: green
- switch.turn_on: red
- delay: 10ms
- switch.turn_off: red
- switch.turn_on: green
else:
- switch.turn_off: red
- delay: 10ms
- switch.turn_on: red
- delay: 30ms
- switch.turn_off: red
- delay: 10ms
- switch.turn_on: red
interval:
- interval: 15s
then:
if:
condition:
- wifi.connected
then:
- logger.log: WiFi is Connected
- script.execute: alive
else:
- logger.log: WiFi not Connected
- script.execute: dead
status_led:
pin: GPIO2
sensor:
- platform: custom
lambda: |-
auto wiegand = new WiegandReader(D6, D5);
App.register_component(wiegand);
return {wiegand};
sensors:
name: "${friendly_name} Card ID"
internal: true
on_value:
then:
- homeassistant.tag_scanned: !lambda |-
char buf[16];
sprintf(buf, "%.0f", x);
std::string s = buf;
return s;
- platform: wifi_signal
name: "${friendly_name} WiFi Signal"
update_interval: 60s
lock:
- platform: output
name: "$friendly_name"
id: maglock
output: 'lock_pin'
on_lock:
- switch.turn_off: green
- switch.turn_on: red
- switch.turn_on: beeper
- logger.log: 'Locking lock.'
- delay: 500ms
- switch.turn_off: beeper
on_unlock:
- switch.turn_off: red
- switch.turn_on: green
- switch.turn_on: beeper
- logger.log: 'Unlocking lock.'
- delay: 200ms
- switch.turn_off: beeper
- delay: 100ms
- switch.turn_on: beeper
- delay: 200ms
- switch.turn_off: beeper
output:
- platform: gpio
pin: D1
id: 'lock_pin'
switch:
- platform: gpio
name: "${friendly_name} Beeper"
pin: D0
id: beeper
inverted: yes
internal: yes
restore_mode: ALWAYS_OFF
- platform: gpio
name: "${friendly_name} Red"
pin: D7
id: red
inverted: yes
internal: yes
restore_mode: ALWAYS_ON
- platform: gpio
name: "${friendly_name} Green"
pin: D2
id: green
inverted: yes
internal: yes
restore_mode: ALWAYS_OFF