Electronics
Temperature and Humidity over MQTT with an ESP-01
An ESP-01 with a DHT11 that publishes temperature and humidity every two seconds over MQTT.
- 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 temperature and humidity sensor that sends its readings over MQTT. It is built on an ESP-01 with a DHT11.
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
The DHT11 is on GPIO2. Every two seconds the sketch reads the humidity and the temperature in degrees Celsius, skips the round if a reading fails, and publishes both as text:
| Topic | Value |
|---|---|
/sensors/Temperaturesensor | The temperature |
/sensors/Humiditysensor | The humidity |
For a sensor with a wider range and better accuracy, see the newer ESP8266 HomeKit Temperature and Humidity Sensor, which also compares the DHT11 and the DHT22.
Good to know
- The sketch is version 0.1.6 and uses the PubSubClient and DHT libraries.
- 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 Apple-Homebridge-MQTT-Temperature-Humidity-Sensor repository on GitHub.
More projects
Keep building.
Electronics, 3D printing and CNC builds, documented from the first idea to the last screw.
All projects

