Skip to main content

Automating split aircon units with Tasmota + Home Assistant


The task is to automate the control of 6 split aircon units in my house. For historical reasons, they are a wild mix of different makes and ages - Panasonic, Fujitsu, Kelvinator, Stirling and MHI. The goal is to control these units via a home automation system that is hosted locally (instead of cloud-based).

Hardware Components

I use the ESP8266-based WeMos D1 Mini, which is hooked up with a IR transmitter and receiver to emulate the aircon remote control. 

For the firmware, I settled on Tasmota, since it was able to support all the makes of aircon units in my house (via IRRemote8266). I also played around with ESPHome, but its IR Remote Climate component has more limited aircon support (eg. no Panasonic support). 

Building the hardware is pretty straightforward. I bought the stock IR transmitter and receiver boards from AliExpress, thinking it would make my job easier (wrong). 
I also bought a bunch of TSOP34838 IR receivers for comparison.
Turns out you don't really need all the extra resistors (and LED) on the IR receiver board. You can pretty much just plug in the VCC, GND and OUT pins of the bare IR receiver to the D1 Mini, and it will work.  

I am not sure what is the model of the IR receiver on the AliExpress boards. I suspect they are TSOP4838. From the spec sheet, TSOP34838 should have superior performance compared to the TSOP4838 for long IR codes. But for my use case, they gave quite similar performance, except for the Panasonic remote, where the TSOP34838 was used because the AliExpress receiver didn't work very well.

The bigger surprise came from the IR transmitter board. It worked, but needed to be very near to the aircon unit. Upon closer inspection, it turns out the IR led was powered directly by the MCU pin, instead of using a MOSFET which was my assumption! The other SMD components on the board are just a bunch of passive resistors. This severely limited the power driving the IR led, which restricted its range. 

I ended up desoldering the IR LED from the board and hooking up my own resistor (40ohm) and MOSFET (2N7000). When connected to a 5V source, the 40ohm resistor pretty much maxes out the current going through the IR LED, and I was able to increase the range to 2~3m.
Lesson learned: I should have gone for the baked IR LEDs and receivers directly instead of buying the boards. 

This is what my final board looks like. 


Hardware Unit Test

The transmitter is hooked up to D1, and the receiver is hooked up to D1 on the MCU.


The IR receiver was verified to be working by pointing the aircon remote at the board and observing the output at the Tasmota console.

06:07:17.472 MQT: tele/office_ac/RESULT = {"IrReceived":{"Protocol":"LG","Bits":28,"Data":"0x8808440","DataLSB":"0x10012102","Repeat":0,"IRHVAC":{"Vendor":"LG","Model":1,"Mode":"Cool","Power":"On","Celsius":"On","Temp":19,"FanSpeed":"Max","SwingV":"Off","SwingH":"Off","Quiet":"Off","Turbo":"Off","Econo":"Off","Light":"On","Filter":"Off","Clean":"Off","Beep":"Off","Sleep":-1}}}
06:07:17.963 MQT: tele/office_ac/RESULT = {"IrReceived":{"Protocol":"LG","Bits":28,"Data":"0x8808541","DataLSB":"0x1001A182","Repeat":0,"IRHVAC":{"Vendor":"LG","Model":1,"Mode":"Cool","Power":"On","Celsius":"On","Temp":20,"FanSpeed":"Max","SwingV":"Off","SwingH":"Off","Quiet":"Off","Turbo":"Off","Econo":"Off","Light":"On","Filter":"Off","Clean":"Off","Beep":"Off","Sleep":-1}}}
06:07:18.965 MQT: tele/office_ac/RESULT = {"IrReceived":{"Protocol":"LG","Bits":28,"Data":"0x8808642","DataLSB":"0x10016142","Repeat":0,"IRHVAC":{"Vendor":"LG","Model":1,"Mode":"Cool","Power":"On","Celsius":"On","Temp":21,"FanSpeed":"Max","SwingV":"Off","SwingH":"Off","Quiet":"Off","Turbo":"Off","Econo":"Off","Light":"On","Filter":"Off","Clean":"Off","Beep":"Off","Sleep":-1}}}
06:07:19.915 MQT: tele/office_ac/RESULT = {"IrReceived":{"Protocol":"LG","Bits":28,"Data":"0x8808844","DataLSB":"0x10011122","Repeat":0,"IRHVAC":{"Vendor":"LG","Model":1,"Mode":"Cool","Power":"On","Celsius":"On","Temp":23,"FanSpeed":"Max","SwingV":"Off","SwingH":"Off","Quiet":"Off","Turbo":"Off","Econo":"Off","Light":"On","Filter":"Off","Clean":"Off","Beep":"Off","Sleep":-1}}}

