How to Control Your Air Conditioner with Raspberry Pi Board and ANAVI Infrared pHAT

Leon ANAVI may be a full-time software engineer, but in his spare time he has started to develop open source hardware project with the help of others and by himself. Last year, I got hold of his RabbitMax Flex HAT for Raspberry Pi, and tested it with the provided LCD display, one temperature sensor, and a Raspberry Pi 2 board. The board also featured IR receiver & transmitter, and I tried to use it with my aircon remote control, but at the time I did not find a way to do it easily, and control my TV with LIRC instead. Leon has now made a simpler, smaller, and cheaper add-on board for Raspberry Pi Zero, and other Raspberry Pi boards with a 40-pin header, with 3x I2C headers, two IR transmitters, and one IR receiver. He sent me a sample of “ANAVI Infrared pHAT”, and after quickly describing the board, I’ll show how to I could control my air conditioner with a Raspberry Pi 2 board and his Infrared pHAT.

ANAVI Infrared pHAT

The top of the has the 3x I2C header for 3.3V sensors, a UART header to access to serial console, two x 5mm IR transmitters (IR LEDs), and one IR receiver (IR photo sensor). It also has an EEPROM to store the HAT ID.

Click to Enlarge

The other side comes with the 40-pin female header to connect to your Raspberry Pi board.

The board was designed with KiCAD, and the hardware design files are released under a “Creative Commons Attribution-Share Alike 3.0 United States” License on github.

ANAVI Infrared pHAT Connection to Raspberry Pi Board

There’s only one step: insert the board on the 40-pin connector of your RPi board. You can only make one mistake, inserting it the wrong way. It has to be connected in away that it covers part of the board.

I’ve connect it with a Raspberry Pi 2 board with a battery kit, but it fits even better on the Raspberry Pi Zero, or newly released Raspberry Pi Zero W.

Setting up Raspberry Pi, and Controlling the Air Conditioner with LIRC

It’s time to start software setup in order to control the Haier air conditioner pictured below.

You’ll need to install Raspbian, and some packages including LIRC, but I’ve already explained how to do that in RabbitMax Flex Getting Started Guide, so I’m not going to repeat those steps here, especially you can find them in ANAVI Infrared pHAT user’s manual too, and I’ll assume you have already setup your board.

The reason why I could record IR commands from my TV remote control, and not my aircon remote control last time around, is because aircon remotes send not only one byte but also status info each time. The trick is to use mode2’s “alternative display mode” to capture pulse/space data as raw config files.

Let’s do that:


Now I faced the IR receiver and pressed the power key on the remote control:

Wow, that’s a whole bunch of numbers, but that’s exactly what we need as those are the duration of the high and low levels of the IR signal. I have repeated the same command, but capturing 4 keys: off, on, up to 29C, and down to 28C.


Then we need to edit our lircd-haier-ac.conf file manually:

Note that you need to delete the first “big number” from each captured command. For example, I had to delete “4989552” from the first capture of the power key. If you want full control, you’ll need to record all keys. You may want to read lircd.conf manual to understand parameters like aep or aeps. I used the default values, but in case it does not work for you, or works unreliably, you may have to adjust them, possibly from data obtained using an oscilloscope. I did not have such problem, and copied the file to /etc/lirc/lircd.conf:


In theory, you can restart lircd from the command line:


but in my case, I always had troubles when running irsend command:


So I had to reboot the board with sudo reboot to enable changes. Later I used the reload command (to take into account the update config) after restart, and I could avoid a reboot:


Once it’s all working, we can list the keys we’ve just defined in lircd.cong:


To turn on the aircon:


Then I was not sure what action would happen when I recorded the up key once setting the temperature. So I first set the temperature to 23C to check whether it would increment the temperature to 24C, or set it to 29C:


And the later happened, which means you need to record all temperatures you want to set, and there’s no such thing as UP and DOWN keys.

You’ll already guessed how to turning off the aircon:


Then I realized that since “29C” and “28C” commands send the temperature, it might also send the power status, and indeed I can turn on the aircon @ 28C directly with with 28C command. So instead of recording keys for your aircon, you are actually recording “scenes” which you could name “night”, “25Cfanlowswingup”, “off”, and so on. I added 25Cfanlowswingup with temperature set to 25C, fan speed set to low, and swing set to up, added it to lircd.conf, and a single command would turn on the aircon and set all those values:


Pretty neat.

While the instructions above will work with any board with IR receiver (for first time setup) and IR transmitter, you may be interested in getting ANAVI Infrared pHAT on Indiegogo for $9 plus shipping ($5 to  $7). There are also other rewards including the pHAT, I2C sensors, and debug tools. The campaign has already surpassed its funding target ($500), and delivery is planned for September 2017.

