Automation intermediate ⏱ 60 minutes

ESPHome: DIY Sensors and Smart Devices

Create custom sensors and devices with ESP32/ESP8266. YAML-based configuration for Home Assistant.

By homelabbing.io • 2025-12-17
#esphome#esp32#diy#sensors#home-assistant

ESPHome is a revolutionary platform that transforms affordable ESP32 and ESP8266 microcontrollers into powerful smart home devices using simple YAML configuration files. No programming required - just describe what you want, and ESPHome generates optimized firmware automatically.

In this comprehensive guide, you’ll learn how to set up ESPHome, flash your first device, create custom sensors, integrate with Home Assistant, and build a variety of practical IoT devices from temperature sensors to smart LED controllers.

Why ESPHome?

ESPHome has become the go-to solution for DIY smart home enthusiasts:

No Programming Required: Define your device in YAML. ESPHome handles all the C++ code generation, compilation, and optimization automatically.

Powerful Yet Simple: Access advanced features like deep sleep, OTA updates, captive portals, and web servers with just a few lines of configuration.

Native Home Assistant Integration: Devices appear automatically in Home Assistant with all entities configured and ready to use. No MQTT broker required.

Extensive Component Library: Over 200 supported components including sensors, displays, motors, LEDs, switches, and communication protocols.

Cost Effective: ESP32 boards cost 3-8 USD, ESP8266 as low as 2 USD. Build custom sensors for a fraction of commercial device prices.

Local First: All communication happens on your local network. Optional MQTT support for integration with other platforms.

Active Development: Regular updates, new component support, and an engaged community solving real-world problems.

Prerequisites

Before starting, ensure you have:

  • A Linux server or VM with Docker and Docker Compose installed
  • ESP32 or ESP8266 development board (recommendations below)
  • USB cable for flashing (USB-C or Micro-USB depending on board)
  • Basic understanding of electronics (helpful but not required)
  • Soldering iron (optional, for permanent installations)
  • Home Assistant installation (optional but recommended)

ESP Hardware Recommendations

ESP32 DevKit v1

  • Chip: ESP32-WROOM-32
  • Price: 5-8 USD
  • Features: WiFi, Bluetooth, 30+ GPIO pins
  • Best for: Most projects, excellent compatibility

ESP32-C3 SuperMini

  • Chip: ESP32-C3
  • Price: 2-4 USD
  • Features: Tiny size, USB-C, RISC-V processor
  • Best for: Space-constrained projects

ESP32-S2 Mini

  • Chip: ESP32-S2
  • Price: 3-5 USD
  • Features: Native USB, WiFi only (no Bluetooth)
  • Best for: USB HID devices, lower power

TTGO T-Display ESP32

  • Chip: ESP32
  • Price: 10-15 USD
  • Features: Built-in 1.14” color display
  • Best for: Projects needing visual feedback

ESP8266 Boards

Wemos D1 Mini

  • Chip: ESP8266
  • Price: 2-4 USD
  • Features: Compact, breadboard-friendly
  • Best for: Simple sensors, legacy projects

NodeMCU v3

  • Chip: ESP8266
  • Price: 3-5 USD
  • Features: More GPIO pins, larger form factor
  • Best for: Projects needing more pins

Why ESP32 over ESP8266?

ESP32 advantages:

  • More GPIO pins (30+ vs 11)
  • Faster processor (240 MHz vs 80 MHz)
  • More RAM (520 KB vs 80 KB)
  • Bluetooth support
  • Better power management
  • Hall sensor, temperature sensor built-in

Use ESP8266 when:

  • Budget is extremely tight
  • Project is very simple (single sensor)
  • Physical size is critical

Additional Hardware

For temperature/humidity sensing:

  • DHT22 sensor - 3-5 USD (accurate, popular)
  • BME280 sensor - 5-8 USD (temp, humidity, pressure)
  • DS18B20 sensor - 2-4 USD (waterproof option available)