I find that for the different makes of aircon, I needed to tune certain parameters to make the IR decoding work better. In particular, I needed to tweak the IR_RCV_MIN_UNKNOWN_SIZE and IR_RCV_TOLERANCE parameters for the different makes. Some required higher or lower IR_RCV_MIN_UNKNOWN_SIZE values, and vice versa for IR_RCV_TOLERANCE

Note: I am compiling and uploading Tasmota from source using PlatformIO, and placing the customized values in tasmota/user_config_override.h.

Home Automation System

For the home automation system, I settled on Home Assistant. I also evaluated OpenHAB, but the learning curve appears much steeper compared to Home Assistant. What seals the deal for me is also the availability of Tasmota-IRHVAC, a third-party component for Home Assistant that makes integrating my home-made Tasmota aircon controllers a breeze compared to OpenHAB.

I am running Home Assistant in a VirtualBox VM on my Windows server. Getting it up-and-running is as simple as downloading the VDI file and starting it up in VirtualBox using the recommended config (2GB RAM, 2 vCPU). Networking is set to "bridged", and using the "Paravirtualized network adapter". 

Once it is running, access the home page (http://homeassistant.local:8123) and create an admin user to login. 

Then we install 2 addons under Configuration / Add-ons, Backups & Supervisor:
For Mosquitto Broker, the only thing I changed in the config file was adding a login/password:

certfile: fullchain.pem
customize:
  active: false
  folder: mosquitto
keyfile: privkey.pem
logins:
  - username: myuser
    password: mypass
require_certificate: false

There are probably more sophisticated ways to improve the security, but that's what I have settled on for now.

SSH & Web Terminal lets you log into Home Assistant via secure shell, and use the normal shell commands to make changes to the system.

Integrating Tasmota-IRHVAC

I created a folder in config called aircons:

cd config
mkdir aircons

In this folder, I can put all my aircon config files. A sample config file is available in Tasmota-IRHVAC-master/examples/configuration.yaml, with lots of config paramaters that you probably won't need. 

For example, my Panasonic config file (living_ac.yaml) ended up looking like:

  - platform: tasmota_irhvac
    name: "Living AC"
    command_topic: "cmnd/living_ac/irhvac"
    state_topic: "tele/living_ac/RESULT"
    vendor: "PANASONIC_AC"
    target_temp: 25
    initial_operation_mode: "off"
    away_temp: 25
    supported_modes:
      - "heat"
      - "cool"
      - "auto"
      - "off"
    supported_fan_speeds:
      - "auto"
      - "low"
      - "medium"
      - "high"
      - "max"
    supported_swing_list:
      - "off"
    hvac_model: "3"

As explained in the documentation, the supported_modes, supported_fan_speeds and supported_swing_list values are derived by using the target remote on the Tasmota device and observing the console output. You also get the vendor and hvac_model values this way.

In the config folder, there is a configuration.yaml file. I need to add this line at the end to include all the files in the aircons folder.

climate: !include_dir_merge_list aircon/

After all this work is done, Home Assistant needs to be restarted for the changes to take effect. Validate the new config files by selecting Configuration / Settings / Configuration validation / Check configuration. Since yaml files are indentation sensitive, a common error you will encounter is incorrect indentation. Once the configuration is verified to be correct, Home Assistant can be restarted.

One final step is to configure the MQTT section of the Tasmota device to point to MQTT broker on Home Assistant, and to match the instance value in the aircon yaml ("living_ac" in the example above).

A little detour about mDNS

The documentation of Home Assistant is all about accessing the server through the mDNS name http://homeassistant.local.

Unfortunately, I find that mDNS is a little unreliable. Sometimes it takes quite a long while before the homeassistant.local domain becomes available, if at all. I didn't have the time to properly troubleshoot this, and it seems it is such a common problem the Tasmota developers have decided to disable mDNS support by default

As such, I decided to assign a static IP to the Home Assistant VM. This can be done by following the instructions here.

So when configuring MQTT on Tasmota devices, I use the static IP for the MQTT broker address (192.168.1.3 in my case).


User and Password are set to the "myuser" and "mypass" values set previously when configuring the MQTT broker. Topic is set to the name used in the command topic in the aircon yaml file (living_ac if you are following the example living_ac.yaml file, but the screenshot above shows office_ac for another aircon yaml file).

Adding the AC Card to the Home Asisstant Dashboard

If all goes well, you are finally ready to view and control the new AC in the Home Assistant dashboard.

Select the hamburger menu on the dashboard and click Edit dashboard


Then select Add card / By Entity, and you should see the Living AC / climate.living_ac card ready to be added.


This should now show up in the dashboard with all the modes that you have defined for that aircon in its YAML file:


Not only can you now control each aircon remotely, if someone uses the physical remote to change the aircon settings, it will also be reflected in the dahsboard due to the IR receiver we have in our Tasmota hardware.

This is how the boards are mounted, sitting in a 3D-printed enclosure, and placed somewhere under the aircon indoor unit.



With the aircons added to Home Assistant, it also becomes possible to create scripts using Configuration / Automations and Scenes to, for example, turn them all on at the same time when the temperature goes above or below a certain value, or turn them all off at a certain time etc.

Comments

Popular posts from this blog

Update: Line adapter for Ozito Blade Trimmer

Update (Dec 2021): If you access to a 3D printer, I would now recommend this solution , which makes it super easy to replace the trimmer line. I have been using it for a few months now with zero issue.

Filament Joiner Part 2 (With Display and Knob)

Thanks to the current corona-virus crisis, the parts I ordered for the filament joiner project were taking forever to arrive. But now that they have finally arrived, I can put them to good use. These were the parts ordered: 0.96" OLED display SSD1306 Rotary switch encoder KY-040 Here is the final circuit diagram: The OLED display is connected to the SCK and SDA pins of the Nano (A2 and A3 respectively), and powered by 5V and GND. The rotary switch encoder is connected as follows: VCC => 5V GND = > GND CLK => D9 DT => D8 SW => D2 My prototype board now looks like this: The updated code for driving the knob and display is available in  heater-with-display.ino in the Github repository . We now have a fairly compact (about 7cm x 5cm) and independent filament joiner (no need to connect to PC) that is driven solely by a 12V power supply. Here's how to use it to join printer filaments. More usage details in my previous post .

Adding "Stereo Mixer" to Windows 7 with Conexant sound card

This procedure worked for my laptop (Thinkpad E530) with a Conexant 20671 sound card, but I suspect it will work for other sound cards in the Conexant family. I was playing with CamStudio to do a video capture of a Flash-based cartoon so that I can put it on the WDTV media player and play it on the big screen in the living room for my kids. The video capture worked brilliantly, but to do a sound capture, I needed to do some hacking. Apparently, there was this recording device called "Stereo Mixer" that was pretty standard in the Windows XP days. This allowed you to capture whatever was played to the speaker in all its digital glory. Then under pressure from various organizations on the dark side of the force, Microsoft and soundcard makers starting disabling this wonderful feature from Windows Vista onwards. So after much Googling around, I found out that for most sound cards, the hardware feature is still there, just not enabled on the software side. Unfortunately, to