David Furnes is a software engineer based in Brooklyn, New York. ❄️

Con Edison Smart A/Cs & Apple HomeKit

Controlling Con Ed's free Smart A/C kit with my iPhone & a Raspberry Pi.

Con Edison started offering free smart air conditioner kits a few years back. In exchange for letting ConEd occasionally adjust your air conditioner's temperature setting to reduce load on the electrical grid, you can make any A/C "smart"!

The Smart A/C kits are manufactured by ThinkEco, and use a temperature sensor to toggle the power on and off.1 Unfortunately, their app is slow & doesn't integrate into existing smart ecosystems, like Apple's Home app.

Homebridge

HomeKit is how smart devices integrate with Apple's ecosystem – allowing Siri to control the lights, or using geofences to automate devices when you arrive at home. Unfortunately, it isn't as widely supported as Alexa or Google Home.

Luckily, Homebridge is there to help. It's a Node.js application that acts as a "bridge" between third-party device APIs & the HomeKit spec. The homebridge-platform-smartac package adds support for the ThinkEco SmartAC thermostats.

Homebridge emulates a HomeKit "bridge" - a piece of hardware, like the Hue Bridge, that controls smart devices on a network. You'll need an "always on" device that can run Node.js - like a Raspberry Pi. I used a Raspberry Pi 3 B+.

Configuring Homebridge on a Raspberry Pi

I recommend setting up your Raspberry Pi using the official "Getting Started" guide, or this "headless setup" guide if you don't have a spare monitor and keyboard. Don't forget to change the default password!

Install Node.js with nvm

Homebridge's setup instructions use sudo npm install and --unsafe-perm, which is scary! Instead, I'd recommend installing Node.js with nvm (which does not suffer from the underlying node-gyp issue that requires those elevated permissions. Plus, it's easy to install & swap versions!)

Install Homebridge

Now, we can install Homebridge & its dependencies safely:

sudo apt-get install libavahi-compat-libdnssd-dev
npm install -g homebridge homebridge-platform-smartac

Next, create ~/.homebridge/config.yml using this template, with your ThinkEco username & password at the bottom. (Yes, you'll need to store your password in plaintext. 😬 This is one of the trade-offs of using an unofficial API like this.)

"platforms": [
    {
      "platform": "SmartAC",
      "name": "ThinkEco SmartAC Platform",
      "username": "YOUR_THINKECO_EMAIL",
      "password": "YOUR_THINKECO_PASSWORD"
    }
]

Make sure you've configured your ThinkEco modlets, and then run homebridge from your Raspberry Pi's terminal. You should see something like this:

Running 'homebridge' from the terminal

Open your Home app on your phone, choose the "+" button on the Home or Rooms tab, "Add Accessory", and then scan the QR code from the terminal.

You should now see your air conditioner(s) listed as HomeKit accessories!

Homebridge air conditioners in the iOS control center

Configure as a Background Service

Your Homebridge accessories will only work as long as the homebridge command remains running on your Pi's terminal. You can configure it to run in the background using systemd.

Add a new "service" with sudo systemctl edit --full homebridge:

[Unit]
Description=Homebridge
Wants=network-online.target
After=network-online.target

[Service]
Type=simple

# Set this to the user you want to run Homebridge as. The
# default Raspberry Pi user is simply named 'pi', and the
# working directory should be that user's home directory:
User=pi
WorkingDirectory=/home/pi

# You can find the absolute path for 'homebridge' by running
# 'which homebridge' from the terminal. It will likely look
# something like this (but with your Node.js version):
ExecStart=/home/pi/.nvm/versions/node/v8.16.2/bin/homebridge

[Install]
WantedBy=multi-user.target

You can run sudo systemctl enable homebridge to run this service automatically when your Pi starts (and sudo systemctl start homebridge to start it right now).

So how does this work?

Homebridge acts as an intermediary between the Home app & third-party APIs.

Homebridge communicates with the Home app using the HomeKit Accessory Protocol, via hap-nodejs. Different types of accessories, like Light or HeaterCooler, expose different information & abilities.2

On the other end, Homebridge communicates with devices via their own third-party APIs. (For example, the homebridge-platform-smartac plugin pretends to be a visitor to the ThinkEco website & uses their unofficial API).

Uh oh! About that unofficial API...

The downside of using an unofficial API is, well... it's unofficial! ThinkEco updated ther web application in July 2018 with a brand new API. This completely broke the Homebridge plugin, and I had to contribute a fix that updated all of those API calls to continue to control my air conditioners.

Here's hoping for official HomeKit support in the future!

Footnotes

  1. The ThinkEco remote takes temperature readings every 10 minutes. It uses these readings to cut power to the A/C once the sensor reads 1°F below your target temperature & turns it back on once the temperature is 1°F above the target. ThinkEco claims that this protects the air conditioner's compressor, but it's still probably not as safe as using the built-in power button.

  2. I was able to add the ability to "tap" an air conditioner to turn it on or off by changing the accessory type from Thermostat to HeaterCooler! Yay, open source!