Build Your Own Sensors with ESPHome and MQTT: A Home Assistant Guide.
Build custom smart home hardware with ESP32: SCD40/BME280 air quality (CO2, temperature, humidity, pressure) monitor, Bluetooth proxy, Mosquitto MQTT broker, and native API architecture.
Build Your Own Sensors with ESPHome and MQTT: A Home Assistant Guide
Series: Smart Home with Home Assistant — Part 5 of 10 Level: Intermediate Reading time: About 25 minutes Last verified: November 18, 2026 (Home Assistant 2026.11.2, ESPHome 2026.10.2)
In Part 4, we looked at which protocols off-the-shelf devices use. But sometimes the device you need simply doesn't exist, or doesn't work the way you want. Maybe you want to measure the CO2 level in your living room, track your boiler's fault light, or collect data from Bluetooth thermometers at the far end of the house.
That's where ESPHome comes in. With an ESP32 board that costs a few dollars, a sensor, and a single YAML file, you can build your own device that runs entirely locally, doesn't depend on any cloud, and is added to Home Assistant automatically, without writing a single line of C++.
In this part we will:
- Understand what ESPHome is and why it's so popular
- Install the ESPHome Device Builder
- Project 1: Build an air quality sensor with an ESP32 that measures CO2, temperature, humidity, and pressure
- Project 2: Set up a Bluetooth proxy that spreads Bluetooth coverage across the whole house
- Understand the difference between ESPHome's native API and MQTT
- Set up the Mosquitto MQTT broker securely
- Establish security and maintenance rules for ESPHome and MQTT devices
What Is ESPHome?#
ESPHome is an open-source system that builds custom firmware for microcontrollers such as the ESP32, ESP8266, BK72xx, and RP2040 from simple yet powerful configuration files, and lets you control them remotely through home automation systems (GitHub — esphome).
Here's how it works: you describe what your device should do in a YAML file, such as which sensor is connected to which pin and how often to measure. ESPHome reads that description and builds firmware tailored to your device (ESPHome — Get started).
ESPHome lives under the same roof as Home Assistant: it's owned and governed by the Open Home Foundation (Home Assistant Contributors). That's why the integration between the two projects is so tight.
Why ESPHome?
- Hardware without coding: There are ready-made components for hundreds of sensors, displays, relays, and LEDs. Adding a sensor is often just 5–10 lines of YAML.
- Fully local: The device talks directly to Home Assistant on your home network. No cloud account, app, or internet connection required.
- Instant updates: Home Assistant keeps a persistent connection to ESPHome devices. Sensor values are sent the moment they change, without waiting to be polled (Home Assistant — ESPHome).
- Over-the-air updates: The first install happens over USB; every update after that can be wireless (OTA) (ESPHome — Get started).
- Freeing existing devices: Many commercial smart plugs and switches are ESP-based. The ESPHome Devices repository offers ready-made configuration templates and setup guides for devices that can run ESPHome (ESPHome Devices).
What You'll Need#
A starter kit for the projects in this part:
| Item | Description | Note |
|---|---|---|
| ESP32 development board | ESP32-DevKitC or similar | Choose one with a USB port |
| Data-capable USB cable | To connect the board to your computer | Some cheap cables only charge and can't carry data |
| Sensirion SCD40 / SCD41 | CO2, temperature, and humidity sensor (I²C) | A true NDIR-based CO2 sensor |
| Bosch BME280 | Temperature, humidity, and pressure sensor (I²C) | Don't confuse it with the BMP280, which doesn't measure humidity |
| Breadboard and jumper wires | For prototyping | Soldering is recommended for permanent builds |
| 5 V USB power adapter | For power in a permanent install | A quality adapter matters for stability |
Buying tip: True CO2 sensors like the SCD40/SCD41 cost more. Some very cheap "CO2" sensors actually measure only volatile organic compounds (VOCs) and "estimate" a CO2 value, so look for "NDIR" or "photoacoustic" in the product description.
Step 1: Install the ESPHome Device Builder#
The ESPHome Device Builder is the web interface where you create, edit, and install ESPHome configurations (ESPHome — Get started).
On Home Assistant OS
- Go to Settings > Apps > Install app.
- Find ESPHome Device Builder and click it.
- Click Install, then Start, then Open Web UI.
If it isn't listed, open the ⋮ menu in the top right, choose Repositories, and add https://github.com/esphome/home-assistant-addon (ESPHome — Installing).
Under Home Assistant, configuration files are stored in /config/esphome/. For example, a device called "Living Room" lives in /config/esphome/living-room.yaml (ESPHome — Get started). This folder is included in Home Assistant backups, which matters, because there's no way to recover lost configuration files from the device (ESPHome — FAQ).
On Docker (Container installations)
If you use Container, you can run ESPHome as a separate container. The official example command (ESPHome — Installing):
docker run --rm --net=host -v "${PWD}":/config -it ghcr.io/esphome/esphome
The dashboard opens at http://localhost:6052. --net=host is needed for mDNS. Docker Desktop has no host networking, so use -p 6052:6052 there instead; without mDNS, it can only reach devices with a fixed address (ESPHome — Installing).
For permanent use, you can add a service like this to the compose.yaml from Part 2:
esphome:
container_name: esphome
image: "ghcr.io/esphome/esphome:stable"
volumes:
- /opt/esphome/config:/config
restart: unless-stopped
network_mode: host
Step 2: Create Your First Device#
- Open the Device Builder and click Create device.
- Choose one of three options (ESPHome — Get started):
- New Device Setup: The wizard guides you through platform selection, board configuration, and Wi-Fi setup. Choose this if you're not sure.
- Import from File: Upload an existing
.yamlfile. - Empty Configuration: A blank file for writing from scratch or pasting from devices.esphome.io.
- If you didn't enter Wi-Fi credentials in the wizard, add them to the configuration. Without them, the device can't reach your network, talk to Home Assistant, or accept wireless updates (ESPHome — Get started).
Keep secrets separate: secrets.yaml
Instead of writing your Wi-Fi password, API encryption key, and OTA password directly in the device configuration, keep them in secrets.yaml and reference them with !secret. That way you won't expose passwords when sharing configuration files somewhere like GitHub. The official API documentation shows this approach for the encryption key (ESPHome — Native API).
You can edit this file with the Secrets button in the top right of the Device Builder:
# secrets.yaml
wifi_ssid: "HomeNetwork"
wifi_password: "a-very-strong-wifi-password"
api_key_living_air: "PUT-A-32-BYTE-BASE64-KEY-HERE"
ota_password_living_air: "another-strong-password"
Security rule: Never add
secrets.yamlto a Git repository. If you keep your configurations in version control, list this file in.gitignore.
Project 1: Living Room Air Quality Sensor (CO2 + Temperature + Humidity + Pressure)#
Indoor air quality is one of the most overlooked health factors. When CO2 rises in a closed room, people can experience headaches, fatigue, and poor concentration. With this project, you'll measure CO2 in your living room, light an LED on the device when it passes a threshold, and be able to trigger automations in Home Assistant.
Wiring diagram
Both sensors use the I²C protocol. The beauty of I²C is that multiple sensors can share the same two data lines. Each sensor has its own address: the SCD4x defaults to 0x62 (ESPHome — SCD4X), and the BME280 defaults to 0x77, with 0x76 as the other possible address (ESPHome — BME280).
The I²C pins commonly used on ESP32-DevKitC boards are GPIO21 (SDA) and GPIO22 (SCL). Always check your board's pinout.
ESP32-DevKitC SCD40/41 BME280
───────────── ──────── ──────
3V3 ────────────────── VDD ────────────── VIN
GND ────────────────── GND ────────────── GND
GPIO21 (SDA) ────────── SDA ────────────── SDA
GPIO22 (SCL) ────────── SCL ────────────── SCL
GPIO2 ──── [LED + 220Ω resistor] ──── GND (warning LED)
Watch out: Connect the sensors to the 3.3 V pin rather than 5 V, but always check the supply range of your specific sensor module. Some modules have a voltage regulator and some don't.
The full configuration file
The configuration below combines the typical base structure generated by the ESPHome wizard with our sensors:
# /config/esphome/living-air.yaml
esphome:
name: living-air
friendly_name: Living room air quality
area: Living room
esp32:
board: esp32dev
framework:
type: esp-idf
# Logs over the serial port
logger:
# Encrypted native API for Home Assistant
api:
encryption:
key: !secret api_key_living_air
# Over-the-air updates
ota:
- platform: esphome
password: !secret ota_password_living_air
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Opens its own access point if it can't join Wi-Fi
ap:
ssid: "Living-Air-Fallback"
captive_portal:
# I2C bus
i2c:
sda: GPIO21
scl: GPIO22
scan: true
sensor:
# CO2, temperature, and humidity
- platform: scd4x
id: scd_sensor
co2:
name: "CO2"
id: co2_ppm
temperature:
name: "Temperature"
humidity:
name: "Humidity"
update_interval: 60s
# Pressure (we could add the BME280's temperature and humidity too)
- platform: bme280_i2c
address: 0x76
pressure:
name: "Air pressure"
update_interval: 60s
# Wi-Fi signal strength (very useful for maintenance)
- platform: wifi_signal
name: "Wi-Fi signal"
update_interval: 120s
entity_category: diagnostic
# Warning LED
output:
- platform: gpio
pin: GPIO2
id: warning_led_output
light:
- platform: binary
name: "CO2 warning LED"
id: warning_led
output: warning_led_output
# Local automation: LED turns on when CO2 exceeds 1200 ppm
interval:
- interval: 30s
then:
- if:
condition:
sensor.in_range:
id: co2_ppm
above: 1200
then:
- light.turn_on: warning_led
else:
- light.turn_off: warning_led
Line-by-line explanation
The esphome block:
nameis the device's network name. Use lowercase and hyphens. The device can be reached atliving-air.local(ESPHome — Get started).areasets which Home Assistant area the device is assigned to (ESPHome — Core configuration). Make sure it matches the area name you created in Part 3.friendly_nameis the device name shown in Home Assistant.
Why are the entity names so short? Notice we named the sensors just "CO2," "Temperature," and "Humidity" instead of "Living Room CO2." Under the new naming system from Part 3, you name each thing only for what it is, and Home Assistant adds the context (device and area names) itself (Home Assistant Blog — Naming things).
framework: esp-idf: The ESP-IDF framework uses less memory than Arduino, which is why the official Bluetooth proxy documentation recommends esp-idf (ESPHome — Bluetooth Proxy).
api and encryption: ESPHome's native API uses a custom TCP protocol based on protocol buffers that talks directly to Home Assistant. encryption.key is a 32-byte base64-encoded string (ESPHome — Native API). The ESPHome API page includes a tool that generates a random key in your browser for you to copy. On the Home Assistant side, the old password method is deprecated in favor of this encryption key (Home Assistant — ESPHome).
scd4x settings: The SCD4x's default update interval is 60 seconds. Two more settings matter (ESPHome — SCD4X):
temperature_offset: Compensates for the sensor's self-heating and nearby components; defaults to 4 °C. If the sensor's temperature differs from a thermometer you trust, adjust this value.automatic_self_calibration: Automatic self-calibration, enabled by default. It assumes the sensor periodically sees clean outdoor-level air, so it can miscalibrate in a room that's never ventilated.
Local automation (interval): The CO2 warning LED runs on the device itself without needing Home Assistant at all. Even if Home Assistant is down or Wi-Fi drops, the LED still turns on and off correctly. Running critical functions on the device is one of ESPHome's greatest strengths.
Step 3: First install
- Connect the ESP32 to your computer with a data-capable USB cable.
- In the Device Builder, click Install on the device card. ESPHome compiles and installs the configuration (ESPHome — Get started).
- The first build can take a few minutes. Later builds are much faster thanks to caching.
The first install must happen over USB; every update after that can be wireless (ESPHome — Get started).
Step 4: Add it to Home Assistant
Once the configuration is installed and the device has joined Wi-Fi, Home Assistant discovers it automatically and offers to set it up, as long as your network allows mDNS. If not, go to Settings > Devices & services > Add integration, search for ESPHome, and enter the device's host name (living-air.local) or IP address (ESPHome — Get started). Discovery can take up to 5 minutes (ESPHome — Native API).
During setup, Home Assistant asks for the encryption key (Noise PSK). Enter the api_key_living_air value from secrets.yaml (Home Assistant — ESPHome).
Example automation in Home Assistant
Once the device is added, here's an automation that sends a phone notification when CO2 stays high:
alias: "Living room - High CO2 alert"
description: "Sends a notification if CO2 stays above 1200 ppm for 10 minutes."
triggers:
- trigger: numeric_state
entity_id: sensor.living_room_air_quality_co2
above: 1200
for:
minutes: 10
conditions:
- condition: numeric_state
entity_id: zone.home
above: 0
actions:
- action: notify.mobile_app_my_phone
data:
title: "Time to ventilate the living room"
message: >
CO2 is at {{ states('sensor.living_room_air_quality_co2') }} ppm.
Consider opening a window for a few minutes.
mode: single
Note: Entity IDs (
sensor.living_room_air_quality_co2) and the notification service name (notify.mobile_app_my_phone) will differ in your setup. If you pick entities in the visual editor, Home Assistant fills in the correct IDs for you. The condition here only sends the notification when the number of people in the home zone is above zero, that is, when at least one person is home. As covered in Part 3, thezone.homestate is the number of people at home. We'll cover automations in detail in Part 6.
Monitoring several rooms with one ESP32: Sub-devices
If one ESP32 has sensors running to different rooms, ESPHome's sub-device feature lets each room appear as a separate device in Home Assistant. This feature arrived in ESPHome 2025.7 (ESPHome Blog), and the Home Assistant 2026.11 child-device support we mentioned in Part 3 includes ESPHome (Home Assistant Blog — Naming things).
esphome:
name: floor-sensors
areas:
- id: living_room_area
name: "Living room"
- id: bedroom_area
name: "Bedroom"
devices:
- id: living_room_sensor
name: "Living room sensor"
area_id: living_room_area
# relation: child # Required from ESPHome 2026.11 (see note below)
- id: bedroom_sensor
name: "Bedroom sensor"
area_id: bedroom_area
# relation: child
sensor:
- platform: dht
pin: GPIO4
temperature:
name: "Temperature"
device_id: living_room_sensor
humidity:
name: "Humidity"
device_id: living_room_sensor
- platform: dht
pin: GPIO5
temperature:
name: "Temperature"
device_id: bedroom_sensor
humidity:
name: "Humidity"
device_id: bedroom_sensor
This structure is based on the official ESPHome example (ESPHome — Core configuration).
ESPHome 2026.11 warning: ESPHome 2026.11, in beta at the time of writing, makes a
relation:field required on every entry underesphome: devices:. This is listed in the release notes' upgrade checklist. Userelation: childfor a logical part of this node andrelation: viafor a separate physical device reached through this node (ESPHome 2026.11 beta). Uncomment those lines when you move to 2026.11.
Project 2: Cover the Whole House with a Bluetooth Proxy#
There are lots of cheap Bluetooth Low Energy (BLE) sensors: thermometers, hygrometers, plant sensors, smart scales. The problem is that Bluetooth range is short, and your Home Assistant server is probably sitting in one corner of the house.
ESPHome's bluetooth_proxy component uses ESPHome devices to extend Home Assistant's Bluetooth reach. Home Assistant's Bluetooth integration aggregates ESPHome proxies with any USB Bluetooth adapters, and device integrations like BTHome receive their data through it. The component supports BLE devices only (ESPHome — Bluetooth Proxy).
The simplest configuration
Add these lines to any ESP32 configuration (ESPHome — Bluetooth Proxy):
esp32_ble_tracker:
bluetooth_proxy:
active: true
active: true enables active connections, which let Home Assistant connect to BLE devices to read and write data. It's on by default on the ESP32 (ESPHome — Bluetooth Proxy).
Connection slots
| Platform | Default slots | Limit and guidance |
|---|---|---|
| ESP32 | 3 | Maximum 9; staying at 5 or below is recommended to avoid stability and memory issues. Ethernet-based proxies can generally handle 4 reliably |
| RP2040 / RP2350 | 3 | Maximum 3 |
| BK72xx and LN882x | Not supported | Advertisement-only |
Devices that stay connected occupy a slot permanently. Devices that connect briefly and disconnect free it up again. Passive sensors that only broadcast their data don't use slots at all (ESPHome — Bluetooth Proxy).
Hardware and placement tips
The official documentation recommends (ESPHome — Bluetooth Proxy):
- Use an Ethernet-connected board. This frees the ESP32's radio from Wi-Fi traffic and improves Bluetooth performance. A model with an external antenna does even better; the docs give the Olimex ESP32-PoE-ISO-EA over the ESP32-PoE-ISO as an example.
- Keep it away from network gear. Don't put the proxy in a rack or next to a router or switch. Electromagnetic interference degrades Bluetooth reception; keeping it at least 3 meters from such equipment is recommended.
- Place it near your Bluetooth devices. Put the proxy close to the devices it needs to interact with.
- Don't change the scan parameters. The defaults are recommended. Aggressive scanning can cause overheating on PoE-based proxies and Wi-Fi instability on Wi-Fi-based ones.
Scan mode: Auto, active, and passive
For ESPHome Bluetooth proxies running recent firmware, Home Assistant lets you choose how they scan for devices. The default and recommended mode is Auto: the proxy listens passively most of the time and briefly switches to active scanning when a device or integration needs more details. According to Home Assistant, this saves around 95 to 96 percent of scan-related battery drain on Bluetooth devices compared with continuous active scanning (Home Assistant — ESPHome).
Practical tip: Putting a Bluetooth proxy on every floor, or every two or three rooms, is the cheapest way to get uninterrupted data from Bluetooth sensors. You can also add
bluetooth_proxyto your air quality sensor so one device does both jobs. In a very busy Bluetooth environment, though, a separate Ethernet-connected proxy is more stable because of memory and radio sharing.
Native API or MQTT?#
ESPHome devices can talk to Home Assistant in two ways: the native API or MQTT. Understanding which to choose is one of the most important decisions in this part.
Advantages of the native API
The ESPHome documentation lists these advantages of the native API over MQTT (ESPHome — Native API):
- Much more efficient: Messages are encoded with protocol buffers. A binary sensor state message, for example, is about one tenth the size.
- One-click configuration: It can be added to Home Assistant in one click, without retained MQTT discovery messages.
- One less single point of failure: Each ESP is its own server. With MQTT, if the broker goes down, nothing can communicate.
- Stability: ESPHome has more control over the protocol.
- Low latency: Usually only a couple of milliseconds, too short for the eye to notice.
The same page stresses that MQTT is a great protocol and will never be removed (ESPHome — Native API).
When to use MQTT
MQTT makes sense when:
- Several systems need the same data: If Node-RED, Grafana, a database, or another home automation system will read the same sensor data, MQTT's publish-subscribe model is very handy.
- You use Zigbee2MQTT: Zigbee2MQTT, covered in Part 4, already requires an MQTT broker. Home Assistant's MQTT integration lists Zigbee2MQTT among the software with built-in MQTT discovery support (Home Assistant — MQTT).
- You have Tasmota or other MQTT-based devices.
- Devices are on a different network or at a remote site, and you want to manage the link through a single broker.
Our recommendation: Use the native API to connect your ESPHome devices to Home Assistant. Save MQTT for cases where you already need it, such as Zigbee2MQTT, and for scenarios where data has to be shared with several systems.
An important trap: The reboot timeout
If you enable MQTT on an ESPHome device but don't use the native API, remove the api: section or set reboot_timeout: 0s. Otherwise, the device will reboot every 15 minutes because no client has connected to the native API (ESPHome — MQTT). This is one of the most common causes of "my device keeps restarting" complaints.
The default timeout is 15 minutes. Only clients that complete authentication count; a port scan or a client with a stale encryption key, for example, doesn't prevent the reboot (ESPHome — Native API).
Setting Up the Mosquitto MQTT Broker#
If you'll use MQTT, you need a broker. Home Assistant's recommended setup is the Mosquitto MQTT broker app (Home Assistant — MQTT).
Installing on Home Assistant OS
- Go to Settings > Apps > Install app.
- Find the Mosquitto broker app and click it.
- Click Install.
After you start the app, Home Assistant usually discovers the MQTT integration automatically and suggests it on the Settings > Devices & services page.
Creating an MQTT user
The Mosquitto app can use Home Assistant users without any extra configuration. The official advice is to create a new MQTT user in the Home Assistant UI under Settings > People > Users, not on Mosquitto's configuration tab (Mosquitto app — DOCS).
Things to watch (Mosquitto app — DOCS):
- The username must not be
homeassistantoraddons; these are reserved. - If the option to create a user isn't visible, turn on Advanced mode in your Home Assistant profile.
- The app doesn't support anonymous logins. Every connection needs a username and password.
Security tip: Create a separate user for each MQTT client (Zigbee2MQTT, each ESPHome or Tasmota device, Node-RED). If one device's password leaks, you only need to revoke that user. Since these users won't log in to the Home Assistant UI, don't give them administrator rights, and turn on Local access only.
Ports and encryption
| Connection type | Port | Description |
|---|---|---|
| Unencrypted MQTT | 1883 | Default |
| Unencrypted WebSocket | 1884 | Default |
| Encrypted MQTT (TLS) | 8883 | When certificate and key files are provided |
| Encrypted WebSocket | 8884 | When certificate and key files are provided |
For TLS, place the certfile and keyfile in Home Assistant's ssl folder and set them in the app configuration. To disable the unencrypted ports entirely, leave them blank on the app page's network card (Mosquitto app — DOCS).
A realistic approach for home networks: If the broker is only reachable from your home network and isn't exposed to the internet, starting with port 1883 and strong passwords is enough for most homes. If you'll expose the broker, have a guest network, or connect devices from other locations, always use TLS (8883). Never forward the MQTT port on your router directly to the internet.
Access control lists (ACL)
For a higher level of security, you can use ACLs so each user can only access its own topics. According to the official documentation, this takes three steps (Mosquitto app — DOCS):
- Turn on customization in the app configuration:
customize:
active: true
folder: mosquitto
- Create
/share/mosquitto/acl.conf:
acl_file /share/mosquitto/accesscontrollist
- Define users and their permissions in
/share/mosquitto/accesscontrollist. For example, to restrict the Zigbee2MQTT user to its own topics:
user addons
topic readwrite #
user homeassistant
topic readwrite #
user zigbee2mqtt
topic readwrite zigbee2mqtt/#
topic readwrite homeassistant/#
The homeassistant and addons users need unrestricted read/write access to all topics; otherwise Home Assistant may run into problems (Mosquitto app — DOCS).
Note: The
zigbee2mqttuser permissions above are an example. Zigbee2MQTT needs to write tohomeassistant/topics for Home Assistant discovery. After tightening ACLs, always test that your devices still appear correctly.
Mosquitto on a Container installation
On Container, you need to add a configuration file to the Mosquitto service shown in Part 2. /opt/mosquitto/config/mosquitto.conf:
listener 1883
allow_anonymous false
password_file /mosquitto/config/passwd
persistence true
persistence_location /mosquitto/data/
log_dest stdout
To create users:
docker exec -it mosquitto mosquitto_passwd -c /mosquitto/config/passwd homeassistant_mqtt
docker exec -it mosquitto mosquitto_passwd /mosquitto/config/passwd zigbee2mqtt
docker restart mosquitto
The -c flag creates the file from scratch; don't use it for the second and later users, or the earlier users will be wiped.
Testing MQTT
To check that the broker is running and messages are flowing, you can subscribe to every topic from a terminal:
mosquitto_sub -h 192.168.1.10 -u test_user -P 'password' -t '#' -v
In Home Assistant, you can also subscribe to a topic and watch messages, or publish a test message, from Settings > Devices & services > MQTT > Configure.
Using ESPHome with MQTT (If You Need It)#
If you want an ESPHome device to send its data to MQTT as well, add an mqtt: section to its configuration (ESPHome — MQTT):
mqtt:
broker: 192.168.1.10
username: living_air
password: !secret mqtt_password_living_air
If you want to use the native API and MQTT together, you can turn off MQTT entity discovery so the same entities don't show up twice in Home Assistant. The ESPHome documentation shows this structure (ESPHome — MQTT):
api:
encryption:
key: !secret api_key_living_air
mqtt:
broker: 192.168.1.10
username: living_air
password: !secret mqtt_password_living_air
discovery: false # Don't announce MQTT entities to Home Assistant
discover_ip: true # Allow the device itself to be discovered
With this configuration, Home Assistant finds the device over MQTT but talks to it over the native API. That keeps features that only work over the native API, such as Bluetooth proxy and voice assistant, available, while other systems like Node-RED or Grafana can read the sensor data from MQTT (ESPHome — MQTT).
MQTT topic structure
By default, ESPHome prefixes all MQTT messages with the device name. A component's state topic follows the format <prefix>/<component_type>/<component_name>/state. When the device connects, it sends a retained online message to <prefix>/status, and if the connection drops, the broker publishes offline to the same topic (ESPHome — MQTT). The Home Assistant discovery prefix defaults to homeassistant (ESPHome — MQTT).
Security and Maintenance Rules#
The devices you build are part of your network. They deserve as much care as commercial devices, if not more.
For ESPHome devices
- Enable API encryption on every device. The old password method is deprecated and will be removed in a future release (Home Assistant — ESPHome).
- Give each device a different encryption key and OTA password.
- Only enable "Allow the device to perform Home Assistant actions" on devices you trust. When enabled, ESPHome devices can call services and send events in Home Assistant. It's off by default for newly added devices (Home Assistant — ESPHome).
- Keep device names unique. Two devices with the same name can cause connection issues, failed discovery, and unexpected behavior (Home Assistant — ESPHome).
- Back up your configuration files. Lost configurations can't be recovered from the device (ESPHome — FAQ). On Home Assistant OS, the
/config/esphome/folder is included in Home Assistant backups. Keeping them in a private Git repository, excludingsecrets.yaml, is a good extra habit. - Use a fixed IP if you can't rely on mDNS.
manual_ipassigns the device a static IP, anduse_addressoverrides the address used to connect to it (ESPHome — FAQ).
For MQTT
- Anonymous access must be off. It's already off in Home Assistant's Mosquitto app (Mosquitto app — DOCS).
- Give every client its own user.
- Don't expose the MQTT port to the internet.
- If you need remote access, use TLS (8883) and preferably a VPN. We'll cover this in Part 9.
Update strategy
- The ESPHome Device Builder shows when your devices can be updated after a new ESPHome release. Rather than updating every device at once, update a test device first.
- Before major version changes, read the upgrade checklist in the release notes. For example, ESPHome 2026.11 makes the
relation:field required for sub-devices and raises the minimum ESP-IDF framework version to 5.1 (ESPHome 2026.11 beta). - "If it works, don't touch it" applies to ESPHome devices too. If you don't need a new feature or a security fix, you don't have to install every release right away.
Troubleshooting#
| Problem | Likely cause | Fix |
|---|---|---|
| Computer doesn't see the ESP32 | Charge-only USB cable or missing driver | Use a data cable; install the CP210x or CH340 driver |
| I²C sensor not found | Wrong pin, wrong address, loose wire | Check the addresses found in the logs with i2c: scan: true; try 0x76 or 0x77 for the BME280 |
| Device reboots every 15 minutes | MQTT in use but no client connected to the API | Remove the api: section or add reboot_timeout: 0s (ESPHome — MQTT) |
| Home Assistant doesn't discover the device | mDNS is blocked (VLAN, guest network) | Add the integration manually by IP; use manual_ip if needed |
| CO2 reading is always very low or drifts | Auto-calibration never saw fresh air | Run the sensor in fresh air for a few minutes, or review the automatic_self_calibration setting |
| Temperature reads higher than actual | Self-heating of the ESP32 and sensor | Move the sensor away from the board; adjust temperature_offset |
| Bluetooth proxy is unstable | Too many active connections, radio shared with Wi-Fi | Keep slots at 5 or fewer; use an Ethernet-connected board |
| Zigbee2MQTT can't connect to the broker | Wrong username/password or ACL restriction | Check Mosquitto's logs; verify the topic permissions in the ACL |
Frequently Asked Questions#
Do I need to know how to program to use ESPHome?
No. Most projects can be completed with YAML configuration alone. For advanced needs you can write small C++ snippets called lambdas, but you don't need them to get started.
Should I buy an ESP8266 or an ESP32? We recommend the ESP32 for new projects. It offers Bluetooth, more memory, and more pins. Features like the Bluetooth proxy require an ESP32 (ESPHome — Bluetooth Proxy).
Can I install ESPHome on a smart plug I bought? Often yes, if the device is ESP-based. Search for your model in the ESPHome Devices repository. Some models require opening the device and making a serial connection to flash the firmware. Always unplug mains-powered devices before opening them.
Will my ESPHome device work without the internet? Yes. ESPHome devices talk to Home Assistant over your local network, and on-device local automations keep running even without Home Assistant.
Should I install Mosquitto only for Zigbee2MQTT? If you use Zigbee2MQTT, you need an MQTT broker. For ESPHome devices, the native API is enough; add MQTT only if the data needs to be shared with other systems too.
Can I use the native API and MQTT on the same device?
Yes. The ESPHome documentation shows that both can be enabled together. In that case, it makes sense to turn off MQTT entity discovery with mqtt.discovery: false (ESPHome — MQTT).
What's Next#
Now both off-the-shelf and homemade devices are in Home Assistant. In Part 6, we'll bring them to life with automations:
- Every type of trigger, condition, and action
- Scripts, scenes, and helpers
- Ready-made automations with blueprints
- Debugging with the target exclusions and "Triggered by" filter introduced in 2026.11
- Real-world automation scenarios
Complete series overview for building an autonomous, privacy-first smart home: