← All postsMy bed base just got smarter with an ESP32

My bed base just got smarter with an ESP32

To be fair, my adjustable base was already smart enough. It speaks Bluetooth Low Energy, which is how the remote talks to it. What is flaky is all the infra around it, and it is genuinely awkward to control.

First the remote died, then the app made it worse

The base shipped with a physical Bluetooth remote, which of course died on me about three months later. I could have changed the batteries, but I have been down that road before with other battery powered things around the house, and it turns into an infernal cycle of dying devices (yeah, I am looking at you, Nest by Yale). So I decided to let it die and go the smart home route, which was supposed to be the best idea. One device to control them all.

The app is not the best experience in the world. It is slow to scan and slow to connect. It is generic across a whole family of similar beds, so there are a couple of steps to wade through before I even reach my own remote screen. And once I am done, I have to remember to actually close it, because if it stays connected in the background it holds the link to the smart controller and blocks other clients from connecting to it, since the BLE controller can only hold a single connection at a time. Which in practice means my partner cannot control it at the same time.

It is also purely local and purely manual. There is no way to automate any of it based on the house temperature or the room lighting.

The One that flipped the equation

So I decided an ESP32 was the way to go. One board sitting in the bedroom holding a permanent BLE link to the base, which gets me multiple clients on it, automations, and real remote control.

It took a few iterations to work out what to send. Once I had the commands, the whole thing became an ESPHome YAML on an ESP32 that keeps the BLE client connected, publishes over MQTT to Home Assistant, and shows up there as a normal device.

The SmartBed dashboard in Home Assistant: head and foot controls, under-bed light, massage wave, flat preset and an emergency stop

Head up and down, foot up and down, under-bed light, massage wave, a flat preset, and an emergency stop. All of it from the Home Assistant companion app, and all of it snappy, because nothing has to scan and pair first. The ESP is holding the line so the rest of us can rest easy (no pun intended).

Telling the motor when to stop

The one thing I really needed to emulate was how to tell the motor when to stop. That logic is not in the bed, it is baked into both the physical remote and the app.

A single tap only moves the bed in snail steps. So to get any sense of actual movement I had to emulate multiple taps in quick succession. That is what each movement script does: it fires the same 5 byte command every 200 ms, up to 75 times, and then sends the stop command at the end.

The good thing about the bed controller is that it stops on its own when it hits the hardware limits, so I never had to work out where the edges are (phew, dodged that one).

The scripts run in mode: restart, so a new press cancels the one already running and takes over. That is the feature that lets me keep levering the bed into place, and that is all it is. Each script also checks the BLE client is still established before every write, so a dropped link ends the movement rather than silently doing nothing.

The board flashes its LED on each press and publishes an event to MQTT, so every button press is visible in Home Assistant and available as an automation trigger.

The Pachy device page in Home Assistant, showing the ESPHome and MQTT integrations and a live activity log of button presses

It has been sitting in the bedroom doing this quietly for months. The bed is effectively on my home WiFi. Multiple people can control it, nothing has to be paired, and no app has to be closed.

Crazy thing I could do with this thing now

The base has a feature where you tap a button when your partner hears you snoring, and it raises your head just a touch, which helps with my sleep apnea. It works, but it needs someone to hear me. Not me, obviously, I am dead asleep in the middle of the thing.

I also have a PAP machine, and it detects snoring on its own. That data already lands in Home Assistant, live, as its own sensor.

The ResMed dashboard in Home Assistant, where the machine's own snore and therapy metrics already arrive as live sensors

So the full circle is right there: snoring event detected, bed goes into snoring mode, nobody has to wake up.

It is not built yet. The anti-snore preset was not one of the commands I got out of the remote when I sniffed it. I have the eight that are wired up, plus zero gravity, massage start and a memory position that I found but never exposed. The snore position needs one more capture session, and then the automation itself is the easy part.

That is the next thing I do to this bed.

I am really excited about how good ESP has gotten

It has been a game changer at home for these little quirks everybody has in different spaces, and for being able to customize your own home quickly and cheaply.

The whole thing runs on an ESP32-C3 Super Mini.

If you want one of these on your own bed, let's talk.

I genuinely think you could have an incredible custom smart home with small tweaks and cheap investments that could increase your level of comfort 100 times (I am kidding, it could be more). If you are curious about one thing in your home you could do with this, it can probably be done. Book a session and we can do incredible things to your home.

Want this built for you? Book a consult