Getting Started with ESPHome through Hass.io

ESPHome is the perfect solution for creating custom firmware for your ESP8266/ESP32 boards. In this guide we’ll go through how to setup a basic “node” by use of the Hass.io add-on.

But first, here’s a very quick introduction to how ESPHome works: ESPHome is a tool which reads in a YAML configuration file (just like Home Assistant) and creates a custom firmware binary. The tool also has many helpers that simplify flashing devices (uploading the new binary file) and aim to make managing your ESP boards as simple as possible. Once you have added devices or sensors in ESPHome’s configuration, they will even automatically show up in Home Assistant’s UI.

Installation

Installing the ESPHome Hass.io add-on is easy. Just navigate to the Hass.io panel in your Home Assistant frontend and add the ESPHome add-on repository: https://github.com/esphome/hassio

../_images/hassio_repo.png

Then, scroll down and locate the ESPHome Hass.io Add-Ons section. Click on ESPHome, then INSTALL.

../_images/hassio_addons_section.png

After that, wait a bit until the add-on is installed (this can take a while) and go to the add-on page. Start the add-on and then click “Open Web UI”.

../_images/hassio_addon.png

You should now be greeted by a nice introduction wizard which will step you through creating your first configuration.

../_images/hassio_start.png

Dashboard Interface

Assuming you created your first configuration file with the wizard, let’s take a quick tour of the ESPHome dashboard interface.

../_images/hassio_interface.png

On the front page you will see all configurations for nodes you created. For each file, there are three basic actions you can perform:

  • UPLOAD: This compiles the firmware for your node and uploads it using any connected USB device or, if no USB devices are connected, over-the-air using the OTA Update Component.

    Warning

    The Hass.io Add-On is currently not capable of discovering new USB ports after the add-on has started due to some docker restrictions. Please go to the add-on details page and restart the add-on if a new USB device is not automatically found. If the USB device is still not found, try changing the USB cable and restarting the add-on.

  • SHOW LOGS: With this command you can view all the logs the node is outputting. If a USB device is connected, it will attempt to use the serial connection. Otherwise it will use the built-in OTA logs.

  • COMPILE: This command compiles the firmware and gives you the option of downloading the generated binary so that you can upload it yourself from your computer.

    Note

    If you’re having problems with flashing over USB, you can always download the firmware using the COMPILE button and flash the firmware using ESPHome-flasher.

The configuration files for ESPHome can be found and edited under <HOME_ASSISTANT_CONFIG>/esphome/. For example the configuration for the node in the picture above can be found in /config/esphome/livingroom.yaml.

Now go ahead and use one of the devices guides to extend your configuration for the device you intend to flash an ESPHome firmware onto. Then proceed with uploading the first firmware using the upload button.

Adding some (basic) features

So now you should have a file called /config/esphome/livingroom.yaml (or similar). Go open that file (in any text editor) and add a simple GPIO switch to the configuration like this:

switch:
  - platform: gpio
    name: "Living Room Dehumidifier"
    pin: 5

In above example, we’re simply adding a switch that’s called “Living Room Dehumidifier” (could control anything really, for example lights) and is connected to the pin GPIO5.

Now when you go to the Home Assistant “Integrations” screen (under “Configuration” panel), you should see the ESPHome device show up in the discovered section (although this can take up to 5 minutes). Alternatively, you can manually add the device by clicking “CONFIGURE” on the ESPHome integration and entering “<NODE_NAME>.local” as the host.

../_images/gpio-ui.png

After the first upload, you will probably never need to use the USB cable again, as all features of ESPHome are enabled remotely as well. No more opening hidden boxes stowed in places hard to reach. Yay!

Adding A Binary Sensor

Next, we’re going to add a very simple binary sensor that periodically checks a GPIO pin to see whether it’s pulled high or low - the GPIO Binary Sensor.

binary_sensor:
  - platform: gpio
    name: "Living Room Window"
    pin:
      number: 16
      inverted: True
      mode: INPUT_PULLUP

This is an advanced feature of ESPHome, almost all pins can optionally have a more complicated configuration schema with options for inversion and pinMode - the Pin Schema.

This time when uploading, you don’t need to have the device plugged in through USB again. The upload will magically happen “over the air”.

../_images/gpio-ui1.png

Where To Go Next

Great 🎉! You’ve now successfully setup your first ESPHome project and uploaded your first ESPHome custom firmware to your node. You’ve also learned how to enable some basic components via the configuration file.

So now is a great time to go take a look at the Components Index. Hopefully you’ll find all sensors/outputs/… you’ll need in there. If you’re having any problems or want new features, please either create a new issue on the GitHub issue tracker or find us on the Discord chat (also make sure to read the FAQ).