This is an old revision of the document!
ESP32 Infrared Remote
Introduction
This project extends an existing Home Assistant setup (on Raspberry Pi 4) to control IR‐only devices via an ESP32 acting as an IR transceiver, and to monitor indoor temperature and humidity. We use the YS-IRTM module to sniff and replay NEC‐protocol commands, and a DHT11 sensor to read environment data every 30 minutes. All IR commands and sensor readings are exposed in Home Assistant as entities.
General Description
Block Diagram
Modules and Interactions
Home Assistant Server (Raspberry Pi 4)
Runs ESPHome add-on for firmware management,
API, MQTT and OTA.
Receives IR command events and sensor data from ESP32, exposes them as switches and sensors.
ESP32 IR & Sensor Hub
Connects over Wi-Fi (static IP) to Home Assistant via ESPHome native
API.
Interfaces via UART (irSerial.begin at 9600, SERIAL_8N1) on GPIO 22 (RX) and GPIO 23 (TX) with YS-IRTM.
Reads DHT11 sensor on GPIO 21 every 30 minutes.
YS-IRTM IR Emitter/Receiver Module
38 kHz carrier, hardware-decode for NEC frames only.
Outputs 3-byte payloads on receive; accepts 5-byte payloads to transmit.
DHT11 Temperature & Humidity Sensor
Reads temperature and humidity on GPIO 21; data logged every 30 minutes.
Hardware Design
Parts List
ESP32 development board – 46 RON
YS-IRTM IR emitter/receiver module (38 kHz, NEC) – 22 RON
DHT11 sensor module – 15 RON
4-channel 3.3 V ↔ 5 V level shifter – 11 RON
IR LED + transistor + resistor (built into module)
Jumper wires and breadboard
Total cost: ≈ 94 RON
Connections and Wiring
YS-IRTM Module
LVCC → 3.3 V (ESP32)
HVCC → 5 V (ESP32)
GND → ESP32 GND
TXD → level shifter → ESP32 GPIO 22 (RX)
RXD ← level shifter ← ESP32 GPIO 23 (TX)
DHT11 Sensor
VCC → 3.3 V (ESP32)
GND → ESP32 GND
DATA → ESP32 GPIO 21
IR LED & Driver
IR LED anode → 5 V via resistor → transistor → ESP32 GPIO (configured by module)
Common GND for all devices
Software Design
Environment & Components
ESPHome (YAML-based) for Wi-Fi,
API, MQTT, OTA.
`uart` on GPIO 22/23 at 9600 baud, SERIAL_8N1.
`remote_receiver` + `remote_transmitter` for YS-IRTM NEC frames.
`dht` sensor component on GPIO 21, update_interval: 1800 s.
Custom `text_sensor` lambda to parse 3-byte NEC payloads into HA events.
Receive Handling
1. YS-IRTM decodes NEC IR and emits 3 bytes over UART.
2. ESPHome buffers 3 bytes, then publishes an MQTT/state update (`ir_hub/last_command`).
3. Home Assistant sensor template splits into user-code and command.
Transmit Handling
1. HA invokes `switch.ir_send_<device>_<cmd>`.
2. ESPHome writes 5-byte payload (Addr: 0xA1, F1: 0xF1, UC High, UC Low, Cmd) to UART.
3. YS-IRTM emits NEC frame (9 ms mark, 4.5 ms space, data bits 562 µs @38 kHz).
4. Module replies 0xF1 on success; ESPHome retries once after 1 s if no ack.
Sensor Handling
Known IR Codes
Device | Function | NEC Code |
Sound system | Power On/Off | 01 FE 04 |
Sound system | Mute | 01 FE 09 |
Sound system | Volume Down | 01 FE 05 |
Sound system | Volume Up | 01 FE 06 |
Images
<!– Insert picture: ESP32 in Home Assistant UI –>
<!– Insert picture: Hardware components assembled –>
<!– Insert picture: Graph – Inside Temperature –>
<!– Insert picture: Graph – Inside Humidity –>
Results
All NEC remotes in the stereo system are learned and replayed via Home Assistant. Indoor temperature and humidity are logged every 30 minutes and available in HA dashboards. OTA updates allow wireless firmware management.
Future Improvements (Brief)
Download
Bibliography/Resources
YS-IRTM Module Datasheet
ESPHome Documentation – UART, remote_receiver, remote_transmitter, dht
Home Assistant ESPHome Integration Guide