# ESP32 air-con controller

> An ESP32 that learns an air-con remote's IR codes, replays them, reads the room, and runs its schedules even when the internet is down.

Canonical: https://mark-web.com/projects/esp32
Author: Mark Sulleza
Stack: C++ on PlatformIO, KiCad, AWS IoT Core, Lambda, DynamoDB, CDK
Source: https://github.com/mSulleza/esp32

## The board

[Screenshot: The routed top layer of the controller board in KiCad.] An orderable integrated board, with a schematic, a parts list for assembly and fabrication steps in the repo. The prototype is a dev board and modules on a breadboard.

An ESP32 GPIO can't drive an IR LED to remote-control range by itself: it sources tens of milliamps, and the LED wants a hundred or more in short pulses. So the LED runs off the 5 V rail through a transistor the GPIO switches. The IR receiver is a 38 kHz demodulator module and connects straight to a pin, and a temperature and humidity sensor sits on I²C.

## The enclosure

[Screenshot: An exploded view of the printed enclosure, the lid above the base.] A printed two-part enclosure, with an open window over the IR parts.

[Screenshot: The lid's features over the board from above: USB-C, buttons, the IR window and the sensor vent.] The lid's openings over the board, seen from above.

## Teach it your remote

1. Put the device in capture mode with the button or the API.
2. Point the air-con remote at it and press each button you'll want: power, modes, temperatures, fan speeds.
3. The codes are stored on the device, and replaying one drives the air-con exactly as the remote would.

## Control and schedules

Commands and schedules go through a small AWS backend: an HTTP API in front of Lambda, DynamoDB for state and schedules, and AWS IoT Core over MQTT with TLS to the device. Every API route needs a signed-in user, and the device's IoT policy reaches only its own topics.

The device keeps its schedules locally and fires them on time even when the internet is down. Steady-state cost is a few cents a month per device: Lambda instead of a server, and no VPC or NAT gateway.

## Updates

Firmware updates are signed. The device checks an ECDSA P-256 signature over the whole image before switching to it, and a failed check aborts the update.
