Components

Notes on using ESPhome and cheap, readily available electronic components. Most of this is documented by ESPHome (linked in the info boxes), these are my own notes that also cover some frustrations and pitfalls -- as well as a reference guide for myself (and whoever else).

Sensors

Potentiometer

Potentiometer pinout

IKEA VINDRIKTNING Particulate matter sensor

Hacking and improving the cheap IKEA sensor.

PN532 (RFID/NFC reader)

ManufacturerPhilips semiconductors
NamePN532
Datasheetpn532ds.pdf
AdafruitPN532 NFC/RFID controller breakout board1
ESPHome componentpn5322
ESPHome API docspn532.h File reference3
ESPHome configpackages/sensors/rfid.yml4
VCC\(2.7-5.4V\)5

Supports both SPI and I²C for communicate, reads NFC/RFID tag is able to write to (programmable) tags.

PN532
One variaton of the PN532 board

The PN532 can use both SPI or I²C to commincate, configured with a dip switch on the module. Some boards will have the table for the dip switch printed on the PCB silkscreen (not mine).

If there is no table on the silkscreen, usually2 this is how they are set up:

Protocol12
SPIOFFON
I²CONOFF

Send tag_scanned event to Home Assistant

This will send tag_scanned event with the UID of the tag to Home Assistant when a tag is scanned:

pn532_i2c:     # or pn532_spi
  on_tag:
    then:
      - homeassistant.tag_scanned: !lambda 'return x;'

Which will make your tag show up in Home Assistant under /config/tags where you can assign names to them and create automations. Unfortunately its not possible to use the name/friendly name of the tag in an automation trigger, only the UID (tag_id):

automation:
    - alias: my_tag_scanned
      trigger:
        - platform: tag
          tag_id: DE-AD-BE-EF
      condition: []
      action: []

Helpful sensors

When a tag is scanned, the pn532 component will by default write the tag id (and type) to the logger, so you can retrieve it from there using esphome logs for example (or if you have the web_server component enabled you can use the web ui).

But its useful to just add sensors to the ESPHome node showing this information instead (less hassle to read it, and useful for debugging.

text_sensor:
  - platform: template
    id: tag_uid
    name: "${hostname} Tag UID"

binary_sensor:
  - platform: template
    name: "${hostname} Tag scanned"
    id: tag_scanned
    publish_initial_state: true
    # Return last known state, avoids an 'unknown' state on boot
    # Could also use the on_boot trigger (might be better, the lambda is continuisly evaluated)
    lambda: !-
      return {};
    filters:
      - delayed_off: "10s"

Adds a binary_sensor entity that indicates if a tag has just been scanned, and a text_sensor showing the UID of the most recently scanned tag.

pn532_i2c:
  on_tag:
    then:
      # Writes the tag's uid to the text_sensor
      - text_sensor.template.publish:
          id: tag_uid
          state: !lambda 'return x;'

      # Set the binary_sensor to true/on
      # binary_sensor state intead of relying on automations
      - binary_sensor.template.publish:
          id: tag_scanned
          state: ON

  on_tag_removed:
    then:
      # Set the binary_sensor back to false/off.
      - binary_sensor.template.publish:
          id: tag_scanned
          state: OFF

This uses automations provided by the pn532 component in ESPHome (on_tag and on_tag_removed), but it would be preferrable to just use a lambda in the state attribute of the templated text_sensor and binary_sensor.

LD2410 mmWave radar

Lessons learned, and how to use it to detect static presence reliably using different still_energy values to signal on/true and off/false.

Generic PIR

Simple and easy

Displays

MAX7219 LED matrix

HD44780 LCD display

I have some unusual model "2004A-V1.3". Based on the Arduino forum thread and the linked AliExpress page, this is probably an LCD module called SPLC780D that has an onboard I2C adapter/interface called AIP31066. Found a Github repo enjoyneering/LiquidCrystal_I2C with detailed info.

Arduino forum: [https://forum.arduino.cc/t/funky-20x4-lcd-with-interesting-circuitry/1136532/3]

Almost the same: [https://make.net.za/product/20x4-lcd-white-on-blue/]

SSD1306 OLED display

ManufacturerSolomon systech
NameSSD1306
DatasheetSSD1306.pdf
AdafruitMonochrome OLED breakouts, adafruit/Adafruit_SSD1306
Arduino referenceAdafruit SSD1306
ESPHome componentssd1306_i2c7
ESPHome configpackages/displays/ssd1306.yml4
VCC\(3.3 V\), some breakout boards also support \(5 V\).

On the Wemos S2 Mini boards (possibly other ESP32 boards as well), this display will only work with the arduino framework:

esp32:
  board: lolin_s2_mini
  variant: ESP32S2
  framework:
    type: arduino

Any GPIO pins can be used on (most?) ESP32 boards

i2c:
  sda: GPIO16
  scl: GPIO18

font:
  - file: "NotoSansMono-Regular.ttf"
    id: notomono24
    size: 24

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3C
    lambda: |-
      it.printf(0, 30, id(notomono24), TextAlign::BASELINE_LEFT, "sudo.is");

I've found that the font Noto Sans Mono looks good on this display.

PCD8544 Display (Nokia 5110/3310)

ManufacturerPhilips semiconductors
NamePCD8544
Datasheetpcd8544.pdf
AdafruitNokia 5110/3310 monochdome LCD8
ESPHome componentpcd85449
ESPHome API docsesphome::pcd8544::PCD854410
ESPHome configpackages/displays/pcd8544.yml4
VCC\(3.3 V\)9
Driver for esp-idfESP32-PCD8544 documentation11

The display that was used in the Nokia 5110 and 3310 phones, the resolution is 84x48 px. It's still available today (and cheap). They are probably displays disassembled from old Nokia phones and then hand-assembled to PCBs with a LED backlight11.

Wiring

Following an example12 of how the display can be wired to a standard ESP32 dev board:

PCD8544 pinESP32 pin
RSTGPIO14
CE (CS)GPIO05
DCGPIO19
DIN (DN/MOSI)GPIO23
CLK (SCLK/SCK)GPIO18
VCC3V3
BL (LIGHT)GPIO27
GNDGND

ESPHome

There is a GitHub issue on the ESPHome repo:


References