IR-controlled A/C, an Odyssey (1/many)

5 minute read

It all started when we moved to a new apartment in New York. A/C and heat are provided through 3 “slim units” (Daikin brand), each of them controlled by a separate infrared remote.

Two of the three remotes seems to be “programmable” (as in timer, probably a way to do things based on time and day of the week, something like that), but where’s the fun in that? No way to turn the heat back up when coming back from a trip? I just knew there was some geeking fun to be had there.

I’m trying me best to remember all the steps, but I started over 6 months ago and took very few notes, so I will most probably be adding details as they come back to me.

What I wanted to do

Well, it wasn’t super clear, but generally, I wanted to be able to control all 3 units from a single place, and ideally set up some kind of calendar as well.

That “single place” should be available on a smartphone, for the case when we’re coming back from vacation or something similar, it would be nice to find a warm (or cool) home.

So there I was, with some more or less clear requirements.

How

Well, these 3 units are controlled by IR remotes, so that shouldn’t be too hard, right? Famous last words…. The general idea was to have one device (not sure yet what) under each unit, and they would send out the information. There are other approaches, a little more integrated, but I also wanted to have a little bit of geek fun.

At the time where I started, I had a USB IR Toy, from a previous project I never really started, and that was going to be good enough to prototype everything, and then I would find a way to make 3 good-looking enough boxes with some kind of IR transmitter in it. Easy peasy.

With regards to programming language, I assumed I would go with what I found. I assumed most of the resources out there would be in Python, and so be it. I can read and write simple Python, that will be just fine.

Episode 1, the prototype

Obviously I wasn’t the first one to want to do this with a Daikin AC units, and I found some pretty good resources out there. People had done the hard part of the job for me: get the sequences.

Kind people have done most of the work for me

  • https://github.com/dannyshaw/daikin-pi was really where I started. They use the GPIO while I was going to use a USB transmitter at first, but both are going through LIRC, so that should be fine, and I would probably move to GPIO later, ot have something small and pretty.
    • It has a ton of links in the README file, some of which really explain how one reverse engineers the signal
    • For example see https://savjee.be/2020/09/2020-09-tuya-ir-hub-daikin-ac-home-assistant-esphome/ (this is long and hard)
    • And https://github.com/blafois/Daikin-IR-Reverse has a long and detailed explanation of the frames to be sent.

It’s not perfect though

On the principle

I had mostly one principle issue with it: the daikin-pi project works by replacing the lircd.conf file at every call, and then calling service lircd restart, and then finally with an exec() call to lircd.

I know it’s not that bad, but it itched, really. There were 2 things I really wanted to change with this design

  • Not replace the lircd.conf file each time, and restart lircd. I could change that right away
  • Not call lirc through and exec call. Whatever my server would be, I would use lircd’s socket.

Generating a very long configuration file

I use Celsius, sorry about that, it’s a really hard habit to change.

What helped me here is having pretty low expectation. I figured I only needed

  • 2 modes: heat and cool
  • temperatures between 18°C (~64.5F) and 25°C (~77F), the rationale being I wouldn’t cool under 18°C ever or heat above 25°C (yes I missed some use cases here)
  • horizontal swing: on or off
  • vertical swing: on or off

So with 15 temperatures (the Daikin IR protocal works in increments of .5°C), 2 modes, and 4 fan modes, that’s 120 commands total. +1 for fully off.

Well, truth be told, I actually started with 19°C to 30°C, because it was summer, and thought I thought I was planning for heat I was, I didn’t think it through. So it was 23 possible temperatures, hence 184+1 commands.

With that, I modified the daikin.py script a little bit in order to just get the key sequence for a given config, and then just iterated over all the possibilities.

This gave me a first large lircd.conf config file of 40k+ lines, but that’s fine. Each command was identify by ON_[MODE]_[TEMP]_[VERTICAL_SWING]_[HORIZONTAL_SWING], for example ON_COOL_190_VFALSE_HFALSE

Trying it out

So I have that Raspberry Pi 3 already installed, I plug the IR Toy in, install lircd, copy the config file over (there was some trial and error as I had missed a few things when playing around to make one giant config file), and go for it.

Hurdle with the USB IR Toy

I’m just putting this here since this series of article will turn into “all the things that went wrong” (and there are quite a few), but I don’t have super precise notes.

There were permission issues on the device, that I tried to fix with some udev sorcery, and I never quite figured that out (back in my days there wasn’t anything like udev 🧓🏻 ), but I didn’t really try too long, and after 10 minutes, if was clear that for this phase, I was going to call lirc as root, and that’s not the end of the world.

I remember however getting an error message that the device couldn’t be written to. After searching a bit, turns out I needed to update the IR Toy’s firmware. That’s was surprisingly straightforward, and it worked.

Tadah!

Once that was fixed, I issued a command, something like

irsend SEND_ONCE daikin-pi ON_COOL_190_VFALSE_HFALSE

and the next thing you know, the unit in the room beeped!

I’ll admit it, I got really excited and thought that I could just focus on the frontend at that point. It was clear that the IR part was figured out…