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).
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.
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:
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.
I created a folder in config called 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:
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.
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.