Rough estimate, check with your seller: prices vary by shop and period.
Project goal
You will measure temperature, humidity, atmospheric pressure and light level with two small sensors, a BME280 and a BH1750, and send everything to Home Assistant, the software that gathers your connected devices. Both sensors share the same two wires, what is called an “I²C bus”, on an ESP32, a small electronic board with Wi-Fi. The build works indoors and, once sheltered from rain and sun, outdoors.
Why build it
Atmospheric pressure announces changes in the weather, light level can drive shutters and lighting, and the outdoor temperature feeds heating and watering. One ESP32 therefore replaces several off-the-shelf sensors, and every reading arrives in the same place.
Useful terms for this project: ESP32 (small Wi-Fi board) · ESPHome (prepares the board’s program) · GPIO (the board’s pins) · OTA (update without a USB cable)
Prerequisites
- Home Assistant with ESPHome and Wi-Fi reaching the install spot.
- A BME280 module (3.3 V, I²C) and a BH1750 module (“GY-302”). Beware of BMP280 boards that look the same: they do not measure humidity.
- Outdoors: a rain-protected USB supply and a vented shelter such as a Stevenson screen.
Diagrams
Parts list
This ESP32 board is the base for every project in the series. ESPHome also works with other ESP32 boards: the board-choice guide helps you compare them. Which ESP32 board to choose?
Suggested board
ESP32-C6-DevKitC-1
- Wi-Fi 6, Bluetooth 5, Zigbee and Thread (at hardware level)
- Supported by ESPHome (ESP-IDF framework)
- USB-C for flashing and power
Watch-outs
- 2.4 GHz Wi-Fi only
- Use a USB cable that carries data
Main components
| Item | Quantity | Role and precautions |
|---|---|---|
| ESP32-C6-DevKitC-1 | 1 | Control board (see the box above). |
| BME280 I²C module (address 0x76 or 0x77) | 1 | Temperature, humidity and pressure. Check it is a BME280, not a BMP280. Main component: search for « BME280 I2C module pressure temperature humidity » at your seller (affiliate link, check price and availability). |
| BH1750 module (GY-302) | 1 | Measures light from 1 to 65,535 lx, which saturates in direct sun: use a diffuser outdoors. Main component: search for « BME280 I2C module pressure temperature humidity » at your seller (affiliate link, check price and availability). |
| Radiation shield (printed or commercial Stevenson screen) | 0–1 | Essential outdoors: without a shelter, the sun skews temperature by several degrees. |
Small parts
| Item | Quantity | Role and precautions |
|---|---|---|
| USB-C data cable | 1 | For flashing and power. Charge-only cables do not carry data. |
| USB 5 V power supply (CE/UKCA-marked charger) | 1 | At least 1 A for the board alone; more if peripherals draw power from it. |
| Dupont jumper wires (male-female and female-female) | 1 | One mixed pack covers every prototype. |
| Breadboard | 1 | To test without soldering; replace with a soldered build if you need it permanent. |
| Soldering iron and solder (optional) | 1 | Only for a permanent build; the prototype works without. |
| Heat-shrink tubing | 1 | Insulates solder joints and splices; avoid tape in a permanent build. |
| Vented plastic or 3D-printed enclosure | 1 | Protects the board; leave a cable gland and vents if the sensor measures air. |
Amazon links are affiliate links: the site may earn a commission at no extra cost to you.
Step-by-step build
Step 1. Prepare ESPHome and create the device
- In Home Assistant, open the ESPHome Device Builder add-on (see the tutorial “Install ESPHome in Home Assistant (Device Builder)”). ESPHome is the software that turns a simple settings file into the program for your ESP32 board, without you having to write any code.
- Open “Secrets” (top right): this file keeps your passwords apart, so you can share your configurations without revealing them. Check that wifi_ssid (the name of your Wi-Fi network), wifi_password, api_encryption_key (the key that encrypts the link with Home Assistant), ota_password (for updates without a cable) and ap_password (for the board’s fallback Wi-Fi network) exist, and add any missing line. A valid API key is a long 32-byte string encoded in base64, which you can generate with “openssl rand -base64 32”.
- Click “New device”, name it “station-meteo”, pick ESP32-C6, skip the flash for now, then replace the file content with the YAML from this page (“Edit”). YAML is a configuration file written in plain text: it describes, line by line, what the board must do.
What you should see: The file opens in the editor with syntax highlighting and no red underline.
Check: The “Validate” action (⋮ menu) answers “Configuration is valid”.
Step 2. Wire both sensors on the I²C bus
- With the USB power unplugged, connect the board’s 3V3 pin to the BME280’s VIN pin and the BH1750’s VCC pin, then a GND pin of the board to the GND pins of both sensors: 3V3 is the 3.3-volt power supply and GND is the ground.
- Connect SDA of both modules to GPIO6 and SCL of both modules to GPIO7: SDA carries the data and SCL the rhythm (the clock) of the exchange, two wires shared by both sensors, which the board tells apart by their address. GPIO refers to the metal pins lined up along the edge of the board.
- Leave the BH1750 ADDR pin unconnected (address 0x23) and the BME280 SDO pin at GND or free depending on your module (address 0x76).
What you should see: Nothing gets hot; the modules run on 3.3 V.
Check: Every wire is on the right pin: SDA to SDA and SCL to SCL, never crossed.
Step 3. Flash the board and add it to Home Assistant
- Connect the board to your computer with the USB-C data cable: “flashing” means writing the program into the board’s memory, and this first write must be done over a cable. The board can already be wired or sitting on the breadboard, but any external peripheral with its own power supply must stay switched off.
- In ESPHome click “Install”, then “Plug into this computer” (Chrome or Edge over HTTPS) or “Manual download” and upload the file with ESPHome Web (web.esphome.io). If the port is missing, follow the flashing tutorial.
- After the reboot open Settings → Devices & services: the ESPHome device is discovered; click “Configure” and paste the API encryption key.
What you should see: The “Logs” show the Wi-Fi connection and then “Successfully connected to Home Assistant”.
Check: The device appears under Devices & services → ESPHome with its entities; later updates need no cable and go over Wi-Fi (this is OTA, “Over The Air”).
Step 4. Check that both addresses are detected
- Install the YAML, the configuration file from this page, on the board: the “scan: true” option lists the I²C addresses found in the log, that is the “number plate” of each sensor on the bus.
- Open the device logs in ESPHome.
- Look for the lines “Found i2c device at address 0x23” and “0x76” (or 0x77).
What you should see: Both addresses appear in the log.
Check: If 0x77 appears instead of 0x76, fix “address” in the YAML.
Step 5. Check the readings in Home Assistant
- In Home Assistant, open the ESPHome device: four readings have been created there, “Temperature”, “Humidity”, “Pressure” and “Illuminance” (the light level).
- Compare the temperature with a reliable thermometer in the same room.
- Cover the BH1750 with your hand: the value drops.
What you should see: Values are plausible: pressure around 1,000 hPa, indoor humidity between 20 and 80 %.
Check: The temperature gap stays under about 1 °C; otherwise move the sensor away from the warm board.
Step 6. Install outdoors (optional)
- Place the BME280 in the ventilated shelter, in the shade and away from a wall exposed to the sun, about 1.5 m above the ground: at that height and out of direct sun, the reading reflects the real air temperature rather than that of a hot wall.
- Put the BH1750 in open air under a translucent diffuser, sensor facing up.
- Protect the board and supply in a waterproof enclosure; let only the sensor wires leave it.
What you should see: Outdoor temperature follows a nearby reference station with a small offset.
Check: Check for condensation inside the enclosure after a cold night.
ESPHome code (YAML)
YAML is a configuration file written in plain text: it tells ESPHome what the board must do. Paste this one into ESPHome after creating the device. It targets an ESP32-C6 board; values to personalise are marked with “CHANGE” comments.
esphome:
name: station-meteo
friendly_name: Weather station
esp32:
board: esp32-c6-devkitc-1 # XIAO ESP32C6: use board: seeed_xiao_esp32c6
framework:
type: esp-idf # required for ESP32-C6
logger: # serial logs, also visible over Wi-Fi
api:
encryption:
key: !secret api_encryption_key
ota:
- platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid # 2.4 GHz network only
password: !secret wifi_password
ap: # fallback hotspot if the Wi-Fi is unreachable
ssid: "station-meteo fallback"
password: !secret ap_password
captive_portal:
i2c:
sda: GPIO6 # I2C bus shared by both sensors
scl: GPIO7
scan: true # lists detected addresses in the log
frequency: 100kHz
sensor:
- platform: bme280_i2c
address: 0x76 # 0x77 if the SDO pin is tied to 3.3 V
update_interval: 60s
temperature:
name: "Temperature"
oversampling: 16x
pressure:
name: "Pressure"
humidity:
name: "Humidity"
- platform: bh1750
name: "Illuminance"
address: 0x23 # 0x5C if the ADDR pin is tied to 3.3 V
update_interval: 60s
- platform: wifi_signal
name: "WiFi signal"
update_interval: 120s
entity_category: diagnostic
YAML comments are in English, as in the ESPHome documentation. This code has not been run on your hardware: use “Validate” before flashing and adjust pins and names.
Home Assistant integration
- The four entities appear as one device; Home Assistant keeps their history and plots them on the dashboard (history card or gauge).
- Measured pressure is absolute, at your altitude. To compare with a forecast, convert it to sea level (roughly 12 hPa more per 100 m of altitude near sea level).
- Useful automations: close blinds when light passes a threshold, or start ventilation when indoor humidity exceeds 65 %.
Common problems and troubleshooting
| Symptom | Fix |
|---|---|
| No address detected in the log | SDA and SCL are swapped, a module is not powered or a pin solder joint is bad. Check the wires one by one. |
| Humidity at 0 % or missing | You probably have a BMP280 (no humidity). Check the reference printed on the chip; you need a BME280. |
| Temperature several degrees too high | The sensor is too close to the board or in direct sun. Move it away with a longer wire and shelter it. |
| Light stuck at 65,535 | The BH1750 is saturated in direct sun. Add a translucent diffuser in front of the sensor. |
FAQ
Can I add more sensors on the same bus?
Yes, as long as addresses differ; the I²C bus can host several modules on the same two wires.
Do I need a BME280 or a BMP280?
A BME280 if you want humidity; the BMP280 only measures temperature and pressure.
Are the sensors accurate?
Values are good enough for home automation; for a reference value compare with a calibrated instrument, as accuracy depends on the module and its self-heating.
Related tutorials
These step-by-step guides explain the gestures common to every project in the series.
- Install ESPHome in Home Assistant (Device Builder)Install the add-on, prepare your passwords (secrets) and create the first device
- Flash an ESP32 with ESPHome (USB, drivers, boot mode)First upload over USB, CP210x and CH340 drivers, boot mode
- ESP32 wiring basics: GPIO, 3.3 V and pull-upsWhich pins to avoid, 3.3 V versus 5 V, pull-up resistors and common ground
- ESPHome OTA updates: flash without a cableUpdate the board without a cable, OTA password and recovery if something goes wrong
