Danny Guo | 郭亚东

Automating My Air Conditioner

 ·  488 words  ·  ~3 minutes to read
I may earn commissions from purchases made through affiliate links in this post.

I have a dumb window air conditioner in my bedroom. It’s dumb in the sense that it doesn’t have a built-in thermometer, so it’s unable to maintain a constant temperature.

Edit: Someone helpfully pointed out that my unit does have the ability to self-regulate. Looking at some customer reviews, I do see some complaints that it doesn’t work very well on this model. But still, I should have read the manual instead of assuming that the top knob is just a static control. My bad!

Frigidiare air conditioner controls

If I leave it on overnight, it eventually makes the room too cold. I decided to automate it using an air quality monitor and a smart plug.

Air Quality Monitor

Last year, I watched David Heinemeier Hansson’s talk on indoor air quality and bought an Awair Element air quality monitor on his recommendation.

Awair Element

The Element monitors temperature, humidity, carbon dioxide, volatile organic compounds (VOC), and fine dust levels (PM2.5). Awair provides an official API, which makes it easy to pull the data. I did some yak shaving and wrote a JavaScript client for the API.

I run some personal software on a Vultr VPS, so I added a cron job to query the API for the current air quality metrics every 10 minutes.

Smart Plug

Next, I had to figure out how to turn the air conditioner on and off. I investigated smart plugs but didn’t find any with APIs that are intended for public use.

Most of the plugs integrated with voice assistants like Alexa and Google Home. However, I couldn’t find APIs for the voice assistants either. Voice control and the respective mobile apps seemed like the only ways to interact with them.

I ended up buying a Kasa smart plug.

Kasa smart plug

Kasa doesn’t provide a documented API, but other people have reverse engineered how Kasa’s mobile apps work, so I can use this Node.js package to control my plug remotely. Thanks to this package, it was easy to get things working.


Before going to sleep, I turn my air conditioner on to the low setting. Through the night, my VPS cron job checks the current temperature every 10 minutes. If the temperature is above 75°F, the job turns the smart plug on. If the temperature is under 73°F, the job turns the smart plug off.

This setup has worked well for me for the past summer. After the first night, it was very satisfying to check the Awair app and see that the temperature bounced between the two thresholds.

Awair app screenshot


It would have been much easier to spend a little more money in the first place to buy an air conditioner that has a built-in thermometer.

I learned later that I also could have used IFTTT, which has an Awair integration, with a high temperature trigger and a low temperature trigger. I could have linked these triggers to the Kasa integration to turn the smart plug on and off.

But doing it through the APIs myself was much more fun!

← How to Replace All Instances of a Substring in JavaScript How to Get a Free S/MIME Certificate →

Follow me on Twitter or Mastodon or subscribe to my newsletter or RSS feed for future posts.

Found an error or typo? Feel free to open a pull request on GitHub.