For distance/presence:

  • HC-SR04 ultrasonic - 1-2 USD
  • VL53L0X ToF sensor - 3-5 USD
  • LD2410 mmWave radar - 8-12 USD

For light/motion:

  • BH1750 light sensor - 1-2 USD
  • PIR motion sensor - 1-2 USD
  • APDS-9960 gesture sensor - 3-5 USD

For control:

  • Relay modules - 1-3 USD each
  • WS2812B LED strips - 5-15 USD per meter
  • Servo motors - 2-5 USD

ESPHome Installation

Create directory structure:

mkdir -p /opt/esphome/config
cd /opt/esphome

Create docker-compose.yml:

version: '3.8'

services:
  esphome:
    container_name: esphome
    image: ghcr.io/esphome/esphome:latest
    restart: unless-stopped
    ports:
      - "6052:6052"
    volumes:
      - ./config:/config
      - /etc/localtime:/etc/localtime:ro
    environment:
      - TZ=America/New_York
    network_mode: host
    # Required for device discovery and flashing
    privileged: true

Start ESPHome:

docker-compose up -d

# View logs
docker-compose logs -f esphome

Access dashboard at http://YOUR-SERVER-IP:6052

Home Assistant Add-on (Alternative)

If running Home Assistant OS:

  1. Settings > Add-ons > Add-on Store
  2. Search “ESPHome”
  3. Click Install
  4. Start add-on
  5. Open Web UI

Standalone Installation (Advanced)

# Install Python 3.9+
sudo apt update
sudo apt install python3 python3-pip python3-venv

# Create virtual environment
python3 -m venv esphome-venv
source esphome-venv/bin/activate

# Install ESPHome
pip3 install esphome

# Run dashboard
esphome dashboard config/

Your First ESPHome Device

Creating a Basic Configuration

Let’s create a simple “Hello World” device that blinks an LED.

Via Web Dashboard:

  1. Open http://YOUR-SERVER-IP:6052
  2. Click ”+ New Device”
  3. Click “Continue”
  4. Enter device name: test-esp32
  5. Select device type: ESP32
  6. Enter WiFi credentials
  7. Click “Next”
  8. Click “Skip” (we’ll configure manually)

Via Manual Configuration:

Create config/test-esp32.yaml:

# Basic ESPHome configuration
esphome:
  name: test-esp32
  friendly_name: Test ESP32
  platform: ESP32
  board: esp32dev

# WiFi connection
wifi:
  ssid: "YOUR_WIFI_SSID"
  password: "YOUR_WIFI_PASSWORD"

  # Enable fallback hotspot (captive portal) if WiFi fails
  ap:
    ssid: "Test-ESP32 Fallback"
    password: "fallback123"

# Enable captive portal for WiFi configuration
captive_portal:

# Enable logging
logger:
  level: INFO

# Enable Home Assistant API
api:
  encryption:
    key: "GENERATED_KEY_HERE"

# Enable over-the-air updates
ota:
  password: "GENERATED_PASSWORD"

# Enable web server
web_server:
  port: 80

# Built-in LED (GPIO 2 on most ESP32 boards)
light:
  - platform: binary
    name: "Built-in LED"
    id: builtin_led
    output: builtin_led_output

output:
  - platform: gpio
    pin: GPIO2
    id: builtin_led_output

First Flash (USB)

Initial flash must be done via USB:

  1. Connect ESP32 to computer via USB
  2. In ESPHome dashboard, click device
  3. Click “Install”
  4. Select “Plug into this computer”
  5. Select USB port (e.g., /dev/ttyUSB0)
  6. Click “Install”
  7. Wait for compilation and upload (2-5 minutes)

Manual flashing (if web flash fails):

# Install esptool
pip3 install esptool

# Find device port
ls /dev/ttyUSB* /dev/ttyACM*

# Flash firmware
esptool.py --port /dev/ttyUSB0 write_flash 0x0 test-esp32.bin

# Monitor serial output
esptool.py --port /dev/ttyUSB0 monitor

