GithubHelp home page GithubHelp logo

Support RC522 about feature-requests HOT 39 CLOSED

esphome avatar esphome commented on June 1, 2024 4
Support RC522

from feature-requests.

Comments (39)

HausnerR avatar HausnerR commented on June 1, 2024 14

Hey,
I created simple integration through ESPHome custom component API.
Have a look here: https://github.com/HausnerR/esphome-door-lock

It's really simple and exposes various data to HA.
Can be inspiration for your needs.

from feature-requests.

glmnet avatar glmnet commented on June 1, 2024 4

I got some dirty code running already. Is there a need to support other thing than reading the uid only?

from feature-requests.

OttoWinter avatar OttoWinter commented on June 1, 2024 3

Just ordered one and will try to see how difficult it is when it arrives (shipment from china, could take some time)

from feature-requests.

SteveEdson avatar SteveEdson commented on June 1, 2024 3

Can this be merged as an official integration? I have an M5Stack Atom with a RFID module and would love to be able to use it officially.

from feature-requests.

glmnet avatar glmnet commented on June 1, 2024 3

custom_components mechanism should work in v1.15 which was released a few weeks ago.

@blademckain you really mean uart? or i2c?

Thankgs @sgvj

SDA and SCK are the labels for I2C but only SPI is implemented now. However, SPI needs: CS (or sometimes called SS), CLK, MISO, MOSI at least... in the RC522 board when SPI is used, SDA is CS and CLK is SCK

As for the pins to use on the ESP8266 / ESP32, ESPHome supports almost any pin for SPI, it's wise to always try to use the pins given in the examples

from feature-requests.

thoscut avatar thoscut commented on June 1, 2024 1

from feature-requests.

apeeters avatar apeeters commented on June 1, 2024 1

Does this library help? It seems to be more up-to-date: https://github.com/miguelbalboa/rfid

from feature-requests.

schmurtzm avatar schmurtzm commented on June 1, 2024 1

Yes this library seems nice, it is used in the great project esp-rfid.
Hope this will help to implement it in esphome :)

from feature-requests.

gio-dot avatar gio-dot commented on June 1, 2024 1

