Saturday, June 18, 2016

Automating the Air Conditioning - Step One: Control

Over the last couple years, a few articles about interfacing with IR controlled devices have popped up in my news feeds. Coincident with getting our new Air Conditioning Units (which have IR remote controls), a new walk-through popped up that seemed like something I could handle. The project required a cheap ESP8266 board (which has WiFi, some general purpose pins, and runs off micro USB for power), and an IR receiver and LED set for a total bill of materials of around ten dollars.

Here's another link to the project, to give credit where credit is due.

Once the parts arrived, it was time to get into black magic territory:

Here be Dragons

I got the Arduino IDE set up with no issues, and started playing with "sketches" - the code that runs on this little guy. I immediately ran into problems. It turns out you can't have spaces OR punctuation in the sketch name (which nobody bothered to mention in the tutorials I read), so my file "Brian's IR Emitter" had several problems right off the bat.

Once I got that figured out, I was able to load up the example IR recorder with no problems. I pointed the remote control at the receiver and started hitting buttons, with no idea what would happen next. Eventually I figured out (mostly by random clicking) that I needed to open the "serial monitor" to see the data the remote control was sending over IR. Here's the sample data from the "On/Off" button:

Encoding  : UNKNOWN
Code      : BBF4F9F (32 bits)
Timing[67]: 
     +9050, -4550     + 550, - 600     + 600, - 600     + 550, - 650
     + 550, - 600     + 600, - 600     + 550, -1700     + 600, - 600
     + 550, - 650     + 550, -1700     + 600, -1750     + 600, -1750
     + 550, -1750     + 550, -1700     + 600, - 600     + 550, -1750
     + 600, -1750     + 550, - 600     + 600, -1700     + 550, - 600
     + 600, - 600     + 550, - 650     + 550, - 600     + 600, - 600
     + 550, - 600     + 550, -1700     + 550, - 650     + 550, -1750
     + 550, -1750     + 600, -1750     + 550, -1750     + 550, -1750
     + 600, -1700     + 600
unsigned int  rawData[67] = {9050,4550, 550,600, 600,600, 550,650, 550,600, 600,600, 550,1700, 600,600, 550,650, 550,1700, 600,1750, 600,1750, 550,1750, 550,1700, 600,600, 550,1750, 600,1750, 550,600, 600,1700, 550,600, 600,600, 550,650, 550,600, 600,600, 550,600, 550,1700, 550,650, 550,1750, 550,1750, 600,1750, 550,1750, 550,1750, 600,1700, 600};  // UNKNOWN BBF4F9F

As far as I can tell, the remote for this particular model is pretty dumb. It sends out one command per button press, identical every time, and the AC unit decides what to do with that command (turn on or turn off, increment or decrement the temperature, etc.)

Next step was to swap out the receiver for an emitter (the IR LED). I made the switch, and tried to load the original poster's "emitter" sketch. And tried. And tried. And tried again. Nothing.

Turns out, the IR diode does something weird at start up (draws too much power, maybe?) and the entire ESP8266 hangs. I have to physically detatch the LED, boot the ESP8266 and then plug in the LED. That particular bug was not a lot of fun, and was only solved through an equal measure of google searches and dumb luck.

Once I got that working, I copied the original poster's simple web server, and made it even simpler, knocking it down to a single entry to toggle the power on my AC unit. Here's what the front end looks like, in its entirety:

Brian's ESP8266 IR Remote

FAN ON/OFF




Miraculously, it worked! And all I really needed is that link: http://192.168.1.194/ir?fan=power. A GET command to that link with cause the ESP8266 to issue the "toggle" IR command. Booyah!


Later on, I'll have to put this on a smart plug that can monitor energy usage, so I can know whether the unit is on or not, and decide to toggle the IR command or not. But that's for Step 2: Automation. For now, all I've done is add that toggle command to my Alexa HA Bridge (from BWS systems - it's the best Alexa HA bridge I've used so far)

Now that I've got this one working, I'll but together another one for the AC unit in the master bedroom, and then I'll integrate it with OpenHAB, and (hopefully) Nest. Making it work with Nest would be a real coup - I don't think anyone else has pulled that off yet, and I've got an idea for how to do it that I haven't ready about anywhere else. But that will be a post for another day, after some more parts arrive from Amazon.

No comments:

Post a Comment