Clone
7
Creating Your First Device in Home Assistant ‐ ESPHome
Dave Williams | DitroniX | G8PUO edited this page 2026-05-30 06:37:52 +01:00

Congratulations

You now have a board which you are excited to add to Home Assistant. So let's get started.

Note: This is not a step by step guide, so please follow the prompts where needed and you should be able to flow through the process.

Top Level

  • Use Home Assistant ESPHome to Create and Maintain Devices
  • Use existing External Component(s). (Think of these as libraries.)
  • Create Device
  • Paste or Edit YAML code
  • Add new Device to Dash

Preliminary Information on the Basics!

How Does It Work?

Using Home Assistant, with integrated ESPHome, you are easily able to create a new 'Device', then flash the board so it will then appear in your Dashboard > Devices.

Home Assistant (ESPHome), devices use .yaml code, which is initially flashed to the board via USB cable.

Once flashed (so the board is 'talking' to Home Assistant'), you can then subsequently easily reflash to the board using OTA, Over-The-Air, via Wi-Fi.

USB re-flashing remains an option if needed.

Example of New Device

Home Assistant (ESPHome) Devices

Home Assistant (ESPHome), uses 'Components', which configures and tells Home Assistant about the device which you are trying to add.

Two 'flavours' of components are available (as far as I am aware):

  • Internal Components (embedded into HA)
  • External Components (This is a custom component, not currently embedded into HA)

DitroniX External Components are located in https://github.com/DitroniX/Home-Assistant-Dev/tree/main/components

DitroniX Component Development

During DitroniX Home Assistant Code Development, the required device 'Component', is simply connected to the DitroniX git (GitHub), repository, as an external component.

You could of course, always 'clone' this component and make your own.

The below is an example of the source pointing to the git repository.

- source:  
type: git  
url: [https://github.com/DitroniX/Home-Assistant-Dev]
(https://github.com/DitroniX/Home-Assistant-Dev)

Get Programming!

Initial Basics

This basic tutorial assumes you already the following installed and configured (links provided is not).

Adding a Device

You will be using ESPHome to add a device and integrate is to Home Assistant.

ESPHome allows you to create device 'configurations' which in turn adds common microcontrollers into smart home devices.

Open ESPHome Builder

Assuming you have added ESPHome device builder to your left menu bar within Home Assistant, simply click 'ESPHome Builder'

Secrets

ESPHome configuration for a device lives in a .yaml file. Within this YAML file, you can add a whole range of device configuration information, the most common between devices is your Wi-Fi setup information.

If not already configured, I would recommend you setup your 'secrets' file. Within YAML , this is <<: !include ../secrets.yaml

To configure the secrets file, you need to:

ESPHome Secrets

ESPHome Secrets Editor

Edit the Wi-Fi settings and click [Save]. That is it, all done!

YAML

YAML is designed to be human-readable and easy to edit. However, like all programming languages, it has it's oddities and quirky gotchas.

  • You can only use spaces for indentation
  • Using the `[Tab] key is strictly forbidden and can cause parser errors or unexpected block merges
  • If you want an empty string, you have to add quotes. E.g. MyString = ""
  • You do not need add a semicolon at the end of each function or command. YAML treats semicolons as a regular string character, rathe than syntax delimiter.

New Device

Within ESPHome, to create a device, simply click the NEW Device on the bottom right of the screen, the click [CONTINUE].

You would normally click the [New Device Setup].

Give your device a meaningful name

Select the ESP device, normally ESP32-C6.

For ESP32-C5, also see this page for reference.

Finally click [INSTALL]. The Auto Generated Encryption Key will be automatically added to the YAML file.

Excellent! Your new device should not be added to the ESPHome Device Builder dash.

Setting up your New Device

Now you have a 'blank device' you could run through flashing it with blank code, to ensure it then appears in the dash as online.

If you right click the three dots on your device, you will be requested to install the YAML to the device itself. As this is a new device and does not know about Wi-Fi etc., simply use the [Plug into this computer] option.

Flashing

You will be using the Web Browser to flash the device.

If you clicked the Install,, you may see this instead

Chose the downloaded and saved file.

Finally - Success! Your board is flashed with a blank code. It should then show in the dash as online.

Adding the DitroniX configuration

You are now at a stage where you can edit the device YAML and add the test code.

YAML Test code is provided in the individual product repositors, or in the YAML folder. https://github.com/DitroniX/Home-Assistant-Dev/tree/main/YAML%20Examples

Click the [EDIT] button on the device dash and this should open the YAML Editor.

At this stage, you will be copying the test YAML code and pasting it into the editor.

Remember, that you must NOT over-write the elements below the # Enable Home Assistant API, or your unique device will not be known by your system.

You may alternatively, simply update the xxxx with your details.

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

ota:
  - platform: esphome
    password: "xxxxx"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "EPEM E36 House Fallback Hotspot"
    password: "xxxxx"

Add Device to your dash

You may now add the device to your normal Home Assistant dash and select required values to be displayed.

Finally

Once your device is up and running, you can always 'tweak', or edit, the YAML code, then quickly reflash, at any time, either by OTA or USB.

You can even duplicate the code for another device.

Remember though, each device has it's own unique 'api key', 'ota password' and 'ap fallback password'. The rest of the code can be duplicated across your devices, where needed.