This shows you the differences between two versions of the page.
iothings:proiecte:2023:hometempcontrol [2024/01/08 04:00] mihai.preda1808 created |
iothings:proiecte:2023:hometempcontrol [2024/01/16 13:34] (current) mihai.preda1808 |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======Home Assistant Heating Control====== | + | ======Home Assistant AC Control====== |
* Author: Preda Mihai Alexandru | * Author: Preda Mihai Alexandru | ||
* Email: <mihai.preda1808@stud.energ.upb.ro> | * Email: <mihai.preda1808@stud.energ.upb.ro> | ||
* Master: SSA | * Master: SSA | ||
+ | * Presentation: {{:iothings:proiecte:2023:home_assistant_ac_control.pptx}} | ||
+ | |||
+ | =====Introduction===== | ||
+ | The primary objective of this project is to enable the integration of non-smart infrared (IR) devices into a home automation system. This integration focuses on enhancing control methods beyond the traditional remote control. A key motivation for this project is the need to automate air conditioning (AC) units. The goal is to establish automation, such as activating heating or cooling when approaching the home under specific temperature conditions. Additionally, the project aims to facilitate voice control of the AC units using Amazon Alexa. | ||
+ | |||
+ | =====Hardware===== | ||
+ | ===Hardware List=== | ||
+ | * ESP32-C3 (Seeed XIAO Studio): Chosen for its compact size, low power consumption, and adequate functionalities (PINs, VCC3, VCC5, USB-C). | ||
+ | * 2.4GHz Antenna | ||
+ | * IR Emitter LED | ||
+ | * IR Receiver (VS838) | ||
+ | * DHT11 Temperature and Humidity Sensor | ||
+ | * PN2222A Transistor | ||
+ | * 470Ω Resistor | ||
+ | * Raspberry Pi 4B (8GB RAM) | ||
+ | |||
+ | ===Circuit Design=== | ||
+ | The circuit and PCB were designed using KiCad. The ESP32-C3's small footprint and low power requirements make it ideal for creating compact sensors. A PN2222A transistor and a 470Ω resistor are used to adapt the 5V requirement of the IR emitter to the 3.3V ESP architecture. The DHT11 sensor is integrated to provide room temperature data, assisting the climate control plugin, mainly since some AC units do not relay their state via IR. | ||
+ | |||
+ | {{:iothings:proiecte:2023:circuit.png?400|}} | ||
+ | {{:iothings:proiecte:2023:pcb.png?400|}} | ||
+ | |||
+ | Due to resource limitations, I soldered the components to a breadboard for the final product despite having a designed PCB. | ||
+ | |||
+ | {{:iothings:proiecte:2023:circuit_soldering.jpeg?400|}} | ||
+ | |||
+ | The result wasn't perfect, but it got the job done. The DHT sensor was moved to the other side of the PCB due to the heat emitted by the ESP32-C3, which could interfere with its readings. | ||
+ | |||
+ | {{:iothings:proiecte:2023:fat_pcb.jpeg?400|}} | ||
+ | {{:iothings:proiecte:2023:pcb_front.jpeg?400|}} | ||
+ | |||
+ | In order to ensure a reliable wifi signal throughout the house, a 2.4GHz antenna was added using the antenna port on the ESP32-C3 board. | ||
+ | |||
+ | ===Enclosure Design=== | ||
+ | To ensure the device blends seamlessly into day-to-day environments without exposing wires or internal components, a custom enclosure was designed using Fusion 360. The design includes: | ||
+ | |||
+ | * Reusing IR-transparent plastic from an old remote to conceal the LEDs. | ||
+ | * An upper part designed to allow ventilation for the DHT11 sensor. | ||
+ | * Three iterations were undertaken to achieve a satisfactory fit and aesthetic. | ||
+ | |||
+ | {{:iothings:proiecte:2023:case.png?400|}} | ||
+ | {{:iothings:proiecte:2023:iteration.jpeg?400|}} | ||
+ | |||
+ | ===Final product=== | ||
+ | |||
+ | The result is a device powered by USB-C that can read temperature, humidity, receive and emit IR signals. | ||
+ | |||
+ | {{:iothings:proiecte:2023:final_product.jpeg?400|}} | ||
+ | |||
+ | |||
+ | =====Software===== | ||
+ | ===Infrastructure Schema=== | ||
+ | |||
+ | The infrastructure consists of Home Assistant, ESPHome, local devices, a third-party cloud service that securely exposes the Home Assistant server to authorized mobile devices, Amazon Alexa cloud for voice assistant capabilities, the local IR capable devices, and an IR controller that was built. | ||
+ | |||
+ | {{:iothings:proiecte:2023:schema.png?400|}} | ||
+ | ===Home Assistant=== | ||
+ | The Home Assistant is a great tool to automatize and manage your entire home. It has a large community, frequent updates, and has been thoroughly tested. For this project, we hosted the Home Assistant server on a Raspberry Pi 4B with 8GB of RAM. | ||
+ | |||
+ | {{:iothings:proiecte:2023:pi_cluster.jpeg?400|}} | ||
+ | |||
+ | My goal was to achieve the following automation using the IR Controller: | ||
+ | |||
+ | {{:iothings:proiecte:2023:automations.png?400|}} | ||
+ | |||
+ | ===ESPHome=== | ||
+ | ESPHome is a standalone project integrated with Home Assistant, offering a platform for all ESP compatible boards. From functionality wrappers to OTA updates, ESPHome covers everything. | ||
+ | |||
+ | {{:iothings:proiecte:2023:esp_home_setup.png?400|}} | ||
+ | {{:iothings:proiecte:2023:esphome_ota.png?400|}} | ||
+ | {{:iothings:proiecte:2023:ha_esp_ir_controller.png?400|}} | ||
+ | ===The IR Controller=== | ||
+ | |||
+ | To extract the AC's remote values, I initially utilized `remote_receiver` from ESPHome, which is essentially a wrapper around IRremoteESP8266. However, it turned out that the ESPHome project had not updated its packages to support ESP32-C3 for this specific component. Due to the ESP32-C3's small footprint, the RMT architecture was slightly altered, providing only two channels for receiving and two for transmitting (by default, ESP32 has four channels for each mode). ESPHome software did not provide a way to select the RMT channels manually, and most of the time, an unsupported channel was assigned, causing the implementation not to work as expected. | ||
+ | |||
+ | {{:iothings:proiecte:2023:esp32c3_rmt.png?400|}} | ||
+ | |||
+ | To resolve the RMT problem, I encountered a [[https://github.com/Jorre05|solution]] on a GitHub issue. It involved adding the capability to define RMT. However, since I also required 'remote_transmitter', I had to find a similar workaround, which I have now made publicly available on [[https://github.com/predam/remote_transmitter|GitHub]] as well. | ||
+ | |||
+ | |||
+ | After resolving the compatibility issues, the next step was to read the signals transmitted by the AC remote. To achieve this, I enabled the dumping of all logs from the receiver. Fortunately, the IR component from ESPHome had a lot of pre-decoded messages. As shown in the logs, I was able to use these existing records of IR signals. If I hadn't been lucky enough to have these pre-decoded messages, I would have had to decode all the remote buttons and sequences myself. | ||
+ | |||
+ | {{:iothings:proiecte:2023:esphome_esp32_ir_dump.png?400|}} | ||
+ | |||
+ | I found it great to be able to turn my AC unit on and off, but having full control over all its functionalities is even better. To achieve this, I set up ESPHome's `climate` component, which acts as a wrapper around `HeatpumpIR`. After flashing new firmware using OTA, I was able to fully control my AC using the Home Assistant interface! | ||
+ | |||
+ | |||
+ | {{:iothings:proiecte:2023:sensor_logs.png?400|}} | ||
+ | {{:iothings:proiecte:2023:eps_ha_ring.png?400|}} | ||
+ | |||
+ | **The IR Controller configuration** | ||
+ | |||
+ | <code> | ||
+ | |||
+ | esphome: | ||
+ | name: ir-controller | ||
+ | friendly_name: IR controller | ||
+ | libraries: | ||
+ | # fix for https://github.com/esphome/issues/issues/4208 | ||
+ | - IRremoteESP8266=https://github.com/predam/IRremoteESP8266.git#v2.8.6 | ||
+ | |||
+ | esp32: | ||
+ | board: seeed_xiao_esp32c3 | ||
+ | framework: | ||
+ | type: arduino | ||
+ | |||
+ | # Enable logging | ||
+ | logger: | ||
+ | |||
+ | # Enable Home Assistant API | ||
+ | api: | ||
+ | encryption: | ||
+ | key: "***" | ||
+ | |||
+ | ota: | ||
+ | password: "***" | ||
+ | |||
+ | wifi: | ||
+ | ssid: !secret wifi_ssid | ||
+ | password: !secret wifi_password | ||
+ | manual_ip: | ||
+ | # Set this to the IP of the ESP | ||
+ | static_ip: 192.168.1.x | ||
+ | # Set this to the IP address of the router. Often ends with .1 | ||
+ | gateway: 192.168.1.1 | ||
+ | # The subnet of the network. 255.255.255.0 works for most home networks. | ||
+ | subnet: 255.255.255.0 | ||
+ | # Enable fallback hotspot (captive portal) in case wifi connection fails | ||
+ | ap: | ||
+ | ssid: "Ir-Controller Fallback Hotspot" | ||
+ | password: "***" | ||
+ | |||
+ | external_components: | ||
+ | - source: github://Jorre05/remote_receiver | ||
+ | components: [ remote_receiver ] | ||
+ | - source: github://predam/remote_transmitter | ||
+ | components: [ remote_transmitter ] | ||
+ | |||
+ | captive_portal: | ||
+ | |||
+ | remote_receiver: | ||
+ | id: rcvr | ||
+ | pin: | ||
+ | number: 4 #D2 | ||
+ | inverted: true | ||
+ | mode: | ||
+ | input: true | ||
+ | pullup: true | ||
+ | rmt_channel: 2 | ||
+ | tolerance: 55% | ||
+ | dump: all | ||
+ | |||
+ | remote_transmitter: | ||
+ | id: trsm | ||
+ | pin: 3 #D1 | ||
+ | rmt_channel: 1 | ||
+ | # Infrared remotes use a 50% carrier signal | ||
+ | carrier_duty_percent: 50% | ||
+ | |||
+ | switch: | ||
+ | - platform: template | ||
+ | name: "AC On" | ||
+ | turn_on_action: | ||
+ | remote_transmitter.transmit_panasonic: | ||
+ | address: 0x4004 | ||
+ | command: 0x0720008C | ||
+ | - platform: template | ||
+ | name: "AC DRY" | ||
+ | turn_on_action: | ||
+ | remote_transmitter.transmit_panasonic: | ||
+ | address: 0x4004 | ||
+ | command: 0x07200004 | ||
+ | sensor: | ||
+ | - platform: dht | ||
+ | pin: 7 #D6 | ||
+ | temperature: | ||
+ | name: "Living Room Temperature" | ||
+ | humidity: | ||
+ | name: "Living Room Humidity" | ||
+ | update_interval: 60s | ||
+ | |||
+ | climate: | ||
+ | - platform: heatpumpir | ||
+ | protocol: panasonic_dke | ||
+ | horizontal_default: auto | ||
+ | vertical_default: auto | ||
+ | max_temperature: 30 | ||
+ | min_temperature: 16 | ||
+ | name: "Living Room AC" | ||
+ | receiver_id: rcvr | ||
+ | transmitter_id: trsm | ||
+ | </code> | ||
+ | |||
+ | ===Integrations=== | ||
+ | |||
+ | After integrating the AC control with Home Assistant, I was able to easily connect with Alexa voice assistant ( also thanks to the cloud access of my Home Assistant installation) and create all the suggested automation mentioned in the Home Assistant section. | ||
+ | |||
+ | =====Conclusion===== | ||
+ | |||
+ | In conclusion, the ESP32-C3 is a fantastic small-sized board that can be seamlessly integrated with a variety of sensors. This project demonstrated how easy it is to set up and perform OTA updates using this board, as well as how the board can attain IR capabilities. Additionally, the project highlighted the infinite possibilities for automating tasks using Home Assistant. | ||
+ | |||
+ | =====Resources===== | ||
+ | |||
+ | |||
+ | * **Home Assistant** | ||
+ | * [[https://github.com/home-assistant/core]] | ||
+ | |||
+ | * **Getting Started with Seeed Studio XIAO ESP32C3** | ||
+ | * [[https://wiki.seeedstudio.com/XIAO_ESP32C3_Getting_Started/]] | ||
+ | |||
+ | * **ESP Home Wiki** | ||
+ | * [[https://esphome.io/components]] | ||
+ | |||
+ | * **ESP Home Github Community** | ||
+ | * [[https://github.com/esphome/esphome]] | ||
+ | |||
+ | |||
+ | * **HeatpumpIR - An Arduino library to control split-unit heatpumps over Infrared** | ||
+ | * [[https://github.com/ToniA/arduino-heatpumpir]] | ||
+ | |||
+ | |||
+ | * **IRremoteESP8266 - Infrared remote library for ESP8266/ESP32** | ||
+ | * [[https://github.com/crankyoldgit/IRremoteESP8266]] | ||
+ |