ESPHome (previously known as esphomelib) is a Nabu Casa-owned tool with which you can create custom firmware for readily available and cheap ESP8266 and ESP32 boards. Custom firmware on its own might sound complicated, but ESPHome makes its creation easy. Before you buy your first D1 mini, WS1812B LED strip, and sensor, you might want to know what exactly ESPHome is and what it allows you to do.
You won’t need any programming skills to get started with ESPHome and if you are capable of configuring Home Assistant integrations using YAML, you will feel right at home. ESPHome is the perfect companion to Home Assistant. There is an official integration built-in to Home Assistant, and ESPHome devices, also known as nodes, on your network will be discovered automatically.
Before going into what ESPHome is and what it allows you to do, you might want to take a closer look at the two microchips that are central to this tool: the ESP8266 and its successor, the ESP32.
What is ESPHome, and how does it work?
ESPHome is a tool which reads a configuration file and creates a custom firmware binary. YAML is used to create the configuration file, you will be familiar with the language if you have been using Home Assistant for any amount of time. Each node, that is what we call the individual ESPHome devices, has its individual configuration file.
ESPHome supports a long list of sensors, which can be configured with just a few lines of YAML. The only thing you need to take note of is which pin it is connected to. If we were to hook up a BME280 temperature, humidity, and pressure sensor, we would connect the 3.3V pin on the sensor to 3.3V on the ESP8266 or ESP32 board, the GND pin to GND. To read data from the sensors, the I²C pins can be connected to the appropriate inputs. The following ten lines configure the sensor:
sensor: - platform: bme280 temperature: name: "BME280 Temperature" pressure: name: "BME280 Pressure" humidity: name: "BME280 Humidity" address: 0x77 update_interval: 60s
Not only data from sensors can be gathered, ESPHome can also push data to attached components. For example, it can control an individually addressable LED strip such as those using the WS2812B chip. ESPHome can also drive a variety of displays, ranging from dot matrices to e-paper screens.
How is ESPHome installed?
As you might expect from a Nabu Casa owned tool, ESPHome can be installed as a Home Assistant add-on. Just like Home Assistant, ESPHome is built using the Python programming language and can also be installed natively. And finally, there is an ESPHome Docker image available, which is how I have it installed on my Unraid server.
What does ESPHome look like?
You might be wondering how ESPHome can be controlled once it’s installed. ESPHome uses a web interface from which you can create configuration files for new nodes, compile your custom firmware, and update or flash existing nodes.
The web interface also has a built-in YAML editor, sparing you the need to open the configuration in an external application. The editor will debug the code, and suggest links to components you have wrongly configured.
How is a new configuration created in ESPHome?
The easiest way of creating a configuration file for a new node is by clicking on the big, green plus button in the web interface. By doing so, a configuration wizard, which will insert basic information in to your configuration file, will be started.
Alternatively, you can create your configuration file manually, and it will be picked up by ESPHome. This is useful if you prefer to use a third-party editor, such as Visual Studio Code. Or you could use a combination of both by walking through the configuration wizard, but adding everything else directly to the YAML file.
How are ESP8266 and ESP32 boards flashed?
You have a few options when it comes to flashing your ESP8266 and ESP32 boards for the first time. You can either hook them up to the same machine on which ESPHome is running and flash them using the web interface. This can be a bit of a nuisance if your server or Raspberry Pi isn’t accessible. Luckily, there are alternative ways of flashing a board.
You can also compile your custom firmware using the ESPHome web interface and then download it to your local machine. A little tool named ESPHome-Flasher can then flash the board after hooking it up to a free USB port.
The third and newest option is to use the ESPHome Web Tools. Using them, you can flash a board with nothing more than a Chrome browser. No matter how you flashed the ESPHome node, once it is up and running, you can update it over-the-air (OTA) using the web interface.
What can ESPHome do?
The question “What can’t ESPHome do?” would probably lead to a shorter answer. ESPHome gives you the power to create just about any IoT tool imaginable. To give you a broad idea, I will share a just few things you can do using ESPHome:
- You can build multisensors using any of the supported sensors.
- Information can be gathered from Xiaomi BLE sensors and displayed in Home Assistant (requires an ESP32).
- Bluetooth Low Energy Beacons (iBeacons) built with an ESP32 can be used for presence detection around the home.
- You can control cheap (or expensive) LED strips and create accent or functional lighting.
- E-Paper displays can be used to display any data from Home Assistant.
The popular $15 DIY multi-sensor made by the YouTuber BRUH Automation can be configured with fewer than 50 lines of YAML. That’s right, you can create a multi-sensor which measures temperature, humidity, light, motion, and has an RGB LED in a matter of minutes.
Parts to get you started with ESPHome
There are a few things I recommend you purchase, along with the sensors, lights, and displays you want to make use of. A breadboard and jumper wires are the easiest way of prototyping a new node. Once you have confirmed it to be working, you can move to a more permanent setup.
The WS2812B RGB light strips are what you will have seen in most lighting projects. While they aren’t the best individually addressable RGB LED chips, they are very affordable. Using these LED strips, you can create animations and fit them in or around just about any object.