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
IKEA VINDRIKTNING Particulate matter sensor
Hacking and improving the cheap IKEA sensor.
PN532 (RFID/NFC reader)
Manufacturer | Philips semiconductors |
---|---|
Name | PN532 |
Datasheet | pn532ds.pdf |
Adafruit | PN532 NFC/RFID controller breakout board1 |
ESPHome component | pn532 2 |
ESPHome API docs | pn532.h File reference3 |
ESPHome config | packages/sensors/rfid.yml 4 |
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.
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:
Protocol | 1 | 2 |
---|---|---|
SPI | OFF | ON |
I²C | ON | OFF |
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
ESPHome | |
---|---|
Component | display 6 |
Cookbook | Time & Temperature on OLED Display |
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
Manufacturer | Solomon systech |
---|---|
Name | SSD1306 |
Datasheet | SSD1306.pdf |
Adafruit | Monochrome OLED breakouts, adafruit/Adafruit_SSD1306 |
Arduino reference | Adafruit SSD1306 |
ESPHome component | ssd1306_i2c 7 |
ESPHome config | packages/displays/ssd1306.yml 4 |
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)
Manufacturer | Philips semiconductors |
---|---|
Name | PCD8544 |
Datasheet | pcd8544.pdf |
Adafruit | Nokia 5110/3310 monochdome LCD8 |
ESPHome component | pcd8544 9 |
ESPHome API docs | esphome::pcd8544::PCD8544 10 |
ESPHome config | packages/displays/pcd8544.yml 4 |
VCC | \(3.3 V\)9 |
Driver for esp-idf | ESP32-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 pin | ESP32 pin |
---|---|
RST | GPIO14 |
CE (CS ) | GPIO05 |
DC | GPIO19 |
DIN (DN /MOSI ) | GPIO23 |
CLK (SCLK /SCK ) | GPIO18 |
VCC | 3V3 |
BL (LIGHT ) | GPIO27 |
GND | GND |
ESPHome
There is a GitHub issue on the ESPHome repo:
esphome/issues#1519
: PCD 8544 (Nokia 5110/3310) Display all pixels black