This is an old revision of the document!
ESP32 Infrared Remote Hub (Finished)
Overview
This project delivers a universal infrared (IR) transceiver based on an ESP32, seamlessly integrated with Home Assistant via ESPHome. The hub can learn and replay any remote protocol—whether NEC, extended‐NEC, or raw pulse sequences—allowing full control of air conditioners, audio systems, and other IR-controlled devices. All IR commands are exposed in Home Assistant as switches and buttons, enabling automation, voice control, and OTA updates without additional hardware beyond the ESP32 and simple IR receiver/emitter components.
System Architecture
Block Diagram
Modules and Interactions
Hardware Implementation
Parts List
ESP32 development board
TSOP38×38 IR demodulator
IR LED + transistor + resistor for emitter driver
4-channel 3.3 V ↔ 5 V level shifter (for optional serial devices)
Jumper wires and breadboard or PCB
Total cost: ≈ 85 RON
Connections and Wiring
IR Receiver (TSOP) → ESP32 GPIO (e.g. 23)
IR LED Anode → 5 V through current-limiting resistor → transistor → ESP32 GPIO (e.g. 22) for carrier enable
Transistor Base → ESP32 GPIO through base resistor
GND/common for ESP32, TSOP, and emitter driver
(Optional) UART RX/TX via level shifter if using serial modules
Design Rationale
Switched from YS-IRTM module to TSOP demodulator to capture raw pulses and support proprietary protocols (e.g. Yamato AC).
On-board IR LED driver ensures full carrier strength and reliable distance.
Level shifter retained for future expansions requiring TTL serial devices.
Firmware and Software
Development Environment
ESPHome in Docker: Containerized with host-network mode, USB mapping (`/dev/ttyUSB0`), and OTA port (3232) exposed.
YAML-First Configuration: Single `ir_hub.yaml` defines Wi-Fi, static IP (`192.168.0.136`),
API, OTA, logger, UART (if needed), and switch entities.
Static IP Assignment: Ensures reliable discovery and OTA, bypassing mDNS issues in Docker.
IR Signal Handling
Learning (Capture)
The TSOP38×38 demodulator outputs clean digital bursts.
ESPHome’s `remote_receiver` component timestamps each pulse/space.
A custom lambda buffers pulses into arrays, then exposes them via an MQTT/state event or as a Home Assistant sensor for inspection.
Replaying (Transmit)
ESPHome’s `remote_transmitter` component drives the IR LED at 38 kHz.
Learned pulse arrays are stored in flash (as `raw_codes`), then replayed on command via a Home Assistant switch.
Automatic retries and acknowledgments ensure reliable transmission.
Home Assistant Integration
Entity Exposure: Each learned code appears as a `switch.<device>_<command>` in Home Assistant.
OTA Updates: After initial USB flash, firmware updates are pushed over-the-air from the ESPHome container.
Dashboard Controls: Custom Lovelace cards allow “Learn”, “Replay”, and “Delete” actions per IR code.
Results
Universal IR Hub: Successfully captures and replays NEC, extended protocols, and custom raw timings.
Seamless HA Control: All IR actions are directly automatable and available for voice assistants.
Robust OTA Workflow: New features and learned codes can be deployed wirelessly without on-site USB access.
Conclusions
By leveraging a simple TSOP demodulator, ESPHome’s flexible firmware, and Home Assistant’s automation capabilities, this ESP32-based hub becomes a truly universal IR bridge. It not only replicates existing remotes but can learn new ones on-the-fly, integrate with smart home automations, and evolve through OTA updates.
Download
Bibliography/Resources
ESPHome Documentation – Getting Started, UART, Remote Receiver/Transmitter
Home Assistant – ESPHome Integration Guide
TSOP38×38 Datasheet – Vishay