Share this:
FacebookTwitterHacker NewsSlashdotRedditLinkedInPinterestFlipboardMeWeLineEmailShare

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK Pi 4C Plus

22 Replies to “How to Control Your Air Conditioner with Raspberry Pi Board and ANAVI Infrared pHAT”

  1. Way to go overboard. The same can be done with an ESP8266 and an IR led. You dont even need a resistor since ESPs are 3.3V.

    I’ve put such a setup inside a radio once and simply pointed at the IR receiver from behind.

  2. Great article! Thanks for covering my open source hardware hobby project with the awesome tutorial with the exact steps 🙂

  3. @Leon Anavi
    I wonder with how many Orange Pi boards your HAT would be compatible? At least in Armbian with mainline kernel we introduced DT overlays recently that can be used with such HATs: https://github.com/igorpecovnik/lib.docs/blob/master/docs/Hardware_Allwinner_overlays.md

    And in linux-sunxi wiki one user took the time to add GPIO header pin outs at least for all Orange Pi some weeks ago: http://linux-sunxi.org/Category:H3_Boards

    Maybe you could add some boards to your compatiblity list?

  4. @tkaiser I haven’t tried out the Infrared pHAT with Orange Pi yet. My focus for this project is Raspberry Pi. Btw the majority of the Allwinner development boards that I have are open source hardware from Olimex but their pin out is not compatible with Raspberry Pi. Speaking about Sunxi mainline kernel, recently I read the specifications of NextThingCo about making DIPs for C.H.I.P. The procedure for flashing a device tree fragment in an EEPROM seems very similar to HAT/pHAT for Raspberry Pi.

  5. Hi @Leon Anavi
    Thanks for the detailed description i am able to control my air conditioner from the raspberry pi. Now that the that part is done i want to control other air conditioners too. I have 2 Ac’s of the same company(same model) that i want to control independently from the raspberry pi. Is it possible that i can do this

  6. @Haris
    I think you can define multiple remote controls in lircd.conf

    There may also be a neater way by defining the remote control in separate files, one for each report, and using the include parameter in lircd.conf. See documentation @ http://www.lirc.org/html/lircd.conf.html

  7. @Aditya Mundhalia
    I have just used the default value, and did not look too much into it.
    But LIRC manual explains:

    gap A (typically long) space which follows the trailing pulse.

    It does not show in the data, but I’d assume it might be the minimum time between the end of a key press, and the beginning of another key press. (TBC)

    Do you have troubles with the gap?

    1. cnxsoft thanks gor the reply. I have lirc on my rpi3 works flawlessly on my home theater. But cant get it working with my aircon. I got the raw data as above but don’t know what to put in gap value. Any help be appreciated. Thanks.

  8. Sorry for late reply my comment was not adding all code

    begin remote

    name mides
    flags RAW_CODES
    eps 30
    aeps 100

    ptrail 0
    repeat 0 0
    gap 28205

    begin raw_codes
    name on
    #first2 lines
    4385 4464 505 1685 509 591
    510 1689 510 1687 508 616

    #last 2 lines
    510 1689 510 1687 508 616
    516 1680 511 1685 510 1686
    511
    end raw_codes
    end remote

    1. I try to get high brightness emitters, Mmybe that will help. Also, I get different codes every time I click power button. Is it because of time?

  9. @Aditya Mundhalia
    The values represent the long and short pulses of the IR signals, so there could be some small variance each time.
    If the numbers are much different, then it should mean that some value – like time – inside the remote is changing each time.

  10. Thanks for sharing this!
    I managed to get my Midea AC running with the same principle and with the Anavi PiHat.

  11. Thank you very much for sharing this guide, very nice and clear tutorial. I got finally my panasonic air cooler working.

    1. @Jukka – have you got a working lircd.conf for your panasonic ? Can you post it somewhere ? Having a terrible time getting lirc to talk to mine.

  12. I am following the manual found http://anavi.technology/files/anavi-infrared-phat.pdf
    It has 2 glaring errors on pages 5 & 6. If you examine the install commands they are incomplete. There is obviously more to install on both pages, the cut and paste action used in the creation of the pdf file cut off some of the text, because there were too many characters to fit in one line of the pdf. This why there is an slide bar under the line of text.
    All though it doesn’t seem to effect the operation of the lirc software, my OCD forces me ask if anyone has the full “uncut” version of those two installs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Khadas VIM4 SBC
Khadas VIM4 SBC