Your First ESPHome Sensor: Temperature, Humidity, or a Simple Reading
This is genuinely the lesson where your ESP32 finally does something real, wiring a BME280 sensor, adding its first hardware YAML section, and watching real temperature and humidity readings appear reliably in Home Assistant.
BME280 vs DHT22: what you're wiring
This lesson assumes a BME280, connected over I2C using just four simple wires, power, ground, and two data lines, and reliably reporting temperature, humidity, and pressure together. A DHT22 uses a single signal wire and reports only temperature and humidity, if that's what you bought, the section further down covers the small differences.
BME280 to ESP32 pin diagram
Connect the BME280's VCC pin to your ESP32's 3.3V pin, GND to GND, SDA to GPIO21, and SCL to GPIO22, the standard, widely-used I2C pins on most ESP32 DevKit boards. Double-check your specific board's pinout diagram, some boards label these pins slightly differently, but GPIO21 and GPIO22 are the default I2C pins ESPHome expects unless told otherwise.
Assembly on the breadboard
Place the BME280 module carefully on your breadboard, then use four jumper wires to connect it properly to your ESP32 exactly as described above. Keep all wires short and genuinely secure, a loose connection is a common source of intermittent, hard-to-diagnose readings later on.
Checks before connecting USB
Before plugging in your USB cable, visually trace each one of the four wires back to its correct pin, a wiring mistake caught now saves a confusing troubleshooting session later. Confirm no bare wire ends are accidentally touching each other on the breadboard, a short circuit here is a common, entirely avoidable beginner mistake.
The sensor section in YAML
Add an i2c section clearly declaring your SDA and SCL pins, then a sensor section with platform bme280, address 0x76 (or 0x77, depending on your specific module), and three named entities, temperature, humidity, and pressure, each with its own friendly name following Module 9's naming convention, "Office Temperature", "Office Humidity", "Office Pressure".
Calibration and first readings
BME280 sensors are factory-calibrated and generally quite accurate right out of the box, no manual calibration step is required for this module's purposes. Your first readings should look plausible immediately, room temperature and a reasonable humidity percentage, wildly incorrect values usually point to a wiring issue rather than a calibration one.
Compiling and OTA
Since this device already has ESPHome firmware from Lesson 4, this update can use OTA, wireless upload, rather than USB. Click Install, choose Wirelessly, and the new firmware, including your sensor configuration, uploads directly over your WiFi network, considerably more convenient than reaching for a USB cable each time.
What a first correct log means
A healthy log after this update shows the I2C bus initializing, the BME280 being detected at its address, and periodic sensor readings being logged, each showing a plausible temperature and humidity value. Seeing this pattern confirms both your wiring and your YAML are correct together.
I2C scan in the logs: quick diagnostics
ESPHome's i2c section can optionally scan for connected devices at startup and log every address it finds, useful for confirming your BME280 is actually detected before troubleshooting anything else. If the scan finds nothing, the problem is almost certainly wiring, not YAML.
ESPHome vs Zigbee: two temperature sources
If your office already has a Zigbee temperature sensor from Module 9, you now have two independent temperature readings for the same room, worth comparing, small differences of a degree or so are normal and expected between two different sensor models in slightly different physical positions.
Mini dashboard: both sensors side by side
Create a small dashboard card showing both your Zigbee and ESPHome temperature entities side by side, a genuinely satisfying way to see two different smart home technologies agreeing on the same physical reality in real time.
Dashboard: Zigbee vs ESP, what you see in HA
Both entities appear identically within Home Assistant's interface, a temperature sensor is simply a temperature sensor to the dashboard regardless of whether it arrived via Zigbee or ESPHome. This underlying consistency is exactly why Home Assistant can unify so many different smart home technologies under one roof.
Troubleshooting: NaN and unavailable
A "NaN" reading means the sensor responded but returned an invalid value, often a wiring or power issue. An "unavailable" entity means Home Assistant hasn't heard from the device recently at all, check your device's log first, it usually shows the underlying cause directly.
Checklist after adding a sensor
Confirm all three entities appear in Home Assistant, confirm their values look plausible, confirm the log shows a clean, repeating reading cycle, and note the sensor model and wiring in your ESPHome notebook before moving on.
Have a DHT22 instead of a BME280?
A DHT22 uses a single data pin rather than I2C's two, connect its data pin to any available GPIO, GPIO4 is a common choice, and use platform dht instead of bme280 in your sensor section. You'll get temperature and humidity but no pressure reading, everything else in this lesson applies identically.
Common problems with a first sensor
The most frequent issues are a swapped SDA/SCL connection, a wrong I2C address (try 0x77 if 0x76 shows nothing), and a loose breadboard connection. All three are quick to check and quick to fix once you know to look for them specifically.
OTA vs USB after Lesson 6
From this point forward, nearly every update to this device can use OTA, USB becomes necessary again only if the device stops connecting to WiFi entirely, a scenario Lesson 9's diagnostics lesson covers in depth.
What you record in your ESPHome notebook
Record the sensor model, the GPIO pins used, the I2C address, and today's date. This entry, alongside Lesson 4's device entry, forms the beginning of a genuinely useful hardware reference you'll extend throughout this module.
Exercise after this lesson
Wire your BME280 (or DHT22), add the sensor YAML section, update over OTA, confirm all entities report plausible values, and record the wiring details in your notebook.
Key takeaways
BME280 connects over I2C with just four wires, VCC, GND, SDA, SCL.
This update can use OTA, no USB cable needed after the first flash.
NaN usually means wiring, unavailable usually means connectivity.
Record sensor model, pins, and address in your notebook today.
With a working sensor reporting reliably, Lesson 7 introduces inputs and outputs, a button, a reed switch, and an LED.
A real story: the swapped SDA and SCL
A reader in this course's community wired their BME280 correctly in every single respect except one, SDA and SCL were quietly swapped, an easy mistake given how similarly the two pins are often labeled on budget breakout boards. The I2C scan found absolutely nothing at all, a strong, unmistakable signal something fundamental was wrong somewhere. Swapping the two wires resolved it instantly, a good reminder that this specific pair of pins is always worth double-checking carefully whenever a BME280 stubbornly refuses to appear on the bus.
Why this lesson feels like a genuine milestone
Everything since Lesson 1 has been quietly building toward this exact moment, a genuinely useful, working sensor you built entirely yourself rather than simply bought ready-made off a shelf. That distinction matters a great deal, understanding every single wire and every line of YAML behind this reading is a fundamentally different kind of ownership than merely unboxing a certified product.
Comparing accuracy: BME280 vs a certified Zigbee sensor
A BME280's accuracy is genuinely comparable to most certified consumer temperature sensors, typically within about half a degree, entirely sufficient for the home comfort automations built later in this course. Scientific-grade precision was never truly the goal here, reliable, genuinely good-enough data for practical automation always was.
Adding pressure as a bonus reading
The BME280's pressure reading is a genuine bonus most comparable Zigbee sensors don't offer at all, potentially useful later for weather-related automations, a steadily falling pressure trend can often hint at incoming rain, well beyond this particular module's immediate scope but certainly worth knowing exists for later.
Update interval: choosing a sensible default
Set the update_interval to 60 seconds for now, a sensible default that balances responsiveness against unnecessary network chatter. Temperature and humidity in a typical room change slowly, a shorter interval rarely provides meaningfully more useful information for the automations this course builds in later modules.
Naming your I2C address correctly
Most BME280 breakout boards default to address 0x76, though some manufacturers ship 0x77 instead, usually documented on the seller's own product page or printed faintly on the board itself. If your sensor doesn't appear at 0x76, trying 0x77 next resolves the vast majority of these address mismatches without needing to inspect any documentation at all.
A closer look at friendly names for this sensor
Choosing "Office Temperature" over a generic default like "BME280 Temperature" pays off the moment you have several sensors scattered across different rooms, a dashboard full of room-specific names is considerably easier to scan at a glance than one full of generic component names that all look alike.
What happens during an OTA update, behind the scenes
During an OTA update, your device briefly pauses its normal operation, downloads the new firmware over WiFi, verifies it, and restarts into the new version, typically taking under a minute for a small configuration change like today's. Existing entities briefly show as unavailable during this window, entirely normal and expected, they return automatically once the restart completes.
If OTA fails and USB becomes necessary
Occasionally an OTA update fails partway through, usually due to a temporary WiFi hiccup rather than anything wrong with your configuration. Simply retrying the OTA update resolves this in most cases, and USB remains available as a fallback if OTA repeatedly fails for any reason.
Physical placement of your sensor
Avoid placing your BME280 directly in sunlight, near a heating vent, or right next to your ESP32's own board, which generates a small amount of heat during normal operation, all three can skew temperature readings away from the room's genuine ambient value. A few inches of separation from the board itself, and a location away from direct heat sources, gives considerably more representative readings.
Reading the compile log for sensor-specific warnings
Beyond outright errors, the compile log occasionally shows warnings, a deprecated setting name, for instance, that don't stop compilation but are worth reading anyway. Addressing warnings promptly, rather than ignoring them because compilation still succeeded, keeps your configuration considerably healthier as ESPHome itself evolves over time.
Extending this sensor to a second location later
Once this first sensor is genuinely working well, adding a second one elsewhere in your home is largely a matter of repeating today's steps with a new board and a new device name, the underlying YAML pattern barely changes. This reusability is a large part of what makes ESPHome genuinely worthwhile once you've climbed today's initial learning curve.
A quick note on humidity sensor drift
Humidity sensors, including the BME280's, can drift slightly over months or years of continuous operation, a normal characteristic of this sensor type rather than a defect. If your humidity reading seems consistently off compared to a known reference, a small offset can be applied in YAML later, a detail beyond today's scope but worth knowing exists for the future.
Comparing this lesson's pace to Lesson 5's
Lesson 5 was entirely conceptual, no wiring, no new hardware. This lesson is the opposite, genuinely hands-on from the very first paragraph, wiring, YAML editing, compiling, and troubleshooting all in one sitting. That contrast is deliberate, understanding first, then building, mirrors this course's approach since Module 1.
Why a breadboard beats permanent wiring for now
Keeping this sensor on a breadboard rather than soldering it permanently means you can easily adjust wiring, swap components, or reuse the same breadboard for Lesson 7's button and LED project without needing a second set of hardware. Permanent installation, if you ever want it, is a project for well beyond this module, once you're confident the design genuinely works as intended.
What "done" looks like for this lesson
You're done once all three entities, temperature, humidity, and pressure, show plausible values in Home Assistant, the device's log shows a clean, repeating reading cycle with no errors, and the sensor's details are recorded in your notebook. Nothing more is required before moving on to Lesson 7.
Common questions about this first sensor
Readers often ask whether the BME280 needs any special power supply, it doesn't, your ESP32's own 3.3V pin supplies more than enough current for this sensor. Others ask if the pressure reading is reliable indoors, it is, indoor pressure readings track outdoor atmospheric pressure closely since most homes aren't airtight.
Keeping your wiring documented with a photo
Taking a quick photo of your breadboard wiring before moving on is a genuinely useful supplement to the written notes in your notebook, a picture makes it considerably easier to recreate or troubleshoot the exact same wiring months later than a text description alone, especially once you have several similar-looking projects going at once.
Co dalej: what's next
Lesson 7 shifts from reading the world, sensors, to interacting with it, a button, a reed switch, and an LED, your first taste of inputs and outputs working together on the same board.
A brief word on sensor lifespan
A BME280, kept in a reasonable indoor environment away from moisture and extreme heat, genuinely tends to last for many years of continuous, reliable operation without any meaningful degradation whatsoever. Unlike a battery-powered Zigbee sensor, there's no battery to eventually replace here, only the ESP32 board's own steady power supply to keep connected, one genuinely fewer long-term maintenance item to track carefully in your notebook going forward.
Revisiting your shopping list from Lesson 2
If you're following this module's minimal kit from Lesson 2 exactly as written, this sensor completes the "temperature and humidity" portion of your shopping list entirely and satisfyingly, the remaining button, LED, and resistors from that very same list carry directly forward into Lesson 7's work without needing to buy anything new at all.