Add PN5180 Support
Describe the problem you have/What new integration you would like
Add Support for the PN5180 NFC Reader to ESPhome
Please describe your use case for this integration and alternatives you've tried:
Additional context
I have several Projects creates using the Arduino IDE with an ESP8266 and the PN5180. I would Like to integrate some in Home Assistent using ESPhome, but there ist no Support for the PN5180 yet.
There ist an Arduino/ESP Lib https://github.com/ATrappmann/PN5180-Library that is working great on ESP8266 and ESP32 when creating Projects using the Arduino IDE
Hi, I upvote this requests !
Does @hobbypunk90 could do this ? I see you do it for an other reader recently ?
@hobbypunk90 Could you do it for us please ?
Below code is for ISO15693. If you want to use normal pn5180, youll have to change code to suite your needs
together with chatgpt, i managed to write the following... it exposes a text sensor and simply sets the value of the text sensor to the uid being read. No security whatsoever, so not suitable for production/secure stuff, but it works.
Save it as custom_components/pn5180/pn5180_component.h next to the esphome config file
#pragma once
#include "esphome.h"
#include "PN5180.h"
#include "PN5180ISO15693.h"
using namespace esphome;
class PN5180Component : public PollingComponent, public text_sensor::TextSensor {
public:
// Constructor with pin assignments and update interval
PN5180Component(uint8_t pin_ss, uint8_t pin_busy, uint8_t pin_rst, uint32_t update_interval)
: PollingComponent(update_interval), pn5180_(pin_ss, pin_busy, pin_rst) {}
// Setup function, called once during initialization
void setup() override {
// Initialize the PN5180 instance
pn5180_.begin();
// Reset and set up the RF settings for the PN5180
pn5180_.reset();
pn5180_.setupRF();
}
// Update function, called periodically according to the update interval
void update() override {
static bool default_state = false;
uint8_t uid[8];
// Attempt to read the UID of an ISO15693 tag
ISO15693ErrorCode rc = pn5180_.getInventory(uid);
if (ISO15693_EC_OK == rc) {
// Convert the UID to a string
String uid_str = "";
for (uint8_t i = 0; i < sizeof(uid); i++) {
uid_str += String(uid[i] < 0x10 ? " 0" : " ");
uid_str += String(uid[i], HEX);
}
uid_str.trim();
// Print the UID to the log
ESP_LOGI("pn5180", "Read UID: %s", uid_str.c_str());
// Update the text sensor with the UID value
publish_state(uid_str.c_str());
default_state = false;
// Reset and set up the RF settings for the PN5180 for the next read
pn5180_.reset();
pn5180_.setupRF();
} else {
// If reading the UID fails, log an error and update the text sensor to show no tag detected
if (!default_state)
{
ESP_LOGI("pn5180", "No NFC detected");
publish_state("No NFC detected");
}
default_state = true;
}
}
protected:
// The PN5180 instance used for reading ISO15693 tags
PN5180ISO15693 pn5180_;
};
Use it with the following in your esphome configuratino file:
esphome:
name: fancyname
platform: ESP32
board: esp32dev
includes:
- custom_components/pn5180/
libraries:
- SPI
- https://github.com/ATrappmann/PN5180-Library.git#master
(snip)
text_sensor:
- platform: custom
lambda: |-
auto pn5180_component = new PN5180Component(16, 5, 17, 500); // PIN ss, busy, rst and poll interval (every 500ms)
App.register_component(pn5180_component);
return {pn5180_component};
text_sensors:
name: "NFC tag scanner"
By referencing the github of atrappman directly; i avoid using version 1.5 of the library: https://registry.platformio.org/libraries/atrappmann/PN5180%20Library/installation
Also, compiling fails when using esphome integration on home assistant. But on my local pc it works.
Providing your yml file is correct, it should expose the text sensor to home assistant
up
up
Up !
Did anyone succeeed in creating an native live custom component for the PN5180? I would very much like to set up a stand alone reader featuring this cheap and widely available reader because it is one of the few capable of reading ISO15693 Tags like found in branded music figurines. This could then be used to trigger home assistant automations.
Did anyone succeeed in creating an native live custom component for the PN5180? I would very much like to set up a stand alone reader featuring this cheap and widely available reader because it is one of the few capable of reading ISO15693 Tags like found in branded music figurines. This could then be used to trigger home assistant automations.
If you have zigbee2mqtt, you could use this reader : THZReader
@TLongstride good work w/ THZReader.. Also, Up :D
any chance to get this into esphome?
Up