Shop-bought room sensors are cheap, but building your own with ESPHome shows you how they work, keeps everything on your own network, and lets you add whatever sensors you like. ESPHome turns a short settings file into firmware for an ESP32, and Home Assistant finds the device by itself. This project builds a temperature, humidity and pressure sensor, then uses it in an automation that turns on a dehumidifier when a room gets damp.
What you need
- Home Assistant OS running on your network
- An ESP32 development board and a USB data cable
- A BME280 sensor module (3.3 V)
- Two half-size breadboards and four jumper wires
- A computer with Chrome or Edge, for the first install over USB
Shopping list (6 items)
Some shop links are affiliate links (Amazon UK, Tooled Up): if you buy through one we may earn a small commission, at no extra cost to you. As an Amazon Associate I earn from qualifying purchases. It never changes which products we recommend, and no shop has paid to be included.
Everything for this build, in one place. Each link goes to a page we checked had the part in stock.
- 1×Home Assistant Green (or any Home Assistant OS system)Skip this if you already run Home Assistant OS. A Home Assistant Container install has no apps, so it needs ESPHome installed another way.
- 1×ESP32 development board (ESP32-WROOM-32, 30 pins)A pack of two ELEGOO boards with USB-C and a CP2102 USB chip, so the spare can go in your next project. The board is wide: put it across two breadboards side by side so both rows of pins have free holes.
- 1×USB-A to USB-C data cableThe boards come without a cable. These Anker cables carry data as well as charge, which uploading needs.
- 1×BME280 sensor module, 3.3 V, pins already solderedIt must say BME280. The cheaper BMP280 looks almost the same but has no humidity sensor.
- 2×Half-size breadboards (400 points)Two side by side, with the ESP32 straddling the gap between them.
- 1×Jumper wire kit (male-male, male-female and female-female)40 of each kind. Male-female wires go from a Raspberry Pi's pins to a breadboard.
Each button opens that shop's page for the part, checked when we wrote the list; if one shop is out of stock, try the next. Any equivalent part with the same value works.
The circuit
| BME280 pin | ESP32 pin |
|---|---|
| VIN (or VCC) | 3V3 |
| GND | GND |
| SCL | GPIO 22 |
| SDA | GPIO 21 |
It's the same wiring as our ESP32 weather station. Put the sensor a few centimetres away from the board on its wires, because the ESP32 warms up when Wi-Fi is on and would make the temperature read high.
Install the ESPHome Device Builder
- In Home Assistant, go to Settings → Apps → Install app. (Apps used to be called add-ons.)
- Find ESPHome Device Builder, select it and choose Install. When it has installed, turn on Show in sidebar and choose Start.
- Open ESPHome Device Builder from the sidebar.
Create the device
- Choose New device, give it the name
room-sensor, and choose ESP32 when it asks for the type. The first time, it also asks for your Wi-Fi name and password and saves them in its secrets file. - Plug the ESP32 into the computer you're using, and choose to install it over USB from the browser. This puts ESPHome on the board for the first time. It needs Chrome or Edge. If yours can't, choose to download the file instead and flash it with ESPHome's web tool.
- When it finishes, the board joins your Wi-Fi. From now on you can update it over Wi-Fi, so it can live anywhere with a USB power supply.
The Device Builder writes a settings file for you, with your Wi-Fi details, an encryption key and an update password already in it. Keep those lines as they are.
Add the sensor
Choose Edit on the room-sensor card, and add these lines to the end of the file:
i2c:
sda: GPIO21
scl: GPIO22
sensor:
- platform: bme280_i2c
address: 0x76
update_interval: 60s
temperature:
name: "Temperature"
oversampling: 1x
humidity:
name: "Humidity"
oversampling: 1x
pressure:
name: "Pressure"
oversampling: 1x
- platform: wifi_signal
name: "Wi-Fi signal"
update_interval: 300s
Then choose Install and Wirelessly. ESPHome builds the new firmware (the first build takes a few minutes) and sends it over Wi-Fi. We checked the complete file with ESPHome's own validator.
i2csets up the two-wire bus on GPIO 21 and 22.bme280_i2creads the sensor once a minute. If your module uses address0x77, change the address line.oversampling: 1xtakes one sample per reading, as Bosch recommends for weather monitoring.wifi_signalreports the Wi-Fi strength, which is handy when choosing where to put the sensor.
Add it to Home Assistant
Home Assistant notices the new device by itself. Go to Settings → Devices & services, where it appears as discovered, and choose Add. You'll then have entities such as sensor.room_sensor_temperature and sensor.room_sensor_humidity to put on dashboards, graph and use in automations.
Automation: turn on a dehumidifier when it's damp
Damp rooms grow mould. Above about 70 % relative humidity for long periods, mould becomes much more likely. This automation turns on a dehumidifier plugged into a smart plug when humidity stays above 70 % for 10 minutes, and off when it has been below 60 % for 10 minutes. The gap between the two numbers stops it switching on and off over and over. Create it under Settings → Automations & scenes, or paste it in YAML mode, changing switch.dehumidifier_plug to your own plug's entity:
alias: Dehumidifier on when damp
triggers:
- trigger: numeric_state
entity_id: sensor.room_sensor_humidity
above: 70
for:
minutes: 10
actions:
- action: switch.turn_on
target:
entity_id: switch.dehumidifier_plug
alias: Dehumidifier off when dry
triggers:
- trigger: numeric_state
entity_id: sensor.room_sensor_humidity
below: 60
for:
minutes: 10
actions:
- action: switch.turn_off
target:
entity_id: switch.dehumidifier_plug
A numeric state trigger only fires when the value crosses the threshold, so if the room is already above 70 % when you save the automation, it waits for the next time humidity rises past 70 %. Check that your dehumidifier turns itself back on when its power returns: some need a button press, so a smart plug can't start them. Use a plug rated for the dehumidifier's power. Our guide to smart plugs explains ratings.
Troubleshooting
- The sensor shows as unavailable: open the device's logs in ESPHome Device Builder. An error about the BME280 usually means the wiring or the address is wrong.
- Home Assistant doesn't discover it: both must be on the same network, and the device name must be unique. Add it by hand under Settings → Devices & services → Add integration → ESPHome, using the board's IP address.
- The temperature reads a degree or two high: move the sensor further from the ESP32, or add an offset filter in ESPHome once you've compared it with a trusted thermometer.
Take it further
- Add the soil sensor from our plant watering reminder to get a phone notification when a plant is dry.
- Read our guide to smart home protocols to see how Wi-Fi devices like this compare with Zigbee, Thread and Matter.
Sources
The main references behind this guide. Numbers we worked out ourselves, such as the code outputs, come from running the code.