This shows you the differences between two versions of the page.
iothings:proiecte:2025sric:esp32-ir-hub [2025/04/24 02:46] petru.zincenco |
iothings:proiecte:2025sric:esp32-ir-hub [2025/05/21 03:03] (current) petru.zincenco [Images] |
||
---|---|---|---|
Line 4: | Line 4: | ||
* **Author**: Petru Zincenco | * **Author**: Petru Zincenco | ||
* **Master**: IA | * **Master**: IA | ||
+ | * **Date Completed**: 21 May 2025 | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | I am creating this project because I already have a Home Assistant server running on a Raspberry Pi 3, and I want to extend its capabilities to control my stereo system and air conditioner via IR. By turning an ESP32 into an IR transceiver, I can sniff existing NEC-protocol remote commands, replay them, and even send arbitrary data over IR directly from my phone through Home Assistant. | + | 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 ===== | ===== 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) |
- | - Connected to local Wi-Fi. | + | - Runs ESPHome add-on for firmware management, API, MQTT and OTA. |
- | - Hosts ESPHome for firmware management. | + | - Receives IR command events and sensor data from ESP32, exposes them as switches and sensors. |
- | - Manages the 3 lights directly. | + | * **ESP32 IR & Sensor Hub** |
- | * **ESP32 IR Hub** | + | - Connects over Wi-Fi (static IP) to Home Assistant via ESPHome native API. |
- | - Connects back to Home Assistant over Wi-Fi (API/MQTT). | + | - Interfaces via UART (irSerial.begin at 9600, SERIAL_8N1) on GPIO 22 (RX) and GPIO 23 (TX) with YS-IRTM. |
- | - Controls the YS-IRTM module via UART. | + | - Reads DHT11 sensor on GPIO 21 every 30 minutes. |
* **YS-IRTM IR Emitter/Receiver Module** | * **YS-IRTM IR Emitter/Receiver Module** | ||
- | - 38 kHz carrier, NEC-protocol. | + | - 38 kHz carrier, hardware-decode for NEC frames only. |
- | - Controls the Air Conditioner and Audio System via infrared signals | + | - 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 ===== | ===== Hardware Design ===== | ||
==== Parts List ==== | ==== Parts List ==== | ||
- | + | * ESP32 development board – 46 RON | |
- | * 4-channel 3.3 V ↔ 5 V level-shifter – 11 RON | + | {{ :iothings:proiecte:2025sric:esp32.png?nolink&150 |}} |
- | * YS-IRTM IR emitter/receiver module (38 kHz) – 22 RON | + | * YS-IRTM IR emitter/receiver module (38 kHz, NEC) – 22 RON |
- | * ESP32 development board – 46 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:** ≈ 94 RON | ||
- | **Total cost:** 79 RON | + | ==== Connections and Wiring ==== |
- | + | * **YS-IRTM Module** | |
- | ==== Schematics and Signal Diagrams ==== | + | - LVCC → 3.3 V (ESP32) |
- | + | - HVCC → 5 V (ESP32) | |
- | {{ :iothings:proiecte:2025sric:diagramaelectrica.png?nolink&600 |}} | + | - GND → ESP32 GND |
- | + | - TXD → level shifter → ESP32 GPIO 22 (RX) | |
- | ==== Connections and Wiring Diagram ==== | + | - RXD ← level shifter ← ESP32 GPIO 23 (TX) |
- | + | * **DHT11 Sensor** | |
- | * **LVCC** → 3.3 V | + | - VCC → 5 V (ESP32) |
- | * **HVCC** → 5 V | + | - GND → ESP32 GND |
- | * **GND** → ESP32 GND | + | - DATA → ESP32 GPIO 21 |
- | * **TXD** (module) → level shifter → ESP32 RX | + | * **IR LED & Driver** |
- | * **RXD** (module) ← level shifter ← ESP32 TX | + | - IR LED anode → 5 V via resistor → transistor → ESP32 GPIO (configured by module) |
+ | - Common GND for all devices | ||
===== Software Design ===== | ===== 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. | ||
- | ==== Development Environment and Libraries ==== | + | ==== 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. | ||
- | * **ESPHome** (YAML-based configuration, OTA updates, Home Assistant integration) | + | ==== Transmit Handling ==== |
- | * **`uart`** component on TX/RX pins at 9600 baud to interface with the YS-IRTM’s TTL serial | + | 1. HA invokes `switch.ir_send_<device>_<cmd>`. |
- | * **`text_sensor`** (custom lambda) for buffering and parsing incoming 3-byte payloads into HA events | + | 2. ESPHome writes 5-byte payload (Addr: 0xA1, F1: 0xF1, UC High, UC Low, Cmd) to UART. |
- | * **`remote_transmitter`** declared (IR modulation offloaded to module’s 38 kHz carrier engine) | + | 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. | ||
- | ==== Implemented Algorithms and Structures ==== | + | ==== Sensor Handling ==== |
+ | * DHT11 on GPIO 21 is read every 30 minutes. | ||
+ | * Temperature and humidity values are published to Home Assistant as `sensor.inside_temperature` and `sensor.inside_humidity`. | ||
- | ==== Receive Handling ==== | + | ===== 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 | | ||
- | * YS-IRTM demodulates 38 kHz IR, decodes NEC frames internally, then emits three data bytes (User Code High, User Code Low, Command) over UART upon each valid command | + | ===== Images ===== |
- | * ESPHome listens on UART, accumulates up to three bytes in a small buffer, then fires an MQTT/state update and resets the buffer | + | ===== Images ===== |
- | * NEC repeat frames are suppressed by the module; ESPHome can apply further debouncing or grouping if needed | + | Hardware setup: ESP32, YS-IRTM module and DHT11 sensor wired on the breadboard and powered on. |
- | + | {{ :iothings:proiecte:2025sric:fizic.jpeg?nolink&700 |}} | |
- | ==== Transmit Handling ==== | + | 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 |}} | |
- | * To transmit, ESP32 sends a five-byte payload via `uart.write`: | + | Inside Temperature Graph: Logged DHT11 readings showing temperature variations over time. |
- | - Address byte (default `0xA1`) | + | {{ :iothings:proiecte:2025sric:temperatura.png?nolink&700 |}} |
- | - Command byte `F1` (`0xF1`, trigger TX) | + | Inside Humidity Graph: Logged DHT11 readings showing humidity fluctuations over time. |
- | - Data byte 1 (NEC User Code High) | + | {{ :iothings:proiecte:2025sric:umiditate.png?nolink&700 |}} |
- | - Data byte 2 (NEC User Code Low) | + | |
- | - Data byte 3 (NEC Command) | + | |
- | * The module appends the inverse of the command byte automatically and generates a full NEC frame with a 9 ms leading mark, 4.5 ms space, 562 µs mark/space per bit, and final mark at 38 kHz | + | |
- | * On success, YS-IRTM replies over UART with the command byte (`0xF1`); silence indicates a bad payload | + | |
- | * ESPHome waits (e.g. 1000 ms) for the ack and can retry transmission if no response arrives | + | |
===== Results ===== | ===== 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. | ||
- | ===== Conclusions ===== | + | ===== Future Improvements (Brief) ===== |
+ | * 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> | ||
- | |||
- | ===== Journal ===== | ||
- | |||
- | ===== Bibliography/Resources ===== | ||