Verify Connection

After flashing:

  1. Device reboots and connects to WiFi
  2. Check ESPHome dashboard - device shows “Online”
  3. Click “Visit” to open device web interface
  4. Toggle “Built-in LED” switch
  5. LED on ESP32 board should blink

Troubleshooting:

# View device logs in real-time
docker exec -it esphome esphome logs config/test-esp32.yaml

# Common issues:
# - Wrong WiFi credentials: Device creates fallback AP
# - Wrong board type: Won't boot properly
# - Wrong GPIO pin: LED won't light (check your board's pinout)

Common Sensor Configurations

Temperature and Humidity (DHT22)

Wiring:

  • VCC to 3.3V
  • GND to GND
  • DATA to GPIO4

Configuration:

sensor:
  - platform: dht
    pin: GPIO4
    model: DHT22
    temperature:
      name: "Living Room Temperature"
      id: living_room_temp
      accuracy_decimals: 1
      filters:
        - sliding_window_moving_average:
            window_size: 5
            send_every: 5
    humidity:
      name: "Living Room Humidity"
      id: living_room_humidity
      accuracy_decimals: 1
      filters:
        - sliding_window_moving_average:
            window_size: 5
            send_every: 5
    update_interval: 30s

Temperature/Humidity/Pressure (BME280)

Wiring (I2C):

  • VCC to 3.3V
  • GND to GND
  • SCL to GPIO22 (ESP32) or GPIO5 (ESP8266)
  • SDA to GPIO21 (ESP32) or GPIO4 (ESP8266)

Configuration:

i2c:
  sda: GPIO21
  scl: GPIO22
  scan: true

sensor:
  - platform: bme280
    temperature:
      name: "BME280 Temperature"
      oversampling: 16x
    pressure:
      name: "BME280 Pressure"
    humidity:
      name: "BME280 Humidity"
    address: 0x76
    update_interval: 60s

Motion Detection (PIR Sensor)

Wiring:

  • VCC to 5V (or 3.3V if sensor supports it)
  • GND to GND
  • OUT to GPIO5

Configuration:

binary_sensor:
  - platform: gpio
    pin: GPIO5
    name: "Living Room Motion"
    device_class: motion
    filters:
      - delayed_off: 10s  # Prevent rapid on/off

Distance Measurement (HC-SR04)

Wiring:

  • VCC to 5V
  • GND to GND
  • TRIG to GPIO12
  • ECHO to GPIO14

Configuration:

sensor:
  - platform: ultrasonic
    trigger_pin: GPIO12
    echo_pin: GPIO14
    name: "Garage Distance"
    update_interval: 2s
    timeout: 3m
    filters:
      - filter_out: nan
      - median:
          window_size: 5
          send_every: 2

Light Level (BH1750)

Wiring (I2C):

  • VCC to 3.3V
  • GND to GND
  • SCL to GPIO22
  • SDA to GPIO21

Configuration:

i2c:
  sda: GPIO21
  scl: GPIO22

sensor:
  - platform: bh1750
    name: "Living Room Illuminance"
    address: 0x23
    update_interval: 30s

Waterproof Temperature (DS18B20)

Wiring:

  • RED to 3.3V
  • BLACK to GND
  • YELLOW to GPIO4
  • 4.7k resistor between VCC and DATA

Configuration:

dallas:
  - pin: GPIO4

sensor:
  - platform: dallas
    address: 0x1234567890ABCDEF  # Replace with actual address
    name: "Pool Temperature"
    resolution: 12
    update_interval: 60s

Find device address:

# View logs while device boots
docker exec -it esphome esphome logs config/your-device.yaml

# Look for: "Found dallas device with address: 0x..."

Smart Switches and Relays

Basic Relay Control

Wiring:

  • Relay VCC to 5V
  • Relay GND to GND
  • Relay IN to GPIO16
  • Connect load through relay COM/NO

Configuration:

