Electronics
MQTT Button with an ESP-01
An ESP-01 with a push button that publishes its state over MQTT, for use with Homebridge.
- Homebridge
- MQTT
- Archived
- 1 min read
Archived project
The GitHub repository for this project is archived: it is read-only and no longer updated. What follows describes the project as it was, so check for a newer alternative before you build it.
A wireless button on an ESP-01. Press it and the state goes out over MQTT, and the led on the module follows. Any other device can subscribe to the same topic.
Homebridge is a program that runs on a computer such as a Raspberry Pi, and makes devices that do not support HomeKit show up in the Apple Home app. This project dates from the Homebridge years, before the native HomeKit firmware of this site. For how the site builds HomeKit devices today, see HomeKit or Matter for your ESP32.
MQTT is a light messaging protocol: devices publish messages on a topic, and other devices that subscribe to that topic receive them, through a broker.

How it works
| Pin | Use |
|---|---|
| GPIO0 | The button |
| GPIO2 | A control led to see that everything works |
On every press the sketch toggles its state and publishes ON or OFF on the topic button/01. It subscribes to the same topic, so the led follows what any device on the topic says. A debounce time ignores noise on the input. Change the topic for every button.
Good to know
- The sketch is version 1.7.4 and uses the PubSubClient library.
- The repository is under the MIT licence.
- Apple, HomeKit and Homebridge are trademarks of their owners. This project is not made or approved by them.
The project is in the HomeBridge-MQTT-Button repository on GitHub.
More projects
Keep building.
Electronics, 3D printing and CNC builds, documented from the first idea to the last screw.
All projects

