ESP8266 and ESP32 are low-cost micro-controllers by Espressif Systems. They come in various form of development boards and are very popular in the Arduino development environment. The Make Advisor website has reviews on some of the popular ESP8266 and ESP32 boards. Since my home automation system is based on Home Assistant, I started to experiment with custom firmware to enable them to be controlled directly from Home Assistant. The development boards I tried were the NodeMCU LUA ESP-12E and ESP32 Devkit.
A couple of requisite software tools are needed: ESPHome Flasher for flashing custom firmware onto the development board, and USB-to-serial driver. Both NodeMCU LUA ESP-12E and ESP32 Devkit boards use the CP2102 USB-to-UART chipset which required a virtual COM port driver for connection to PC.
- Install ESPHome Flasher; Wndows and Mac versions can be downloaded from https://github.com/esphome/esphome-flasher/releases
- Download and install USB driver from Silicon Lab website
- Install ESPHome Hass.io Add-on for Home Assistant:
- open the Home Assistant Supervisor pane and click on the Add-on Store tab
- click the three dots on the top right and select Repository
- in the Add Repository filed, enter https://github.com/esphome/hassio and click Add then Close
- the ESPHome Hass.io Add-On is now added to the Add-on Store
- select ESPHome then Install
- start ESPHome add-on then click on Open Web-UI to launch ESPHome Dashboard
- Add development board board to ESPHome:
- on the ESPHome Dashboard, click the + button to add a new device, I called mine “nodemcu_1”
- for Device Type, select “NodeMCU”for ESP8266 or “Espressif ESP32 Dev Module” for ESP32 Devkit
- next enter wifi SSID and password and click “Submit”
- on the newly created device, click the three-dot menu on the top right corner and select “Compile”
- when the compilation completes, click “Download Binary” and save the bin file on your local drive
- connect the ESP8266/ESP32 board to USB port and launch ESPHome Flasher, the serial port should be selected automatically
- select the bin file for “Firmware” and click “Flash ESP”. Confirms successful flash and that the device is on-line in the console log
- I always setup my IoT devices with static IP and use the secret file feature for ease of management. To set up static IP, change the device configuration yaml file as follow:
esphome:
name: nodemcu_1
platform: ESP8266
board: nodemcuv2
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.1.41
gateway: 192.168.1.1
subnet: 255.255.255.0
dns1: 192.168.1.1
dns2: 8.8.8.8
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
- After the initial flashing, OTA update can be used for subsequent updates to the device configuration, no need to connect the board through USB port.
- To add the ESP device to Home Assistant, go to “Configuration” -> “Integration”. The device should be listed in the Discovered panel. Click Configure, and any sensor or switches attached to the ESP device will be included as Home Assistant entities.