switch:
  - platform: gpio
    pin: GPIO16
    name: "Desk Lamp"
    id: desk_lamp
    icon: "mdi:lamp"

  - platform: restart
    name: "ESP32 Restart"

Smart Plug with Power Monitoring

Using HLW8012 chip (common in Sonoff S31):

sensor:
  - platform: hlw8012
    sel_pin: GPIO12
    cf_pin: GPIO4
    cf1_pin: GPIO5
    current:
      name: "Plug Current"
    voltage:
      name: "Plug Voltage"
    power:
      name: "Plug Power"
    energy:
      name: "Plug Energy"
    update_interval: 10s

switch:
  - platform: gpio
    pin: GPIO13
    name: "Plug Switch"
    id: relay

Multi-Gang Switch

Configuration:

switch:
  - platform: gpio
    pin: GPIO16
    name: "Light 1"
    id: light_1

  - platform: gpio
    pin: GPIO17
    name: "Light 2"
    id: light_2

  - platform: gpio
    pin: GPIO18
    name: "Light 3"
    id: light_3

  - platform: gpio
    pin: GPIO19
    name: "Light 4"
    id: light_4

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: true
    name: "Button 1"
    on_press:
      - switch.toggle: light_1

LED Controllers

Simple RGB LED Strip (WS2812B)

Wiring:

  • VCC to 5V power supply
  • GND to GND (ESP32 and power supply)
  • DATA to GPIO13

Configuration:

light:
  - platform: fastled_clockless
    chipset: WS2812B
    pin: GPIO13
    num_leds: 60
    rgb_order: GRB
    name: "LED Strip"
    id: led_strip
    effects:
      - addressable_rainbow:
          name: Rainbow
          speed: 10
          width: 50
      - addressable_color_wipe:
          name: Color Wipe
      - addressable_scan:
          name: Scanner
      - addressable_twinkle:
          name: Twinkle
      - addressable_fireworks:
          name: Fireworks

RGBW LED Controller

Configuration:

output:
  - platform: ledc
    pin: GPIO16
    id: red_output
  - platform: ledc
    pin: GPIO17
    id: green_output
  - platform: ledc
    pin: GPIO18
    id: blue_output
  - platform: ledc
    pin: GPIO19
    id: white_output

light:
  - platform: rgbw
    name: "Kitchen Light"
    red: red_output
    green: green_output
    blue: blue_output
    white: white_output
    effects:
      - random:
      - pulse:
      - strobe:

PWM Dimmable Light

Configuration:

output:
  - platform: ledc
    pin: GPIO16
    id: pwm_output
    frequency: 1000 Hz

light:
  - platform: monochromatic
    name: "Dimmable Light"
    output: pwm_output
    gamma_correct: 2.8
    default_transition_length: 1s

Advanced Features

Deep Sleep for Battery Devices

Extend battery life with deep sleep:

deep_sleep:
  run_duration: 10s
  sleep_duration: 10min
  id: deep_sleep_1

sensor:
  - platform: dht
    pin: GPIO4
    temperature:
      name: "Temperature"
    humidity:
      name: "Humidity"
    update_interval: 5s
    on_value:
      then:
        - deep_sleep.enter: deep_sleep_1

  - platform: adc
    pin: GPIO36
    name: "Battery Voltage"
    attenuation: 11db
    filters:
      - multiply: 2  # Voltage divider correction

Display Integration (SSD1306 OLED)

Wiring (I2C):

  • VCC to 3.3V
  • GND to GND
  • SCL to GPIO22
  • SDA to GPIO21

Configuration:

i2c:
  sda: GPIO21
  scl: GPIO22

font:
  - file: "fonts/Arial.ttf"
    id: arial_font
    size: 12

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3C
    lambda: |-
      it.printf(0, 0, id(arial_font), "Temperature:");
      it.printf(0, 15, id(arial_font), "%.1f°C", id(living_room_temp).state);
      it.printf(0, 30, id(arial_font), "Humidity:");
      it.printf(0, 45, id(arial_font), "%.1f%%", id(living_room_humidity).state);

