Since Home Assistant 0.115 was released there is a Integration called “Tags” and makes life so much easier to add a RFID/NFC Reader.
On GitHub there is adonno/tagreader of a ESPHome Project. The guy that owns the repo even has a Website to order a RFID/NFC Kit that even comes with a 3D Printed case.
I built mine by buying the needed PN352 NFC Reader. I already had the rest of the parts in stock but what is needed is the following.
WeMos D1 Mini
PN352 NFC Reader
Piezo Speaker
WS2812 Compatible LED (Optional)
I followed the Wire Diagram from the GitHub Page and copied the tagreader.yaml into ESPHome.
I modified it a bit, had compiling issues with it so here is my modified code. I opted out on the LED since I plan to make this reader battery powered.
wifi:
ssid: "IoT"
password: "YOUR WIFI PASSWORD"
ap:
ssid: "Tagreader Fallback Hotspot"
password: "YOUR WIFI PASSWORD"
captive_portal:
esphome:
name: tagreader
platform: ESP8266
board: d1_mini
on_boot:
priority: -10
then:
- wait_until:
api.connected:
- logger.log: API is connected!
- rtttl.play: "success:d=24,o=5,b=100:c,g,b"
switch:
- platform: template
name: "${friendly_name} Buzzer Enabled"
id: buzzer_enabled
icon: mdi:volume-high
optimistic: true
logger:
api:
services:
- service: rfidreader_tag_ok
then:
- rtttl.play: "beep:d=16,o=5,b=100:b"
- service: rfidreader_tag_ko
then:
- rtttl.play: "beep:d=8,o=5,b=100:b"
- service: play_rtttl
variables:
song_str: string
then:
- rtttl.play: !lambda 'return song_str;'
ota:
spi:
clk_pin: D0
miso_pin: D1
mosi_pin: D2
pn532:
cs_pin: D3
update_interval: 2s
on_tag:
then:
- homeassistant.tag_scanned: !lambda 'return x;'
- if:
condition:
switch.is_on: buzzer_enabled
then:
- rtttl.play: "success:d=24,o=5,b=100:c,g,b"
output:
- platform: esp8266_pwm
pin: D8
id: buzzer
rtttl:
output: buzzer
I had a few issues getting ESPHome to Compile this on a Local System, mostly due to the wxPython package wanting to be a pain in the butt so I just did it on the HA Server then downloaded the compiled binary. I tried to use Tasmotizer to write the firmware binary to the D1 Mini but it would put the D1 Mini into a Bootloop. I had to end up using my Windows VM and use ESPHome Flasher.
After it flashes disconnect the D1 Mini and connect it back up so it does a cold boot. From there go into Home Assistant and under Integrations and select ESPHome and it should add itself into it.
Go into Configuration and select Tags then try scanning a RFID Tag that came with the PN352 and you should see something pop up on the screen.
From there you can create Automation and such for your liking.
Now you can use RFID and NFC with this setup. Sadly my Phone doesn’t have NFC but I can still use the Reader. Keep in mind that RFID and NFC are different. You can’t read RFID Tags with a Phone.