Introduction

In this post, we explore the diverse capabilities and opportunities offered by Espressif’s renowned microcontrollers, the ESP8266 and ESP32.

Guides:

In order to program and use the boards, we could use different methods:

Personally, I have the two types of boards,

Arduino IDE

Using the Arduino IDE is the easiest way to program and use any ESP board, with plenty of examples for development

IDE,

iot

Examples,

iot

Blink code example,

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);
}

And if using the MQTT Client library, PubSubClient, we could use the ESP8266 with MQTT to communicate with Home Assistent, as previous post.

ESPHome

Using python to install the tool and following the official guide, it is very easy as well to just program anything on the board (ESP8266 or ESP32), reusing components to communicate with different sensors only by adding the description in the yaml file, and even programming Over-The-Air (OTA) the microcontroller.

Create a project, esphome wizard livingroom.yaml

Adding some features,

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

Upload the code, esphome run livingroom.yaml

On the Home Assistant side, the ESPHome is detected as new integration, and a new Device (in this case, called espi) could be found

iot

The feature of the ESP8266 is a simple switch, which will toggle the LED status, D0, between HIGH and LOW. This can now be controlled by the Home Assistant with the control entity

iot

From here, all the components could be added following the same logic (More component description here).

And after this first programming, the next could be done by OTA.

iot

ESPHome ESP8266 Example - Temperature and Humidity

If we want to add a sensor for Temperature and Humidity such as the AHT20, it is available in the ESPHome so we just follow the example for the sensor component page for AHT Sensors

# Example configuration entry
sensor:
  - platform: aht10
    variant: AHT20
    temperature:
      name: "Living Room Temperature"
    humidity:
      name: "Living Room Humidity"
    update_interval: 60s

Including the I2C communication, also as a component

i2c:
  sda: GPIO4
  scl: GPIO5
  scan: true

Hardware connection as follow (According the pinout)

iot

And after uploading the code, we can already see in the logs the communication the communication is successful. iot

The ESP is getting the information from the sensor and sending out. iot

And finally, in the home assistant, we can see the Sensor values humidity and temperature, with the names defined in the .yaml. iot

ESPHome Device Builder

Another way to use the ESPHome is with the Builder, as a web server. After installing the dependencies following the tutorial

pip install tornado esptool

We can start the dashboard,

mkdir config
esphome dashboard config

And launching in chrome the dashboard, localhost:6052

iot

The device can be created, and the configuration could be modified directly on the local web. In other words, we could have exaclty the same as the standard ESPHome but with nicer interface.

iot

Bonus: ESP32 Bluetooth Proxy

For adding Bluetooth devices to our home assistant, we could follow the recommendation from HAA better approach than a directly connected adapter or card is to use a Bluetooth proxy using an ESP32 since Linux kernel updates have previously broken Bluetooth functionality

Therefore, this is the ESP32 module to add for forwarding the Bluetooth devices to HA via Wi-Fi: https://esphome.io/components/bluetooth_proxy

Although, there is a “ready-made project” to use directly for the bluetooth proxy, a better (and configurable) option is to do it ourself, at least, with ESPHome. In any case, this is the yaml configuration to add in our devices, coming from the “ready-made” project from before.

Notes:

  • The ESPHome Device Builder could be installed directly on the rpi with HA, but it the rpi is not the most recent one I don’t recommend it for resources.
  • The integrated bluetooth from rpi could be disconnected to ensure we are using the proxy and not the internal bluetooth.
  • With my current / cheap ESP32 I couldn’t manage to connect BLE devices. This may be coming because the ESP32 I use is one of the first generation.

Wrap-up and Ideas for Enhancement

  • In this post, we explore 3 ways to program our Espressif devices: Arduino IDE; ESPHome and ESPHome Builder.
    • ArduinoIDE is nice, with lot of support, but if custom programming needs to be made, I personally will chose ESP-IDF.
    • ESPHome/ESPHome Builder, are a very quick way to integrate a sensor, if you need only that, and the component you want to integrate is on the list.
  • HW Setup
  • For the next project,