Rotary Encoder Input

Configuration:

sensor:
  - platform: rotary_encoder
    name: "Volume"
    pin_a: GPIO25
    pin_b: GPIO26
    min_value: 0
    max_value: 100
    on_clockwise:
      - logger.log: "Turned clockwise"
    on_anticlockwise:
      - logger.log: "Turned counterclockwise"

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO27
      mode: INPUT_PULLUP
      inverted: true
    name: "Encoder Button"
    on_press:
      - logger.log: "Button pressed"

Bluetooth Proxy (ESP32 only)

Turn ESP32 into a Bluetooth proxy for Home Assistant:

esp32_ble_tracker:
  scan_parameters:
    interval: 1100ms
    window: 1100ms
    active: true

bluetooth_proxy:
  active: true

This extends Bluetooth range for devices like Xiaomi sensors, trackers, and BLE devices.

Voice Assistant Ready

microphone:
  - platform: i2s_audio
    id: mic
    adc_type: external
    i2s_din_pin: GPIO26
    pdm: false

speaker:
  - platform: i2s_audio
    id: speaker
    dac_type: external
    i2s_dout_pin: GPIO25

voice_assistant:
  microphone: mic
  speaker: speaker

Automations and Logic

Conditional Actions

binary_sensor:
  - platform: gpio
    pin: GPIO5
    name: "Motion"
    on_press:
      - if:
          condition:
            sensor.in_range:
              id: light_level
              below: 50
          then:
            - light.turn_on: room_light
          else:
            - logger.log: "Too bright, light not needed"

Timers and Delays

switch:
  - platform: gpio
    pin: GPIO16
    name: "Bathroom Fan"
    id: bathroom_fan
    on_turn_on:
      - delay: 15min
      - switch.turn_off: bathroom_fan

State Machines

globals:
  - id: motion_count
    type: int
    restore_value: no
    initial_value: '0'

binary_sensor:
  - platform: gpio
    pin: GPIO5
    name: "Motion"
    on_press:
      - lambda: |-
          id(motion_count) += 1;
          if (id(motion_count) > 3) {
            id(alarm_mode).turn_on();
          }

Time-Based Automation

time:
  - platform: homeassistant
    id: homeassistant_time
    on_time:
      - seconds: 0
        minutes: 0
        hours: 7
        days_of_week: MON-FRI
        then:
          - light.turn_on:
              id: bedroom_light
              brightness: 30%
              transition_length: 5min

Home Assistant Integration

Automatic Discovery

With api: enabled, devices auto-discover in Home Assistant:

  1. ESPHome device boots and connects
  2. Home Assistant detects new ESPHome device
  3. Notification appears: “New device discovered”
  4. Click “Configure”
  5. Enter encryption key from YAML
  6. All entities appear automatically

Entity Customization

sensor:
  - platform: dht
    pin: GPIO4
    temperature:
      name: "Living Room Temperature"
      device_class: temperature
      state_class: measurement
      unit_of_measurement: "°C"
      accuracy_decimals: 1
      icon: "mdi:thermometer"
      entity_category: diagnostic

Calling Home Assistant Services

binary_sensor:
  - platform: gpio
    pin: GPIO0
    name: "Doorbell Button"
    on_press:
      - homeassistant.service:
          service: notify.mobile_app
          data:
            title: "Doorbell"
            message: "Someone is at the door"
      - homeassistant.service:
          service: camera.snapshot
          data:
            entity_id: camera.front_door
            filename: /config/www/doorbell.jpg

Using Home Assistant States

binary_sensor:
  - platform: homeassistant
    name: "Security System Armed"
    entity_id: alarm_control_panel.home
    id: security_armed

switch:
  - platform: gpio
    pin: GPIO16
    name: "Front Door Lock"
    id: front_door
    interlock_wait_time: 500ms
    on_turn_on:
      - if:
          condition:
            binary_sensor.is_on: security_armed
          then:
            - logger.log: "Cannot unlock while armed"
            - switch.turn_off: front_door

