Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iothings:proiecte:2025sric:esp32-ir-hub [2025/05/21 02:12]
petru.zincenco
iothings:proiecte:2025sric:esp32-ir-hub [2025/05/21 03:03] (current)
petru.zincenco [Images]
Line 1: Line 1:
-===== ESP32 Infrared Remote ​Hub (Finished) ​=====+===== ESP32 Infrared Remote =====
  
 ===== Metadata ===== ===== Metadata =====
Line 6: Line 6:
   * **Date Completed**:​ 21 May 2025  ​   * **Date Completed**:​ 21 May 2025  ​
  
-===== Overview ​===== +===== Introduction ​===== 
-This project ​delivers a universal infrared ​(IR) transceiver based on an ESP32, ​seamlessly integrated with Home Assistant via ESPHomeThe hub can learn and replay ​any remote protocol—whether ​NEC, extendedNEC, 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.+This project ​extends an existing Home Assistant setup (on Raspberry Pi 4) to control ​IR‐only devices via an ESP32 acting as an IR transceiverand to monitor indoor temperature and humidityWe 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.
  
-===== System Architecture ​=====+===== General Description ​=====
 ==== Block Diagram ==== ==== Block Diagram ====
-{{:​iothings:​proiecte:​2025sric:​logicaldiagram.png?​nolink&​600 |}}+{{ :​iothings:​proiecte:​2025sric:​diagrama_2_.png?​nolink&​700 |}}
  
 ==== Modules and Interactions ==== ==== Modules and Interactions ====
