
# 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)