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:16]
petru.zincenco
iothings:proiecte:2025sric:esp32-ir-hub [2025/05/21 03:03] (current)
petru.zincenco [Images]
Line 7: Line 7:
  
 ===== Introduction ===== ===== 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 Home Assistant entityWith this hub in place, you can automate your stereo system ​and air conditioner directly from Home Assistant ​or a mobile app.+This project extends an existing Home Assistant setup (on Raspberry Pi 4) to control IRonly 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 NECprotocol commands, ​and DHT11 sensor to read environment data every 30 minutesAll IR commands ​and sensor readings are exposed in Home Assistant ​as entities.
  
 ===== General Description ===== ===== 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)   
-    - Wi-Fi-connected,​ runs ESPHome add-on for firmware management and OTA.   +    - Runs ESPHome add-on for firmware management, API, MQTT and OTA.   
-    - Receives ​MQTT/API updates ​from ESP32 and presents IR codes as switches/buttons.   +    - Receives ​IR command events and sensor data from ESP32, exposes them as switches ​and sensors.   
-  * **ESP32 IR Hub**   +  * **ESP32 IR & Sensor ​Hub**   
-    - Connects over Wi-Fi to Home Assistant ​(static IP).   +    - Connects over Wi-Fi (static IP) to Home Assistant via ESPHome native API.   
-    - Interfaces via UART (9600 baud) with the YS-IRTM ​IR emitter/​receiver.   +    - Interfaces via UART (irSerial.begin at 9600, SERIAL_8N1) on GPIO 22 (RX) and GPIO 23 (TX) with YS-IRTM. ​  
-    - Implements ESPHome `remote_receiver` and `remote_transmitter` components.  ​+    - Reads DHT11 sensor on GPIO 21 every 30 minutes.  ​
   * **YS-IRTM IR Emitter/​Receiver Module**  ​   * **YS-IRTM IR Emitter/​Receiver Module**  ​
-    - 38 kHz carrier, hardwaredecode for NEC frames only.   +    - 38 kHz carrier, hardware-decode for NEC frames only.   
-    - Outputs 3byte payloads ​(User Code High, User Code Low, Command) ​on receive.   +    - Outputs 3-byte payloads on receive; accepts ​5-byte payloads to transmit.   
-    - Accepts ​5-byte payloads ​(Address, F1, UC High, UC Low, Cmd) to transmit ​NEC codes.+  * **DHT11 Temperature & Humidity Sensor** ​  
 +    - Reads temperature and humidity on GPIO 21; data logged every 30 minutes.
  
 ===== Hardware Design ===== ===== Hardware Design =====
 ==== Parts List ==== ==== Parts List ====
-  * ESP32 development board – 46 RON   +  * ESP32 development board – 46 RON 
-  * YS-IRTM IR emitter/​receiver module (38 kHz, NEC) – 22 RON   +{{ :​iothings:​proiecte:​2025sric:​esp32.png?​nolink&​150 |}}   
-  * 4-channel 3.3 V ↔ 5 V level-shifter – 11 RON  ​+  * YS-IRTM IR emitter/​receiver module (38 kHz, NEC) – 22 RON 
 +{{ :​iothings:​proiecte:​2025sric:​ys-irtm.png?​nolink&​150 |}} 
 +  * DHT11 sensor module – 15 RON 
 +{{ :​iothings:​proiecte:​2025sric:​dht11.png?​nolink&​150 |}}   
 +  * 4-channel 3.3 V ↔ 5 V level shifter – 11 RON 
 +{{ :​iothings:​proiecte:​2025sric:​lvconvertor.png?​nolink&​150 |}}  
   * Jumper wires and breadboard  ​   * Jumper wires and breadboard  ​
-**Total cost:​** ​79 RON  ​+**Total cost:​** ​≈ 94 RON  ​
  
 ==== Connections and Wiring ==== ==== Connections and Wiring ====
