PN532 NFC/RFID Controller Hub

The pn532 component allows you to use PN532 NFC/RFID controllers (datasheet, adafruit) with esphomelib. This component is a global hub that establishes the connection to the PN532 via SPI and outputs its data. Using the PN532 binary sensors you can then create individual binary sensors that track if an NFC/RFID tag is currently detected by the PN532.

See Setting Up Tags for information on how to setup individual binary sensors for this component.

As the communication with the PN532 is done using SPI for this integration, you need to set the two switches on the board to the SPI mode (usually by setting the first one to OFF and the second one to ON). Additionally, you need to have an spi bus in your configuration with both the miso_pin and mosi_pin set.

# Example configuration entry
  clk_pin: D0
  miso_pin: D1
  mosi_pin: D2

  cs_pin: D3
  update_interval: 1s

  - platform: pn532
    uid: 74-10-37-94
    name: "PN532 NFC Tag"

Configuration variables:

  • cs_pin (Required, Pin Schema): The pin on the ESP that the chip select line is connected to.
  • update_interval (Optional, Time): The duration of each scan on the PN532. This affects the duration that the individual binary sensors stay active when they’re found. If a device is not found within this time window, it will be marked as not present. Defaults to 1s.
  • on_tag (Optional, Automation): An automation to perform when a tag is read. See on_tag.
  • spi_id (Optional, ID): Manually specify the ID of the SPI Component if you want to use multiple SPI buses.
  • id (Optional, ID): Manually specify the ID for this component.

Example for hooking up the PN532 via SPI. Notice the position of the two switches on the right.


This automation will be triggered when the PN532 module responds with a tag. Please note that this can be called quite often (with an interval of update_interval) as it’s triggered repeatedly if the tag is re-read many times.

The parameter x this trigger provides is of type std::string and is the tag UID in the format 74-10-37-94. The configuration below will for example publish the tag ID on the MQTT topic pn532/tag.

  # ...
      - mqtt.publish:
          topic: pn532/tag
          payload: !lambda 'return x;'