I don't want to belittle the work of anyone, but there are much better NFC readers on the market (even if it seems that not lot of people know them): they are Wiegand readers; there are many forms of them, all ip 65-68 and they use a specific protocol standardized for access control purpose. There is already a feature request for it, but it seems that no one can help to create a custom component or an integration.
I use them with arduino, there are good libraries for Wiegand protocol (es. https://github.com/monkeyboard/Wiegand-Protocol-Library-for-Arduino)
Take a look here:
https://www.aliexpress.com/af/wiegand-reader.html?d=y&origin=n&SearchText=wiegand+reader&catId=0&initiative_id=SB_20200923231554

from feature-requests.

schmurtzm avatar schmurtzm commented on June 1, 2024 1

Hi, I use the code from HausnerR since a little more than one year and I'm happy with it. Thanks @HausnerR by the way ;)

I've made this jukebox audio launcher for my childs with it.
Happy to see that it is going to be natively implemented in ESPhome 😃

from feature-requests.

rradar avatar rradar commented on June 1, 2024

And here is a link for a working integration/project for the dirt cheap ($1.5 with shipping and tags!) RC522:

from feature-requests.

OttoWinter avatar OttoWinter commented on June 1, 2024

I just had a go at it using this library as a starting point. However, the RC522 seems to be quite a lot "weirder" than the PN532, and the PN532 was already hard to implement since its protocol is quite hard to understand. And that's before having to go through all the debugging.

Especially this method here is a prime example of bad source. It has lots of comments, yes, but it's still very hard to understand and uses ancient style variable re-use.

Putting this on hold until I figure out a better way to implement it.

from feature-requests.

nickrout avatar nickrout commented on June 1, 2024

I was fishing through my electronics drawer and have one of these, so look forward to support.

from feature-requests.

mythicaleinhorn avatar mythicaleinhorn commented on June 1, 2024

I'd also love to see this officially supported.

from feature-requests.

SteveEdson avatar SteveEdson commented on June 1, 2024

from feature-requests.

sgvj avatar sgvj commented on June 1, 2024

Thanks all for your work so far. Looking forward to this.

from feature-requests.

glmnet avatar glmnet commented on June 1, 2024

So, who's gonna help testing it?

from feature-requests.

sgvj avatar sgvj commented on June 1, 2024

@glmnet can do!

from feature-requests.

SteveEdson avatar SteveEdson commented on June 1, 2024

Happy to help test too

from feature-requests.

glmnet avatar glmnet commented on June 1, 2024

Ok, we can use this thread to report any issues / success stories.

In case anybody needs some help setting up the installation of the component, the required yaml is that of pn532, grab files from here and here is an explanation I just googled of how to copy files into your installation.

from feature-requests.

blademckain avatar blademckain commented on June 1, 2024

i would like to try using my RC522 with esphome.
how should i connect the wires?
is it possible to connect via uart?

from feature-requests.

blademckain avatar blademckain commented on June 1, 2024

ok i saw that the library only supports spi
here is the same library but more updated with uart support too

from feature-requests.

sgvj avatar sgvj commented on June 1, 2024

This worked perfectly for me. Scanned tags show up in homeassistant instantly.
THANK YOU SO MUCH @glmnet !

Being a bit green I had to figure out some things please correct me if I'm wrong with these assumptions
Q: What do I connect SDA(on the rc522) to on my dev-board?
A: I used the pin next to miso mosi and clk which has RX in it's definition
Q: What is the CS PIN mentioned in the configuration
A: CS connectes to SDA
Q: Which pins can I use for 'reset' in the configuration
A: Any pin capable of sending (TX or regular)

For others testing
Create 'custom_components' folder next to yaml and then 'rc522' folder and place the files into that.
Then custom_components isn't read by standard release versions of esphome, use these instructions to install dev.

from feature-requests.

blademckain avatar blademckain commented on June 1, 2024

@glmnet yeah i mean really UART
i2c and spi need a lot of wire!

my esp32 near the door is now full and I don't have so many free pins!!

from feature-requests.

blademckain avatar blademckain commented on June 1, 2024

@glmnet
I was wrong!!!
i2c only needs 2 wires too so i2c might be fine for my needs too!
sorry

from feature-requests.

bernardovalente avatar bernardovalente commented on June 1, 2024

I'm having this errors when compiling using the custom component:


INFO Reading configuration /config/esphome/rfid_entrada.yaml...
INFO Generating C++ source...
INFO Compiling app...
INFO Running:  platformio run -d /config/esphome/rfid_entrada
Processing rfid_entrada (board: nodemcuv2; framework: arduino; platform: [email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES: 
 - framework-arduinoespressif8266 3.20704.0 (2.7.4) 
 - tool-esptool 1.413.0 (4.13) 
 - tool-esptoolpy 1.20800.0 (2.8.0) 
 - toolchain-xtensa 2.40802.200502 (4.8.2)
Dependency Graph
|-- <ESPAsyncTCP-esphome> 1.2.3
|   |-- <ESP8266WiFi> 1.0
|-- <ESPAsyncWebServer-esphome> 1.2.7
|   |-- <ESPAsyncTCP-esphome> 1.2.3
|   |   |-- <ESP8266WiFi> 1.0
|   |-- <Hash> 1.0
|   |-- <ESP8266WiFi> 1.0
|-- <ESP8266WiFi> 1.0
|-- <ESP8266mDNS> 1.2
|   |-- <ESP8266WiFi> 1.0
|-- <DNSServer> 1.1.1
|   |-- <ESP8266WiFi> 1.0
|-- <SPI> 1.0
Compiling /data/rfid_entrada/.pioenvs/rfid_entrada/src/main.cpp.o
Compiling /data/rfid_entrada/.pioenvs/rfid_entrada/lib4d9/ESP8266WiFi/WiFiServer.cpp.o
Compiling /data/rfid_entrada/.pioenvs/rfid_entrada/lib4d9/ESP8266WiFi/WiFiServerSecureAxTLS.cpp.o
Compiling /data/rfid_entrada/.pioenvs/rfid_entrada/lib4d9/ESP8266WiFi/WiFiServerSecureBearSSL.cpp.o
Compiling /data/rfid_entrada/.pioenvs/rfid_entrada/lib4d9/ESP8266WiFi/WiFiUdp.cpp.o
Compiling /data/rfid_entrada/.pioenvs/rfid_entrada/liba41/ESPAsyncTCP-esphome/AsyncPrinter.cpp.o
Compiling /data/rfid_entrada/.pioenvs/rfid_entrada/liba41/ESPAsyncTCP-esphome/ESPAsyncTCP.cpp.o
src/main.cpp: In lambda function:
src/main.cpp:270:28: error: expected type-specifier before 'RFIDRC522Sensor'
       auto my_sensor = new RFIDRC522Sensor();
                            ^
src/main.cpp:272:51: error: could not convert '{<expression error>, <expression error>}' from '<brace-enclosed initializer list>' to 'std::vector<esphome::text_sensor::TextSensor*>'
       return {my_sensor->rfid, my_sensor->rfidlast};
                                                   ^
src/main.cpp:273:3: warning: control reaches end of non-void function [-Wreturn-type]
   });
   ^
*** [/data/rfid_entrada/.pioenvs/rfid_entrada/src/main.cpp.o] Error 1
========================== [FAILED] Took 2.12 seconds ==========================

any thoughts?

from feature-requests.

glmnet avatar glmnet commented on June 1, 2024

can you post full yaml?

from feature-requests.

bernardovalente avatar bernardovalente commented on June 1, 2024

sorry had to delete the previous response.

you mean the nodemcu yaml?

esphome:
  name: rfid_entrada
  platform: ESP8266
  board: nodemcuv2

# If buzzer is enabled, notify on api connection success
  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"

# Define switches to control LED and buzzer from HA
switch:
- platform: template
  name: "${friendly_name} Buzzer Enabled"
  id: buzzer_enabled
  icon: mdi:volume-high
  optimistic: true

# Enable SPI interface
spi:
  clk_pin: D0
  miso_pin: D1
  mosi_pin: D2
  
rc522:
  cs_pin: D8
  reset_pin: D3

text_sensor:
  - platform: custom
    lambda: |-
      auto my_sensor = new RFIDRC522Sensor();
      App.register_component(my_sensor);
      return {my_sensor->rfid, my_sensor->rfidlast};
    
    text_sensors:
     - name: "RFID ID (tempo real)"
     - name: "RFID (última leitura)"


# Define the buzzer output
output:
- platform: esp8266_pwm
  pin: D7
  id: buzzer

# Define buzzer as output for RTTTL
rtttl:
  output: buzzer

wifi:
  ssid: "xxxxxxxx"
  password: "xxxxxxxx"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Rfid Entrada Fallback Hotspot"
    password: "xxxxxxxxxxx"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "xxxxxxx"
  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:
  password: "xxxxxxx"

from feature-requests.

Thuurke avatar Thuurke commented on June 1, 2024

@sgvj can you post you're yaml file? Also a bit green here ;)

For others testing
Create 'custom_components' folder next to yaml and then 'rc522' folder and place the files into that.
Then custom_components isn't read by standard release versions of esphome, use these instructions to install dev.

from feature-requests.

sgvj avatar sgvj commented on June 1, 2024

@Thuurke. Short and sweet.

esphome:
  name: devicename
  platform: ESP32
  board: esp-wrover-kit

wifi:

spi:
  clk_pin: GPIO14
  miso_pin: GPIO12
  mosi_pin: GPIO13

rc522:
  cs_pin: GPIO27
  reset_pin: GPIO4
  update_interval: 1s
  on_tag:
    then:
      - homeassistant.tag_scanned: !lambda 'return x;'

captive_portal:
logger:
api:
ota:

from feature-requests.

Thuurke avatar Thuurke commented on June 1, 2024

Oke nice. The logs show:

[D][rc522:157]: Found new tag 'xx-xx-xx-xx'

But I still don't get how this. Which device_id shoudl I use and where do I find it?

trigger:
- platform: event
event_type: tag_scanned
event_data:
device_id: 178D8E87-2945-43C6-9507-xxxxxxxxxxx
tag_id: 4e32a633-241d-4191-8325-0e197a9bb05b

@Thuurke. Short and sweet.

from feature-requests.

sgvj avatar sgvj commented on June 1, 2024

What are you trying to do? Once Homeassistant got the tags on Configuration>Tags page I just create an automation by clicking the robot. My setup dosen't require knowing the specific reading device so that is blank.
The automation looks like:

- id: '1601067933665'
  alias: Tag Skytrain card is scanned
  description: ''
  trigger:
  - platform: tag
    tag_id: 04-CD-37-A2-9F-4F-80
  condition: []
  action:
  - service: media_extractor.play_media
    data:
      media_content_id: https://www.youtube.com/watch?v=69RdQFDuYPI&list=OLAK5uy_kbwoNt5t9bhtUTrWKIw5J5tqePslHIbmE
      media_content_type: audio/youtube
    entity_id: media_player.kitchen_speaker
  mode: single

from feature-requests.

glmnet avatar glmnet commented on June 1, 2024

@bernardovalente your yaml is wrong, for using this component you don't require any custom stuff, check out the sample provided a few post above: #37 (comment)

from feature-requests.

glmnet avatar glmnet commented on June 1, 2024

[D][rc522:157]: Found new tag 'xx-xx-xx-xx'

This just tells you that a tag with that ID was read, and you can use that id if you want ESPHome to react to that tag in a binary_sensor, a local automation. Please refer to the pn532 docs for a detailed explanation, how to use with local automations or how to use with Home Assistant. The same applies for this component.

from feature-requests.

Thuurke avatar Thuurke commented on June 1, 2024

[D][rc522:157]: Found new tag 'xx-xx-xx-xx'

This just tells you that a tag with that ID was read, and you can use that id if you want ESPHome to react to that tag in a binary_sensor, a local automation. Please refer to the pn532 docs for a detailed explanation, how to use with local automations or how to use with Home Assistant. The same applies for this component.

Oke I get it, but I would prefer that the esphome device sends every tag to homeassistant and that the tag handling is done by home assistant. Editing homeassistant yamls is easier than "hardcode"/update the esphome device. But I will experiment with it.

from feature-requests.

Thuurke avatar Thuurke commented on June 1, 2024

Oke I figured it out.
You can do both ways.

In the esphome device with binary sensors
binary_sensor:

  • platform: rc522
    name: tagname
    uid: xx-xx-xx-xx
    or using the new tag system
    on_tag:
    then:
    • homeassistant.tag_scanned: !lambda 'return x;'

Nice!!

[D][rc522:157]: Found new tag 'xx-xx-xx-xx'

This just tells you that a tag with that ID was read, and you can use that id if you want ESPHome to react to that tag in a binary_sensor, a local automation. Please refer to the pn532 docs for a detailed explanation, how to use with local automations or how to use with Home Assistant. The same applies for this component.

Oke I get it, but I would prefer that the esphome device sends every tag to homeassistant and that the tag handling is done by home assistant. Editing homeassistant yamls is easier than "hardcode"/update the esphome device. But I will experiment with it.

from feature-requests.

bernardovalente avatar bernardovalente commented on June 1, 2024

@glmnet I managed to compile and read tags after some changes on the yaml and changed esphome to dev, thanks!

@Thuurke i can see the tags on the log, registered a new tag on HA but it never gets scanned by HA, do yours get updated?

esphome:
  name: rfid_entrada
  platform: ESP8266
  board: nodemcuv2

# If buzzer is enabled, notify on api connection success
  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"

# Define switches to control LED and buzzer from HA
switch:
- platform: template
  name: "${friendly_name} Buzzer Enabled"
  id: buzzer_enabled
  icon: mdi:volume-high
  optimistic: true


wifi:
  ssid: "xxxxxx"
  password: "xxxxxx"
  
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Rfid Entrada Fallback Hotspot"
    password: "xxxxxxxxxx"
    
spi:
  clk_pin: GPIO14
  miso_pin: GPIO12
  mosi_pin: GPIO13

rc522:
  cs_pin: GPIO3
  reset_pin: GPIO0
  update_interval: 1s
  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"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "xxxxxx"
  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:
  password: "xxxx"

# Define the buzzer output
output:
- platform: esp8266_pwm
  pin: GPIO15
  id: buzzer

# Define buzzer as output for RTTTL
rtttl:
  output: buzzer

from feature-requests.

Thuurke avatar Thuurke commented on June 1, 2024

Did you register the esphome device as an home assistant integration? configuration->integrations->+-sign->esphome. After this it should show the scanned tags at confugration->tags

from feature-requests.

bernardovalente avatar bernardovalente commented on June 1, 2024

It's now updating tags, my house door lock tag (nfc?) is not compatible with this reader though and is not registering.

thanks for the help @glmnet @Thuurke

from feature-requests.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.