Projects / ESPHome sensors in Home Assistant

ESPHome sensors in Home Assistant

Beginner1 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. ESP32

    Install ESPHome

    Use the add-on in Home Assistant or pip install esphome.

  2. ESP32

    Create the device

    Make a new device named living-room and paste the YAML above.

  3. ESP32

    Set your Wi-Fi secrets

    Add wifi_ssid and wifi_password to secrets.yaml.

  4. ESP32USBUSB

    Flash by USB

    Connect the ESP32 and press Install, choosing the serial port.

  5. ESP32

    Adopt it

    Home Assistant discovers the device. Click Configure to add it.

  6. ESP32motion

    Check readings

    Temperature, humidity, pressure and motion appear.

  7. ESP32motion

    Make an automation

    Turn on a light on motion between sunset and sunrise.

  8. ESP32

    Update over the air

    Change update_interval and install wirelessly.

In short

How do you build an ESPHome sensors in Home Assistant?

Write a YAML file, flash an ESP32 and a new sensor appears in Home Assistant with no code. You need ESP32 DevKit V1, BME280 Environmental Sensor, PIR Motion Sensor HC-SR501, 5 V 2 A USB adapter, USB A to micro-USB cable (data) and Jumper wires male to male (40 pcs, 20 cm). It takes 8 steps and about 60 minutes.

Level
Beginner
Time
About 60 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
BME280 VIN and GNDESP32 3V3 and GNDSensor supply
BME280 SDAESP32 GPIO 21I2C data
BME280 SCLESP32 GPIO 22I2C clock
PIR VCC and GNDESP32 VIN (5 V) and GNDThe HC-SR501 needs 5 V
PIR OUTESP32 GPIO 27Motion signal at 3.3 V
PowerUSB adapter into the ESP32Flash by USB the first time

Code

ESPHome, either the Home Assistant add-on or the command line tool, version 2024.6 or newer for the ota: platform syntax shown. Put wifi_ssid and wifi_password in the secrets file, and never paste them into a shared file. The BME280 address is 0x76 on most modules and 0x77 on some.

# Save as living-room.yaml in the ESPHome dashboard
esphome:
  name: living-room

esp32:
  board: esp32dev
  framework:
    type: arduino

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

api:

ota:
  - platform: esphome

logger:

i2c:
  sda: 21
  scl: 22

sensor:
  - platform: bme280_i2c
    address: 0x76
    temperature:
      name: "Living room temperature"
    humidity:
      name: "Living room humidity"
    pressure:
      name: "Living room pressure"
    update_interval: 60s

binary_sensor:
  - platform: gpio
    pin: GPIO27
    name: "Living room motion"
    device_class: motion

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Device onlineShows connected in the ESPHome dashboard
TemperatureWithin 1 to 2 °C of a thermometer
Wave a hand at the PIRMotion shows detected, then clear after the PIR's delay
OTA updateWorks without the USB cable

If it does not work

BME280 not found

Try address 0x77 and check SDA and SCL wires.

Device does not appear in Home Assistant

It is on a different network or the API is blocked. Check Wi-Fi and the logs.

PIR always on

Its sensitivity and time pots are set high. Turn them down and give it a minute to settle.

Compile error

ESPHome version differs. Update it and check the ota syntax.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the ESPHome sensors in Home Assistant?

ESP32 DevKit V1, BME280 Environmental Sensor, PIR Motion Sensor HC-SR501, 5 V 2 A USB adapter, USB A to micro-USB cable (data) and Jumper wires male to male (40 pcs, 20 cm).

How long does the ESPHome sensors in Home Assistant take to build?

About 60 minutes for a beginner maker, in 8 steps.

How do I know the ESPHome sensors in Home Assistant works?

Device online: Shows connected in the ESPHome dashboard. Temperature: Within 1 to 2 °C of a thermometer. Wave a hand at the PIR: Motion shows detected, then clear after the PIR's delay.

BME280 not found: what should I check?

Try address 0x77 and check SDA and SCL wires.

Device does not appear in Home Assistant: what should I check?

It is on a different network or the API is blocked. Check Wi-Fi and the logs.

PIR always on: what should I check?

Its sensitivity and time pots are set high. Turn them down and give it a minute to settle.

Compile error: what should I check?

ESPHome version differs. Update it and check the ota syntax.