-  * **LVCC** → 3.3 V (ESP32) ​  +  * **YS-IRTM Module**   
-  * **HVCC** → 5 V (ESP32) ​  +    - LVCC → 3.3 V (ESP32) ​  
-  * **GND** → ESP32 GND   +    ​- ​HVCC → 5 V (ESP32) ​  
-  * **TXD** (module) → level-shifter ​→ ESP32 RX (GPIO 16)   +    ​- ​GND → ESP32 GND   
-  * **RXD** (module) ← level-shifter ← ESP32 TX (GPIO 17)  ​+    - 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 ​ 
  
 ===== Software Design ===== ===== Software Design =====
-==== Environment & Libraries ​==== +==== Environment & Components ​==== 
-  * **ESPHome** (YAML-based) for firmware, OTA, API/MQTT.   +  * **ESPHome** (YAML-based) for Wi-Fi, APIMQTT, OTA.   
-  * **`uart`** ​component ​on GPIO 16/17 at 9600 baud.   +  * **`uart`** on GPIO 22/23 at 9600 baud, SERIAL_8N1.   
-  * **`remote_receiver`** ​to buffer 3-byte NEC frames from YS-IRTM. ​  +  * **`remote_receiver`** ​+ **`remote_transmitter`** for YS-IRTM ​NEC frames.   
-  * **`remote_transmitter`** to send 5-byte NEC payloads back to the module.   +  * **`dht`** sensor component on GPIO 21, update_interval:​ 1800 s.   
-  * **Custom `text_sensor`** lambda ​for parsing incoming bytes into HA events. ​ +  * **Custom `text_sensor`** lambda ​to parse 3-byte NEC payloads ​into HA events.
  
 ==== Receive Handling ==== ==== Receive Handling ====
   1. YS-IRTM decodes NEC IR and emits 3 bytes over UART.  ​   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`). ​  +  2. ESPHome buffers 3 bytes, then publishes an MQTT/state update (`ir_hub/​last_command`). ​  
-  3. Home Assistant sensor template splits ​bytes into user-code and command.+  3. Home Assistant sensor template splits into user-code and command.
  
 ==== Transmit Handling ==== ==== Transmit Handling ====
-  1. Home Assistant ​invokes `switch.ir_send_<​device>​_<​cmd>​`. ​  +  1. HA invokes `switch.ir_send_<​device>​_<​cmd>​`. ​  
-  2. ESPHome writes ​the 5-byte payload (Addr: 0xA1, F1: 0xF1, UC High, UC Low, Cmd) to UART.   +  2. ESPHome writes 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).   +  3. YS-IRTM ​emits NEC frame (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.+  4. Module replies 0xF1 on success; ESPHome retries once after 1 s if no ack.
  
-===== Limitations ===== +==== Sensor Handling ​==== 
-  * **Protocol Support**: Only the NEC protocol ​is supported by YS-IRTM.   +  * DHT11 on GPIO 21 is read every 30 minutes.   
-  * **Incompatible Devices**: The projector ​and air conditioner use non-NEC IR codes and cannot be learned or replayed with this setup.+  * Temperature ​and humidity values are published to Home Assistant as `sensor.inside_temperature` ​and `sensor.inside_humidity`.  ​
  
-===== Future Improvements (Brief) ​===== +===== Known IR Codes ===== 
-  * Add a raw IR capture ​module ​(e.gTSOP38×38 + pulse-timing) to support non-NEC protocols.  ​ +^ Function ​      ^ NEC Code    ^ 
-  * Store learned raw codes in flash for durability ​and offline replay  +| Power On/​Off ​   | 01 FE 04     | 
-  * Integrate an IR-over-IP gateway for cloud-based control and multi-hub scaling.+| Mute            | 01 FE 09     | 
 +| Volume Down     | 01 FE 05     | 
 +| Volume Up       | 01 FE 06     | 
 + 
 +===== Images ===== 
 +===== Images ===== 
 +Hardware setup: ESP32, YS-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 =====
-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.+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.
  
-===== Conclusions ​===== +===== Future Improvements (Brief) ​===== 
-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.+  * 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</​a></​html>​ <​html><​a class="​media mediafile mf_pdf"​ href="?​do=export_pdf">​Download PDF</​a></​html>​
- 
-===== 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