This is an old revision of the document!


ESP32 Infrared Remote

Metadata

  • Author: Petru Zincenco
  • Master: IA
  • Date Completed: 21 May 2025

Introduction

This project extends an existing Home Assistant setup (on Raspberry Pi 3) to control IR-only devices via an ESP32 acting as an IR transceiver. We use the YS-IRTM module to sniff and replay NEC-protocol commands, exposing each learned code as a Home Assistant entity. With this hub in place, you can automate your stereo system and air conditioner directly from Home Assistant or a mobile app.

General Description

Block Diagram

Modules and Interactions

  • Home Assistant Server (Raspberry Pi 3)
    1. Wi-Fi-connected, runs ESPHome add-on for firmware management and OTA.
    2. Receives MQTT/API updates from ESP32 and presents IR codes as switches/buttons.
  • ESP32 IR Hub
    1. Connects over Wi-Fi to Home Assistant (static IP).
    2. Interfaces via UART (9600 baud) with the YS-IRTM IR emitter/receiver.
    3. Implements ESPHome `remote_receiver` and `remote_transmitter` components.
  • YS-IRTM IR Emitter/Receiver Module
    1. 38 kHz carrier, hardware‐decode for NEC frames only.
    2. Outputs 3‐byte payloads (User Code High, User Code Low, Command) on receive.
    3. Accepts 5-byte payloads (Address, F1, UC High, UC Low, Cmd) to transmit NEC codes.

Hardware Design

Parts List

  • ESP32 development board – 46 RON
  • YS-IRTM IR emitter/receiver module (38 kHz, NEC) – 22 RON
  • 4-channel 3.3 V ↔ 5 V level-shifter – 11 RON
  • Jumper wires and breadboard

Total cost: 79 RON

Connections and Wiring

  • LVCC → 3.3 V (ESP32)
  • HVCC → 5 V (ESP32)
  • GND → ESP32 GND
  • TXD (module) → level-shifter → ESP32 RX (GPIO 16)
  • RXD (module) ← level-shifter ← ESP32 TX (GPIO 17)

Software Design

Environment & Libraries

  • ESPHome (YAML-based) for firmware, OTA, API/MQTT.
  • `uart` component on GPIO 16/17 at 9600 baud.
  • `remote_receiver` to buffer 3-byte NEC frames from YS-IRTM.
  • `remote_transmitter` to send 5-byte NEC payloads back to the module.
  • Custom `text_sensor` lambda for parsing incoming bytes into HA events.

Receive Handling

1. YS-IRTM decodes NEC IR and emits 3 bytes over UART.  
2. ESPHome buffers up to 3 bytes, then publishes an MQTT/state update (`ir_hub/last_command`).  
3. Home Assistant sensor template splits bytes into user-code and command.

Transmit Handling

1. Home Assistant invokes `switch.ir_send_<device>_<cmd>`.  
2. ESPHome writes the 5-byte payload (Addr: 0xA1, F1: 0xF1, UC High, UC Low, Cmd) to UART.  
3. YS-IRTM sends the NEC frame on IR LED (9 ms mark, 4.5 ms space, data bits @ 562 µs ×38 kHz).  
4. Module replies with 0xF1 on success; ESPHome retries once after 1 s if no ack.

Limitations

  • Protocol Support: Only the NEC protocol is supported by YS-IRTM.
  • Incompatible Devices: The projector and air conditioner use non-NEC IR codes and cannot be learned or replayed with this setup.

Future Improvements (Brief)

  • Add a raw IR capture module (e.g. TSOP38×38 + pulse-timing) to support non-NEC protocols.
  • Store learned raw codes in flash for durability and offline replay.
  • Integrate an IR-over-IP gateway for cloud-based control and multi-hub scaling.

Results

All NEC remotes in the stereo system are successfully learned and replayed via Home Assistant, enabling automated scenes and mobile control. OTA updates allow incremental feature additions without physical access.

Conclusions

This ESP32 + YS-IRTM hub provides a low-cost, NEC-only IR bridge that integrates seamlessly with Home Assistant. With minor hardware changes, it can be extended to support arbitrary IR protocols.

Download

Bibliography/Resources

  • YS-IRTM Module Datasheet
  • ESPHome Documentation – UART, remote_receiver, remote_transmitter
  • Home Assistant ESPHome Integration Guide
iothings/proiecte/2025sric/esp32-ir-hub.1747782980.txt.gz · Last modified: 2025/05/21 02:16 by petru.zincenco
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0