-  * **Home Assistant Server** (Raspberry Pi 3)   +  * **Home Assistant Server** (Raspberry Pi 4)   
-    - Hosts ESPHome ​in Docker ​for firmware ​builds, API management, and OTA updates.   +    - Runs ESPHome ​add-on ​for firmware ​management, API, MQTT and OTA.   
-    - Manages ​ESP32 IR Hub over Wi-Fi (static IP) using the native ESPHome integration. ​  +    - Receives IR command events and sensor data from ESP32, exposes them as switches ​and sensors  
-    - Presents learned IR commands ​as Home Assistant entities (switches/buttons)+  * **ESP32 IR & Sensor ​Hub**   
-  * **ESP32 IR Hub**   +    - Connects over Wi-Fi (static IP) to Home Assistant via ESPHome ​native API.   
-    - Runs custom ​ESPHome ​firmware configured in YAML.   +    - Interfaces ​via UART (irSerial.begin at 9600, SERIAL_8N1on GPIO 22 (RXand GPIO 23 (TX) with YS-IRTM.   
-    - Interfaces ​with a “dumb” IR demodulator ​(e.g. TSOP38238for raw pulse capture. ​  +    - Reads DHT11 sensor on GPIO 21 every 30 minutes  
-    - Drives an IR LED (via transistorfor signal replay, at 38 kHz carrier.   +  * **YS-IRTM ​IR Emitter/Receiver ​Module**   
-    - Communicates with Home Assistant via the ESPHome native API for real-time control and OTA+    - 38 kHz carrier, hardware-decode ​for NEC frames only.   
-  * **IR Receiver/Emitter Hardware**   +    - Outputs 3-byte payloads on receive; accepts 5-byte payloads to transmit. ​  
-    - **TSOP38238/​4838** demodulator ​for full pulse timing and protocol learning.   +  ​* **DHT11 Temperature & Humidity Sensor**  ​ 
-    - **IR LED** with driver transistor for reliable transmission of any learned code.  +    - Reads temperature and humidity on GPIO 21; data logged every 30 minutes.
  
-===== Hardware ​Implementation ​=====+===== Hardware ​Design ​=====
 ==== Parts List ==== ==== Parts List ====
-  * ESP32 development board   +  * ESP32 development board – 46 RON 
-  * TSOP38×38 ​IR demodulator  ​ +{{ :​iothings:​proiecte:​2025sric:​esp32.png?​nolink&​150 |}}   
-  * IR LED + transistor + resistor for emitter driver ​  +  * YS-IRTM ​IR emitter/​receiver module (38 kHz, NEC) – 22 RON 
-  * 4-channel 3.3 V ↔ 5 V level shifter ​(for optional serial devices) ​  +{{ :​iothings:​proiecte:​2025sric:​ys-irtm.png?​nolink&​150 |}} 
-  * Jumper wires and breadboard ​or PCB   +  * DHT11 sensor module – 15 RON 
- +{{ :​iothings:​proiecte:​2025sric:​dht11.png?​nolink&​150 |}}   
-**Total cost:** ≈ 85 RON  ​+  * 4-channel 3.3 V ↔ 5 V level shifter ​– 11 RON 
 +{{ :​iothings:​proiecte:​2025sric:​lvconvertor.png?​nolink&​150 |}}   
 +  * Jumper wires and breadboard ​  
 +**Total cost:** ≈ 94 RON  ​
  
 ==== Connections and Wiring ==== ==== Connections and Wiring ====
-  * **IR Receiver** (TSOP) → ESP32 GPIO (e.g. 23)   +  * **YS-IRTM Module**   
-  * **IR LED Anode** → 5 V through current-limiting resistor → transistor → ESP32 GPIO (e.g. 22for carrier enable ​  +    - LVCC → 3.3 V (ESP32  
-  ​* **Transistor Base** ​→ ESP32 GPIO through base resistor ​  +    - HVCC → 5 V (ESP32) ​  
-  * **GND/common** for ESP32, TSOP, and emitter driver ​  +    - GND → ESP32 GND   
-  ​* ​(Optional**UART RX/TX** via level shifter if using serial modules ​ +    - TXD → level shifter ​→ ESP32 GPIO 22 (RX)   
 +    - RXD ← level shifter ← ESP32 GPIO 23 (TX)   
 +  * **DHT11 Sensor**   
 +    - VCC → 5 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 ​ 
  
-==== Design ​Rationale ​==== +===== Software ​Design ​===== 
-  * Switched from YS-IRTM module to TSOP demodulator to capture raw pulses and support proprietary protocols ​(e.g. Yamato AC).   +==== Environment & Components ​==== 
-  * On-board IR LED driver ensures full carrier strength and reliable distance.   +  * **ESPHome** ​(YAML-basedfor Wi-Fi, API, MQTT, OTA.   
-  * Level shifter retained ​for future expansions requiring TTL serial devices.+  * **`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.
  
-===== Firmware and Software ===== +==== Receive Handling ​==== 
-==== Development Environment ​==== +  ​1. YS-IRTM decodes NEC IR and emits 3 bytes over UART.   
-  ​* **ESPHome in Docker**: Containerized with host-network mode, USB mapping (`/​dev/​ttyUSB0`), ​and OTA port (3232) exposed.   +  ​2ESPHome buffers 3 bytesthen publishes an MQTT/state update ​(`ir_hub/​last_command`).   
-  ​* **YAML-First Configuration**:​ Single `ir_hub.yaml` defines Wi-Fistatic IP (`192.168.0.136`), API, OTA, logger, UART (if needed), and switch entities.   +  ​3. Home Assistant sensor template splits into user-code ​and command.
-  ​* **Static IP Assignment**:​ Ensures reliable discovery ​and OTA, bypassing mDNS issues in Docker.+
  
-==== IR Signal ​Handling ==== +==== Transmit ​Handling ==== 
-  ​* **Learning (Capture)** ​  +  ​1HA invokes ​`switch.ir_send_<​device>​_<​cmd>​`.   
-    - The TSOP38×38 demodulator outputs clean digital bursts  +  2. ESPHome writes 5-byte payload (Addr: 0xA1, F1: 0xF1, UC High, UC LowCmd) to UART  
-    - ESPHome’s ​`remote_receivercomponent timestamps each pulse/space.   +  ​3. YS-IRTM emits NEC frame (9 ms mark, 4.5 ms space, data bits 562 µs @38 kHz).   
-    A custom lambda buffers pulses into arraysthen exposes them via an MQTT/state event or as a Home Assistant sensor for inspection+  4. Module replies 0xF1 on success; ESPHome ​retries ​once after 1 s if no ack.
-  ​* **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 ​==== +==== Sensor Handling ​==== 
-  * **Entity Exposure**: Each learned code appears ​as `switch.<​device>​_<​command>​in Home Assistant.   +  * DHT11 on GPIO 21 is read every 30 minutes. ​  
-  * **OTA Updates**After initial USB flashfirmware updates are pushed over-the-air from the ESPHome container  +  ​Temperature and humidity values are published to Home Assistant ​as `sensor.inside_temperature` and `sensor.inside_humidity`.   
-  * **Dashboard Controls**Custom Lovelace cards allow “Learn”,​ “Replay”, ​and “Delete” actions per IR code + 
 +===== Known IR Codes ===== 
 +^ Function ​      ^ NEC Code    ^ 
 +| Power On/​Off ​   | 01 FE 04     | 
 +| Mute            | 01 FE 09     | 
 +| Volume Down     | 01 FE 05     | 
 +| Volume Up       | 01 FE 06     | 
 + 
 +===== Images ===== 
 +===== Images ===== 
 +Hardware setupESP32YS-IRTM module and DHT11 sensor wired on the breadboard and powered on
 +{{ :iothings:​proiecte:​2025sric:​fizic.jpeg?​nolink&​700 |}} 
 +ESP32 in Home Assistant UI: The ESP32 entity ​and exposed ​IR switches and sensor values displayed on the HA dashboard. 
 +{{ :​iothings:​proiecte:​2025sric:​esp_ha.png?​nolink&​700 |}} 
 +Inside Temperature Graph: Logged DHT11 readings showing temperature variations over time. 
 +{{ :​iothings:​proiecte:​2025sric:​temperatura.png?​nolink&​700 |}} 
 +Inside Humidity Graph: Logged DHT11 readings showing humidity fluctuations over time. 
 +{{ :​iothings:​proiecte:​2025sric:​umiditate.png?​nolink&​700 |}} 
  
 ===== Results ===== ===== Results =====
-  * **Universal IR Hub**: Successfully captures and replays ​NEC, extended protocols, ​and custom raw timings  +All NEC remotes in the stereo system are learned ​and replayed via Home AssistantIndoor temperature and humidity ​are logged every 30 minutes ​and available ​in HA dashboards. OTA updates allow wireless firmware management.
-  * **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 ​===== +===== Future Improvements (Brief) ​===== 
-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.+  * Add direct IR raw capture ​and transmit to support non-NEC devices.
  
 ===== Download ===== ===== Download =====
-<​html><​a class="​media mediafile mf_pdf"​ href="?​do=export_pdf">​Download PDF Documentation</​a></​html>​ +<​html><​a class="​media mediafile mf_pdf"​ href="?​do=export_pdf">​Download PDF</​a></​html>​
- +
-===== Bibliography/​Resources ===== +
-  * ESPHome Documentation – Getting Started, UART, Remote Receiver/​Transmitter ​  +
-  * Home Assistant – ESPHome Integration Guide   +
-  * TSOP38×38 Datasheet – Vishay ​  +
  
iothings/proiecte/2025sric/esp32-ir-hub.1747782725.txt.gz · Last modified: 2025/05/21 02:12 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