Over-The-Air (OTA) Updates

After initial USB flash, update wirelessly:

Via Dashboard:

  1. Edit YAML configuration
  2. Click “Install”
  3. Select “Wirelessly”
  4. ESPHome compiles and uploads
  5. Device reboots with new firmware

Via Command Line:

# Compile and upload
docker exec -it esphome esphome run config/your-device.yaml

# Compile only
docker exec -it esphome esphome compile config/your-device.yaml

# View logs without uploading
docker exec -it esphome esphome logs config/your-device.yaml

Automatic updates:

ota:
  password: "your_ota_password"
  safe_mode: true
  reboot_timeout: 10min
  num_attempts: 5

Security Best Practices

API Encryption

Always use encrypted API:

api:
  encryption:
    key: "GENERATED_32_BYTE_BASE64_KEY"

Generate key:

docker exec -it esphome esphome wizard config/new-device.yaml
# Key generated automatically

OTA Password Protection

ota:
  password: "strong_random_password_here"

Web Server Authentication

web_server:
  port: 80
  auth:
    username: admin
    password: strong_password

Disable Unused Features

# Disable web server on production devices
# web_server:

# Disable logging on battery devices
logger:
  level: NONE

Network Segmentation

  • Place ESP devices on IoT VLAN
  • Restrict internet access if not needed
  • Only allow necessary Home Assistant communication

Real-World Projects

Multi-Sensor Environmental Monitor

Components:

  • ESP32
  • BME280 (temp/humidity/pressure)
  • BH1750 (light)
  • MQ-135 (air quality)
  • SSD1306 OLED display

Features:

  • Displays all readings on screen
  • Sends data to Home Assistant
  • Battery powered with deep sleep
  • OTA updates

Smart Garage Door Controller

Components:

  • ESP32
  • Relay module
  • Magnetic door sensor
  • HC-SR04 distance sensor
  • Status LED

Features:

  • Open/close garage door via Home Assistant
  • Monitor door position (open/closed)
  • Detect car presence with distance sensor
  • Safety timeout (auto-close after 10 minutes)
  • Notification when door left open

Addressable LED Stair Lighting

Components:

  • ESP32
  • WS2812B LED strips
  • PIR sensors (top and bottom of stairs)

Features:

  • Detect motion at stairs
  • Animate LEDs from direction of motion
  • Turn off automatically after no motion
  • Multiple effect modes
  • Brightness based on time of day

Bed Presence Sensor

Components:

  • ESP32
  • 4x FSR (force-sensitive resistors)
  • Deep sleep mode

Features:

  • Detect if bed is occupied
  • Track sleep duration
  • Trigger automations (turn off lights, set alarm)
  • Battery powered, lasts months

Plant Watering System

Components:

  • ESP32
  • Capacitive soil moisture sensors
  • Relay controlling water pump
  • DHT22 for ambient conditions
  • DS18B20 for water temperature

Features:

  • Monitor soil moisture
  • Automatic watering schedule
  • Adjusts based on weather data
  • Notifications when water reservoir low
  • Historical data tracking

Troubleshooting

Device Won’t Connect to WiFi

Check logs:

docker exec -it esphome esphome logs config/device.yaml --device /dev/ttyUSB0

Solutions:

  1. Verify WiFi credentials in YAML
  2. Check WiFi signal strength
  3. Ensure 2.4GHz network (ESP doesn’t support 5GHz)
  4. Try fallback AP mode
  5. Check WiFi channel compatibility (some regions restrict channels)

Random Reboots or Crashes

Common causes:

  1. Power supply issues: Use quality 5V 1A+ power supply
  2. Bad connections: Check loose wires
  3. GPIO conflicts: Verify pin assignments
  4. Memory exhaustion: Too many features enabled
  5. Overheating: Add heatsink or improve ventilation

Solutions:

