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.

Attiny85 timer programming using Timer1

This Arduino sketch uses Timer1 to drive the LED blinker: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 /* * Program ATTiny85 to blink LED connected to PB1 at 1s interval. * Assumes ATTiny85 is running at 1MHz internal clock speed. */ #include <avr/io.h> #include <avr/wdt.h> #include <avr/sleep.h> #include <avr/interrupt.h> bool timer1 = false , led = true ; // Interrupt service routine for timer1 ISR(TIMER1_COMPA_vect) { timer1 = true ; } void setup() { // Setup output pins pinMode( 1 , OUTPUT); digitalWrite( 1 , led); set_sleep_mode(SLEEP_MODE_IDLE); // Setup timer1 to interrupt every second TCCR1 = 0 ; // Stop timer TCNT1 = 0 ; // Zero timer GTCCR = _BV(PSR1); // Reset prescaler OCR1A = 243 ; // T = prescaler / 1MHz = 0.004096s; OCR1A = (1s/T) - 1 = 243 OCR1C = 243 ; // Set to same value to reset timer1 to

3D Printer Filament Joiner

I have been looking at various ways of joining 3D printing filaments. One method involves running one end of a filament through a short PTFE tubing, melting it with a lighter or candle, retracting it back into the tubing and immediately plunging the filament to be fused into the tubing: One problem with this method is that you can't really control the temperature at which you melt the filament, so you frequently end up with a brittle joint that breaks upon the slightest bend. Aliexpress even sells a contraption that works along the same line. As it uses a lighter or candle as well, it suffers from the same weakness. I am not even sure why you need a special contraption when a short PTFE tubing will work just as well. Another method involves using shrink tubing/aluminium foil, and a heat gun: But a heat gun is rather expensive, so I wanted to explore other alternatives. The candle + PTFE tubing method actually works quite well when you happen to melt it at the rig