first commit - running code
This commit is contained in:
commit
897683f0e7
|
@ -0,0 +1,124 @@
|
|||
|
||||
# ESP Fingerprint for FHEM
|
||||
|
||||
[ESPHome](https://esphome.io/components/fingerprint_grow.html) firmware for ESP32 or ESP8266 to manage and use a R503-RGB Fingerprint Reader over MQTT.
|
||||
|
||||
Supported features of my code:
|
||||
|
||||
* Control R503 LED
|
||||
* LED colors: RED, BLUE, PURPLE, GREEN, YELLOW, CYAN and WHITE
|
||||
* LED effects: BREATHING, FLASHING, ALWAYS_ON, ALWAYS_OFF, GRADUAL_ON and GRADUAL_OFF
|
||||
* enroll a fingerprint to the reader
|
||||
* delete fingerprint
|
||||
|
||||
|
||||
<img src="doc/r503.gif" width="300">
|
||||
|
||||
|
||||
# Getting started
|
||||
|
||||
## Config pins and effects
|
||||
|
||||
Set correct GPIO Pins in `fingerprintdoor.yaml`
|
||||
|
||||
```yaml
|
||||
# -----------------------------
|
||||
# Config
|
||||
# -----------------------------
|
||||
devicename: fingerprintdoor
|
||||
reader_rx_pin: GPIO16
|
||||
reader_tx_pin: GPIO17
|
||||
reader_sensor_pin: GPIO5
|
||||
speed_flash: "100"
|
||||
count_flash: "4"
|
||||
speed_breath: "75"
|
||||
count_breath: "7"
|
||||
speed_gradual_off: "200"
|
||||
speed_gradual_on: "35"
|
||||
```
|
||||
|
||||
## Wifi and MQTT
|
||||
Create a `secrets.yaml`file in your project folder
|
||||
|
||||
```yaml
|
||||
wifi_ssid: "YourSSID"
|
||||
wifi_password: "YourPASS"
|
||||
ota_password: "OtaPass"
|
||||
mqtt_ip: "192.168.1.1"
|
||||
mqtt_user: ""
|
||||
mqtt_password: ""
|
||||
```
|
||||
## Flash to ESP
|
||||
Follow this [GUIDE](https://esphome.io/guides/installing_esphome.html) to install ESPHome and flash it to your device with:
|
||||
|
||||
```shell
|
||||
esphome run fingerprintdoor.yaml --device COM4
|
||||
```
|
||||
> Note: COM Port may differ, change it to your COM port
|
||||
## FHEM MQTT2 device
|
||||
|
||||
```shell
|
||||
defmod myFingerprint MQTT2_DEVICE fingerprintdoor
|
||||
attr myFingerprint event-on-change-reading .*
|
||||
attr myFingerprint room MQTT2_DEVICE
|
||||
attr myFingerprint setList GREEN:on,off,breathe,flash fingerprintdoor/led green_$EVTPART1\
|
||||
BLUE:on,off,breathe,flash fingerprintdoor/led blue_$EVTPART1\
|
||||
RED:on,off,breathe,flash fingerprintdoor/led red_$EVTPART1\
|
||||
PURPLE:on,off,breathe,flash fingerprintdoor/led purple_$EVTPART1\
|
||||
WHITE:on,off,breathe,flash fingerprintdoor/led white_$EVTPART1\
|
||||
CYAN:on,off,breathe,flash fingerprintdoor/led cyan_$EVTPART1\
|
||||
YELLOW:on,off,breathe,flash fingerprintdoor/led yellow_$EVTPART1\
|
||||
cancel:noArg fingerprintdoor/cancel_enroll\
|
||||
enroll fingerprintdoor/enroll $EVTPART1\
|
||||
delete fingerprintdoor/delete $EVTPART1\
|
||||
\
|
||||
```
|
||||
|
||||
## Usage in FHEM
|
||||
|
||||
### Enroll new finger
|
||||
|
||||
Syntax:
|
||||
```shell
|
||||
set <fhem device name> enroll <finger ID>
|
||||
```
|
||||
|
||||
Example:
|
||||
```shell
|
||||
set myFingerprint enroll 1
|
||||
```
|
||||
|
||||
>Note: Enrollment cancel ist possible with:
|
||||
```shell
|
||||
set myFingerprint cancel
|
||||
```
|
||||
|
||||
### Delete finger
|
||||
|
||||
Syntax:
|
||||
```shell
|
||||
set <fhem device name> delete <finger ID>
|
||||
```
|
||||
|
||||
Example:
|
||||
```shell
|
||||
set myFingerprint delete 1
|
||||
```
|
||||
|
||||
### Set Led color and effect
|
||||
Syntax:
|
||||
```shell
|
||||
set <fhem device name> <COLOR> <effect>
|
||||
```
|
||||
|
||||
Example:
|
||||
```shell
|
||||
set myFingerprint BLUE flash
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Credits
|
||||
[ESPHome project](https://esphome.io/)
|
||||
|
||||
[Helpful ESPHome tutorials](https://www.youtube.com/@Smarthomeyourself)
|
Binary file not shown.
After Width: | Height: | Size: 4.7 MiB |
|
@ -0,0 +1,262 @@
|
|||
substitutions:
|
||||
# -----------------------------
|
||||
# Config
|
||||
# -----------------------------
|
||||
devicename: fingerprintdoor
|
||||
reader_rx_pin: GPIO16
|
||||
reader_tx_pin: GPIO17
|
||||
reader_sensor_pin: GPIO5
|
||||
door_sensor_pin: GPIO4
|
||||
speed_flash: "100"
|
||||
count_flash: "4"
|
||||
speed_breath: "75"
|
||||
count_breath: "7"
|
||||
speed_gradual_off: "200"
|
||||
speed_gradual_on: "35"
|
||||
|
||||
|
||||
# --------------------------------------------------------
|
||||
|
||||
esphome:
|
||||
name: $devicename
|
||||
|
||||
esp32:
|
||||
board: nodemcu-32s
|
||||
framework:
|
||||
type: arduino
|
||||
|
||||
# Enable logging
|
||||
logger:
|
||||
|
||||
ota:
|
||||
password: !secret ota_password
|
||||
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
|
||||
# Enable fallback hotspot (captive portal) in case wifi connection fails
|
||||
ap:
|
||||
ssid: "Fingerprintdoor Fallback Hotspot"
|
||||
password: !secret $ota_password
|
||||
|
||||
captive_portal:
|
||||
|
||||
web_server:
|
||||
port: 80
|
||||
|
||||
# MQTT Actions
|
||||
mqtt:
|
||||
broker: !secret mqtt_ip
|
||||
username: !secret mqtt_user
|
||||
password: !secret mqtt_password
|
||||
client_id: $devicename
|
||||
id: mqtt_client
|
||||
on_message: !include "includes/led_effects.yaml"
|
||||
|
||||
|
||||
# Fingerpint functions
|
||||
text_sensor:
|
||||
# ENROLL
|
||||
- platform: mqtt_subscribe
|
||||
name: "MQTT Sub Fingerprint enroll"
|
||||
id: mqtt_sub_enr
|
||||
qos: 0
|
||||
topic: $devicename/enroll
|
||||
on_value:
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return atoi(id(mqtt_sub_enr).state.c_str()) > 0;'
|
||||
then:
|
||||
- lambda: |-
|
||||
ESP_LOGD("main", "Enroll Finger ID: %s", x.c_str());
|
||||
- fingerprint_grow.enroll:
|
||||
finger_id: !lambda return atoi(x.c_str());
|
||||
num_scans: 2
|
||||
- text_sensor.template.publish:
|
||||
id: fingerprint_state
|
||||
state: "Place a finger on the reader"
|
||||
else:
|
||||
- logger.log: "Error, try again!"
|
||||
|
||||
# CANCEL ENROLL
|
||||
- platform: mqtt_subscribe
|
||||
name: "MQTT Sub Fingerprint cancel"
|
||||
id: mqtt_sub_abrt
|
||||
qos: 0
|
||||
topic: $devicename/cancel_enroll
|
||||
on_value:
|
||||
- text_sensor.template.publish:
|
||||
id: fingerprint_state
|
||||
state: "cancelling enrollment"
|
||||
- fingerprint_grow.cancel_enroll:
|
||||
|
||||
# DELETE ID
|
||||
- platform: mqtt_subscribe
|
||||
name: "MQTT Sub Fingerprint delete"
|
||||
id: mqtt_sub_del
|
||||
qos: 0
|
||||
topic: $devicename/delete
|
||||
on_value:
|
||||
- lambda: |-
|
||||
ESP_LOGD("main", "Delete Finger ID: %s", x.c_str());
|
||||
- fingerprint_grow.delete:
|
||||
finger_id: !lambda return atoi(x.c_str());
|
||||
# Update the template text sensor for visual feedback
|
||||
- text_sensor.template.publish:
|
||||
id: fingerprint_state
|
||||
state: !lambda 'return "Deleted " + to_string(x.c_str());'
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: FLASHING
|
||||
speed: 50
|
||||
color: WHITE
|
||||
count: 2
|
||||
|
||||
# DELETE ALL!!!
|
||||
- platform: mqtt_subscribe
|
||||
name: "MQTT Sub Fingerprint delete all"
|
||||
id: mqtt_sub_del_all
|
||||
qos: 0
|
||||
topic: $devicename/deleteall
|
||||
on_value:
|
||||
- fingerprint_grow.delete_all:
|
||||
# Update the template text sensor for visual feedback
|
||||
- text_sensor.template.publish:
|
||||
id: fingerprint_state
|
||||
state: !lambda 'return "Deleted ALL";'
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: FLASHING
|
||||
speed: 50
|
||||
color: WHITE
|
||||
count: 6
|
||||
|
||||
- platform: template
|
||||
name: "Template Text Sensor"
|
||||
id: fingerprint_state
|
||||
|
||||
|
||||
#########################
|
||||
|
||||
sensor:
|
||||
- platform: wifi_signal
|
||||
name: "WiFi Signal Sensor"
|
||||
update_interval: 90s
|
||||
state_topic: $devicename/rssi
|
||||
|
||||
uart:
|
||||
rx_pin: $reader_rx_pin
|
||||
tx_pin: $reader_tx_pin
|
||||
baud_rate: 57600
|
||||
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
pin: $reader_sensor_pin
|
||||
name: Touch Sensor
|
||||
device_class: motion
|
||||
state_topic: $devicename/touch
|
||||
filters:
|
||||
- invert:
|
||||
#- delayed_on: 50ms
|
||||
- delayed_off: 100ms
|
||||
- delayed_on_off: 150ms
|
||||
|
||||
# Door Sensor
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: $door_sensor_pin
|
||||
mode:
|
||||
input: true
|
||||
pullup: true
|
||||
name: "Main Door"
|
||||
device_class: window
|
||||
filters:
|
||||
- delayed_on: 10ms
|
||||
|
||||
|
||||
# Example button configuration
|
||||
button:
|
||||
- platform: template
|
||||
name: Test Button
|
||||
id: my_button
|
||||
|
||||
|
||||
fingerprint_grow:
|
||||
sensing_pin: $reader_sensor_pin
|
||||
on_finger_scan_matched:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: BREATHING
|
||||
speed: 200
|
||||
color: GREEN
|
||||
count: 1
|
||||
- text_sensor.template.publish:
|
||||
id: fingerprint_state
|
||||
state: !lambda 'return "Authorized finger " + to_string(finger_id) + ", confidence " + to_string(confidence);'
|
||||
# Pushing a tag_scanned event based on finger_id only if confidence is greater than 50
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return confidence > 50;'
|
||||
then:
|
||||
- logger.log: "Matched höher 50"
|
||||
# todo - push confidence and finger ID to MQTT
|
||||
on_finger_scan_unmatched:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: FLASHING
|
||||
speed: 25
|
||||
color: RED
|
||||
count: 2
|
||||
- text_sensor.template.publish:
|
||||
id: fingerprint_state
|
||||
state: "Unauthorized finger"
|
||||
on_enrollment_scan:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: FLASHING
|
||||
speed: 25
|
||||
color: BLUE
|
||||
count: 2
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: ALWAYS_ON
|
||||
speed: 0
|
||||
color: PURPLE
|
||||
count: 0
|
||||
- text_sensor.template.publish:
|
||||
id: fingerprint_state
|
||||
state: !lambda 'return "Enrolling into slot " + to_string(finger_id) + ", scanned " + to_string(scan_num) + " time(s)"; '
|
||||
on_enrollment_done:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: BREATHING
|
||||
speed: 100
|
||||
color: BLUE
|
||||
count: 2
|
||||
- text_sensor.template.publish:
|
||||
id: fingerprint_state
|
||||
state: !lambda 'return "Enrolled into slot " + to_string(finger_id);'
|
||||
|
||||
on_enrollment_failed:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: FLASHING
|
||||
speed: 25
|
||||
color: RED
|
||||
count: 6
|
||||
- if:
|
||||
condition:
|
||||
not:
|
||||
# Checks if enroll canceled
|
||||
text_sensor.state:
|
||||
id: fingerprint_state
|
||||
state: "cancelling enrollment"
|
||||
then:
|
||||
- text_sensor.template.publish:
|
||||
id: fingerprint_state
|
||||
state: !lambda 'return "Failed to enroll into slot " + to_string(finger_id);'
|
||||
# Retry enrollment into the same slot
|
||||
- delay: 3s
|
||||
- text_sensor.template.publish:
|
||||
id: fingerprint_state
|
||||
state: !lambda 'return "Retrying enrollment into slot " + to_string(finger_id) + " in 3 seconds...";'
|
||||
- delay: 3s
|
||||
- fingerprint_grow.enroll: !lambda 'return finger_id;'
|
||||
else:
|
||||
- logger.log: "Enrollment aborted"
|
||||
- text_sensor.template.publish:
|
||||
id: fingerprint_state
|
||||
state: "Enrollment canceled"
|
|
@ -0,0 +1,251 @@
|
|||
- topic: $devicename/led
|
||||
payload: green_on
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: GRADUAL_ON
|
||||
speed: $speed_gradual_on
|
||||
color: GREEN
|
||||
count: 0
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: green_off
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: GRADUAL_OFF
|
||||
speed: $speed_gradual_off
|
||||
color: GREEN
|
||||
count: 0
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: green_breathe
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: BREATHING
|
||||
speed: $speed_breath
|
||||
color: GREEN
|
||||
count: $count_breath
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: green_flash
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: FLASHING
|
||||
speed: $speed_flash
|
||||
color: GREEN
|
||||
count: $count_flash
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: red_on
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: GRADUAL_ON
|
||||
speed: $speed_gradual_on
|
||||
color: RED
|
||||
count: 0
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: red_off
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: GRADUAL_OFF
|
||||
speed: $speed_gradual_off
|
||||
color: RED
|
||||
count: 0
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: red_breathe
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: BREATHING
|
||||
speed: $speed_breath
|
||||
color: RED
|
||||
count: $count_breath
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: red_flash
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: FLASHING
|
||||
speed: $speed_flash
|
||||
color: RED
|
||||
count: $count_flash
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: purple_on
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: GRADUAL_ON
|
||||
speed: $speed_gradual_on
|
||||
color: PURPLE
|
||||
count: 0
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: purple_off
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: GRADUAL_OFF
|
||||
speed: $speed_breath
|
||||
color: PURPLE
|
||||
count: 0
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: purple_breathe
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: BREATHING
|
||||
speed: $speed_breath
|
||||
color: PURPLE
|
||||
count: $count_breath
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: purple_flash
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: FLASHING
|
||||
speed: $speed_flash
|
||||
color: PURPLE
|
||||
count: $count_flash
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: yellow_on
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: GRADUAL_ON
|
||||
speed: $speed_gradual_on
|
||||
color: YELLOW
|
||||
count: 0
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: yellow_off
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: GRADUAL_OFF
|
||||
speed: $speed_breath
|
||||
color: YELLOW
|
||||
count: 0
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: yellow_breathe
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: BREATHING
|
||||
speed: $speed_breath
|
||||
color: YELLOW
|
||||
count: $count_breath
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: yellow_flash
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: FLASHING
|
||||
speed: $speed_flash
|
||||
color: YELLOW
|
||||
count: $count_flash
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: cyan_on
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: GRADUAL_ON
|
||||
speed: $speed_gradual_on
|
||||
color: CYAN
|
||||
count: 0
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: cyan_off
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: GRADUAL_OFF
|
||||
speed: $speed_breath
|
||||
color: CYAN
|
||||
count: 0
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: cyan_breathe
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: BREATHING
|
||||
speed: $speed_breath
|
||||
color: CYAN
|
||||
count: $count_breath
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: cyan_flash
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: FLASHING
|
||||
speed: $speed_flash
|
||||
color: CYAN
|
||||
count: $count_flash
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: white_on
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: GRADUAL_ON
|
||||
speed: $speed_gradual_on
|
||||
color: WHITE
|
||||
count: 0
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: white_off
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: GRADUAL_OFF
|
||||
speed: $speed_breath
|
||||
color: WHITE
|
||||
count: 0
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: white_breathe
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: BREATHING
|
||||
speed: $speed_breath
|
||||
color: WHITE
|
||||
count: $count_breath
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: white_flash
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: FLASHING
|
||||
speed: $speed_flash
|
||||
color: WHITE
|
||||
count: $count_flash
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: blue_on
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: GRADUAL_ON
|
||||
speed: $speed_gradual_on
|
||||
color: BLUE
|
||||
count: 0
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: blue_off
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: GRADUAL_OFF
|
||||
speed: $speed_breath
|
||||
color: BLUE
|
||||
count: 0
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: blue_breathe
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: BREATHING
|
||||
speed: $speed_breath
|
||||
color: BLUE
|
||||
count: $count_breath
|
||||
|
||||
- topic: $devicename/led
|
||||
payload: blue_flash
|
||||
then:
|
||||
- fingerprint_grow.aura_led_control:
|
||||
state: FLASHING
|
||||
speed: $speed_flash
|
||||
color: BLUE
|
||||
count: $count_flash
|
Loading…
Reference in New Issue