# Enable watchdog
esphome:
  name: device-name
  on_boot:
    - logger.log: "Device booted"

# Reduce logging
logger:
  level: WARN

# Disable unused features
# web_server:

Sensor Reading Errors

For I2C devices:

i2c:
  sda: GPIO21
  scl: GPIO22
  scan: true  # Enable to list all I2C devices
  frequency: 100kHz  # Try reducing from default 400kHz

For DHT sensors:

sensor:
  - platform: dht
    pin: GPIO4
    model: DHT22
    update_interval: 60s  # Don't poll too frequently

OTA Update Failures

Solutions:

  1. Ensure device has stable power
  2. Check WiFi signal strength
  3. Increase OTA timeout:
ota:
  reboot_timeout: 15min
  num_attempts: 10
  1. Use USB flash if repeated OTA failures

High Power Consumption

Reduce power:

# Use deep sleep
deep_sleep:
  sleep_duration: 5min

# Disable WiFi when not needed
wifi:
  power_save_mode: LIGHT

# Reduce CPU frequency
esphome:
  platformio_options:
    board_build.f_cpu: 80000000L  # 80MHz instead of 240MHz

# Disable Bluetooth
esp32:
  framework:
    type: arduino
    version: recommended
  variant: esp32
  # Don't enable bluetooth_proxy

Advanced Topics

Custom Components

Create custom C++ components:

esphome:
  includes:
    - my_custom_component.h

custom_component:
  - lambda: |-
      auto my_custom = new MyCustomComponent();
      return {my_custom};

Substitutions for Multiple Devices

substitutions:
  device_name: bedroom-sensor
  friendly_name: Bedroom Sensor
  location: Bedroom

esphome:
  name: ${device_name}
  friendly_name: ${friendly_name}

sensor:
  - platform: dht
    pin: GPIO4
    temperature:
      name: "${location} Temperature"

Create templates for device types, then duplicate and customize.

External Components

Use community components:

external_components:
  - source: github://username/repository
    components: [ component_name ]

MQTT Integration

For non-Home Assistant setups:

mqtt:
  broker: 192.168.1.100
  port: 1883
  username: esphome
  password: password
  discovery: true
  discovery_prefix: homeassistant
  topic_prefix: esphome/bedroom_sensor

Cost Breakdown Examples

Basic Temperature Sensor

  • ESP32: 5 USD
  • DHT22: 4 USD
  • USB cable: 2 USD
  • Case: 2 USD (3D printed)
  • Total: 13 USD (vs 30-50 USD commercial)

Smart Light Switch

  • ESP8266: 3 USD
  • Relay module: 2 USD
  • Power supply: 3 USD
  • Switch/button: 1 USD
  • Enclosure: 3 USD
  • Total: 12 USD (vs 30-60 USD commercial)

LED Strip Controller

  • ESP32: 5 USD
  • MOSFET module: 3 USD
  • Power supply: 8 USD
  • WS2812B strip: 12 USD
  • Total: 28 USD (vs 60-100 USD commercial)

Conclusion

ESPHome transforms the ESP32/ESP8266 from simple microcontrollers into powerful, configurable smart home devices. With YAML configuration, you can create custom sensors and actuators that integrate seamlessly with Home Assistant, all at a fraction of the cost of commercial alternatives.

You now have the knowledge to:

  • Set up ESPHome and flash devices
  • Create sensor configurations for various hardware
  • Build smart switches and LED controllers
  • Implement automations and logic
  • Integrate with Home Assistant
  • Deploy battery-powered devices with deep sleep
  • Troubleshoot common issues

Key takeaways:

  • No programming required - just YAML configuration
  • Extensive component library supports most sensors
  • Native Home Assistant integration is seamless
  • OTA updates make iteration easy
  • Cost-effective alternative to commercial devices
  • Active community provides support and examples

Start with a simple sensor project, then gradually tackle more complex builds. The ESPHome community has solved most problems you’ll encounter.

Additional Resources

Happy building!