Skip to main content

XIAO ESP32C3 accesses Home Assistant via ESPHome service

This article will guide you through the installation of the ESPHome service in your own Home Assistant environment. By using the WiFi function of the XIAO ESP32C3, you will be able to connect your XIAO to the Home Assistant as part of your home terminal in a very smooth way.

In addition, we will build a Home Assistant with human presence detection in combination with the most popular 24GHz mmWave Human Static Presence Module Lite.

Getting Started

tip

As of 31 July 2023, the previous issue that would cause the radar to completely die has now been fixed, so please update the library files and configurator for this tutorial species to work properly.

If you want to follow this tutorial through everything, you will need to prepare the following.

XIAO ESP32C324GHz mmWave Human Static
Presence Module Lite

The ultimate goal of this project is to deploy 24GHz mmWave Human Static Presence Module Lite in the Home Assistant.

We have written complete configuration files and libraries for the 24GHz mmWave Human Static Presence Module Lite to facilitate your rapid deployment of sensor to Home Assistant in this project.

The content of this tutorial will broadly go through the following steps.

  1. Select your Home Assistant environment
  2. Install and cofigure ESPHome in Home Assistant
  3. Configure the XIAO ESP32C3 and ESPHome connection
  4. Configure Home Assistant Panel

Of course, if you are interested in how the XIAO ESP32C3 uses Grove in the Home Assistant, you can read this chapter directly.

Select your Home Assistant environment

In this routine, we will not expand on how to install the Home Assistant environment, we will assume that you already have a working Home Assistant device.

If you wish to learn how to install Home Assistant, then you can refer to the official tutorial. We strongly recommend that you install Home Assistant using an x86 device as this is the most user friendly way for you to install Home Assistant with Supervised.

According to the table above, it is most appropriate to install Home Assistant OS and Home Assistant Supervised, which will take a lot of hassle off your hands. If you are running Home Assistant on Docker with OpenWRT (e.g. using LinkStar H68K), please don't worry, we will also provide you with a detailed reference on how to do this.

We have also written how to install Home Assistant for some of Seeed Studio products, please refer to them.

Install ESPHome in Home Assistant

Step 1. Install ESPHome

  • Scenario 1: ESPHome installation under Home Assistant OS (with Add-on Store)

If you have the Home Assistant OS installed, it has an Add-on Store, which makes it much easier to install ESPHome.

In the Add-on Store, you can search for and install ESPHome.

  • Scenario 2: ESPHome installed under Home Assistant under OpenWRT Docker/Docker (without Add-on Store)

As we are installing the Home Assistant Container, we cannot simply download the ESPHome service via the Add-on Store, so a compromise is needed.

We need to download the ESPHome image.

esphome/esphome:latest

On the page where the container is created, we need to make some simple settings.

  • Container Name: your container name
  • Docker Image: choose just downloaded esphome image
  • Network: choose host mode
  • Environment Variables(-e): your environment variable

Once you have filled in the above, save and apply. You will see that the Container has been created. You also need to start it.

In order to achieve the same effect as downloading ESPHome in Home Assistant, we need to modify the configuration file under Home Assistant.

Go to the Home Assistant Container.

We go to the terminal in Home Assistant.

Enter the following command in the terminal.

vi configuration.yaml

Add following content to the end of configuration.yaml.

# Example configuration.yaml entry
panel_iframe:
esphome:
title: "ESPHome"
url: "http://192.168.100.1:6052"
icon: mdi:chip

Exit the docker container by type exit in the Home Assistant Container shell. Once this is done, we restart the Home Assistant container.

Create a new browser page, enter address http://homeassistant:8123/ and enter your Home Assistant account and you will see ESPHome appear in the toolbar on the left.

Configure the XIAO ESP32C3 and ESPHome connection

Step 2. Hardware preparation

The goal of our tutorial is to be able to see the data information of the 24GHz mmWave Human Static Presence Module Lite in the Home Assistant dashboard.

Connect the device to the computer through the main board. The wiring diagram is shown in the table below.

XIAO ESP32C324GHz mmWave Human Static
Presence Module Lite
5V-->5V
GND-->GND
D2-->RX
D3-->TX

Step 3. Keep the XIAO ESP32C3 and Home Assistant on the same LAN

I am sure that your Home Assistant has already done the work of getting into the network, for example by connecting to your device via a network cable. All you need to do then is simply to turn on a local network (e.g. WiFi) so that the XIAO ESP32C3 can also connect to this network.

I will use the LinkStar H68K as an example below. My aim is to get the XIAO connected to the LinkStar H68K's hotspot.

In the Network tab in OpenWRT, select Wireless --> ADD.

For Transmit Power in Device Configuration, select auto.

For the Interface Configuration settings, please fill in the following instructions.

  • General Setup
    • Mode: Depends on how LinkStar accesses the internet. If you are using a cable connection then select Client, if you are connected to WiFi then select Access Point.
    • ESSID: Enter the name of your WiFi, please try not to have spaces or special characters.
    • Network: check lan.
  • Wireless Security
    • Encryption: WPA2-PSK
    • Key: Enter the WiFi password you wish to set.

Once you have filled in the above information, click Save and Apply in the bottom right hand corner and wait a few moments for LinkStar to open a hotspot.

When no device is connected to this hotspot, it will be displayed as no signal.

All things considered, let's return to the Home Assistant page.

Click on the NEW DEVICE. Then click on Continue.

Under the new pop-up window, please enter the name of the application you wish to set up, as well as the name and password of the hotspot you have set up in LinkStar (Or your own WiFi). Make sure that the XIAO ESP32C3 and Home Assistant on the same LAN.

Then click Next.

In the device type, please select ESP32-C3.

Then click Next.

Click on the Encryption key and save it in a secure location, we will use this key in a later step.

Then click SKIP.

Step 4. Change the XIAO ESP32C3 configuration yaml file

Then, we click on the device tab we just created, with the EDIT button in the bottom left corner.

Please note that we need to make changes to this yaml file. We have divided the content to be modified into two main parts, corresponding to one and two in the diagram below.

  • In the of the content, please do not change the device name except the one you have configured, please refer to the code below for the rest of the content.
# part 1:
substitutions:
name: "xiao-esp32c3"
friendly_name: "XIAO ESP32C3"

esphome:
name: "${name}"
friendly_name: "${friendly_name}"
name_add_mac_suffix: true
project:
name: "seeedstudio.mmwave_kit"
version: "2.0"
platformio_options:
board_build.flash_mode: dio
board_build.mcu: esp32c3

external_components:
- source: github://limengdu/mmwave-kit-external-components@main
refresh: 0s

esp32:
board: esp32-c3-devkitm-1
variant: esp32c3
framework:
type: esp-idf

# Enable logging
logger:
hardware_uart: USB_SERIAL_JTAG
level: DEBUG
  • In the of the content, copy the following code after captive_portal:.
Click here to preview the full code
# Sets up Bluetooth LE (Only on ESP32) to allow the user
# to provision wifi credentials to the device.
esp32_improv:
authorizer: none

# Sets up the improv via serial client for Wi-Fi provisioning.
# Handy if your device has a usb port for the user to add credentials when they first get it.
# improv_serial: # Commented until improv works with usb-jtag on idf

uart:
id: uart_bus
baud_rate: 115200
rx_pin: 4
tx_pin: 5
parity: NONE
stop_bits: 1

seeed_mr24hpc1:
id: my_seeed_mr24hpc1

text_sensor:
- platform: seeed_mr24hpc1
heart_beat:
name: "Heartbeat"
product_model:
name: "Product Model"
product_id:
name: "Product ID"
hardware_model:
name: "Hardware Model"
hardware_version:
name: "Hardware Version"
keep_away:
name: "Active Reporting Of Proximity"
motion_status:
name: "Motion Information"
custom_mode_end:
name: "Custom Mode Status"

binary_sensor:
- platform: seeed_mr24hpc1
someone_exist:
name: "Presence Information"

sensor:
- platform: seeed_mr24hpc1
custom_presence_of_detection:
name: "Static Distance"
movement_signs:
name: "Body Movement Parameter"
custom_motion_distance:
name: "Motion Distance"
custom_spatial_static_value:
name: "Existence Energy"
custom_spatial_motion_value:
name: "Motion Energy"
custom_motion_speed:
name: "Motion Speed"
custom_mode_num:
name: "Current Custom Mode"

switch:
- platform: seeed_mr24hpc1
underly_open_function:
name: Underlying Open Function Info Output Switch

button:
- platform: seeed_mr24hpc1
reset:
name: "Module Reset"
custom_set_end:
name: "End Of Custom Mode Settings"

select:
- platform: seeed_mr24hpc1
scene_mode:
name: "Scene"
unman_time:
name: "Time For Entering No Person State (Standard Function)"
existence_boundary:
name: "Existence Boundary"
motion_boundary:
name: "Motion Boundary"

number:
- platform: seeed_mr24hpc1
sensitivity:
name: "Sensitivity"
custom_mode:
name: "Custom Mode"
existence_threshold:
name: "Existence Energy Threshold"
motion_threshold:
name: "Motion Energy Threshold"
motion_trigger:
name: "Motion Trigger Time"
motion_to_rest:
name: "Motion To Rest Time"
custom_unman_time:
name: "Time For Entering No Person State (Underlying Open Function)"

Then, please click on the Save button in the top right corner.

Step 5. Upload firmware to XIAO ESP32C3

  • Method 1: Compile and upload directly

If you are using an x86 device and can see XIAO on the device port, then you can compile and upload the program to XIAO.

Connect XIAO to your device.

Click on the three dots in the bottom right corner of the device bar and select Install.

Click Plug into the computer running ESPHome Dashboard.

Select the connected port.

Now it will download all the necessary board packages and flash the ESPHome firmware into the XIAO ESP32C3. If the flashing is successful, you will see the following output.

If you are unable to find the port after connecting XIAO to your device, then you can try using the second method.

  • Method 2: Upload compiled firmware using the host

Soft routes like LinkStar H68K do not support recognition of external MCU devices, we need to download the compiled firmware first and then upload the firmware via another PC.

Click on the Install button in the top right hand corner. Then select the last item Manual download.

Select Modern format.

It will then take a long time to download and compile, so please be patient. Once everything is ready, the firmware will be automatically downloaded to your computer.

To upload the firmware to XIAO ESP32C3 there are couple options here we show 2 ways of doing it:

Make sure you have the right drivers installed. Below are the drivers for common chips used in ESP devices.

  1. CP2102 drivers: Windows & Mac

  2. CH342, CH343, CH9102 drivers: Windowns, Mac

  3. CH340, CH341 drivers: Windowns, Mac

Open the ESPhome Web tool with Chrome or Edge web browser.

Click CONNECT.

select the XIAO ESP32 serial port in the popup window.

Click INSTALL and then select the .bin file downloaded from above steps.

If you are still unable to upload firmware using method one after installing the driver and changing browsers, then you can try using method two. Please refer to the official tutorial for specific installation methods and instructions.

tip

If you wish to observe the log messages of the XIAO ESP32C3, you can also view them through the View Logs button of this software.

Once the upload is complete, you can disconnect the XIAO ESP32C3 from the PC (unless you have a need to view the logs) and simply power the XIAO separately.

If all goes well, the XIAO ESP32C3 will search for and connect to the WiFi you have set up for it.

Just like me, I use LinkStar H68K's network. You can find it in the network options and see the IP address assigned to it by LinkStar H68K.

Normally, at this point in Home Assistant, the status of the device will also change from offline to online.

Configure Home Assistant Panel

Step 6. Connect to XIAO ESP32C3

If you do not have many Home Assistant devices on your LAN, Home Assistant can automatically search for and add your ESP devices to the Devices tab. You can see this device inside the Devices & Services tab in Settings.

If it does not automatically search, you can also connect to the XIAO ESP32C3 based on its IP address.

Click ADD INTEGRSTION and search for esphome.

Then enter the IP address of the XIAO ESP32C3 with port number 6053. Then click on SUBMIT.

If the IP address and port number entered are correct, then you will see that you are asked to enter the Encryption key, which we asked to save in step 4.

Then click on SUBMIT.

At this point, the steps to add the device have been successfully completed.

Step 7. 24GHz mmWave Module Lite functions overview

To help you quickly understand the full capabilities of the suite and the use of these features, you need to read this section carefully. If you want more detailed information, we recommend that you take the time to read the product's user manual.

For details on the configuration and parameters of the dashboard, we've compiled a detailed write-up in the ESPHome Docs, so please move over to read the full write-up and details.

Step 8. Configure Home Assistant panel

If you find the default cards very boring and unfriendly for presenting data, Home Assistant offers a wide range of ready-made dashboards to choose from.

You can make your own dashboard to suit your preferences.

For example, the option to control the output of information is turned into a nice switch.

Turning the speed of human movement into a visual dashboard display.

This is what I came up with. It looks like it has the makings of a smart home control centre.

So far, we have successfully concluded our tutorial content.

Connect Grove to Home Assistant using XIAO ESP32C3

Of course, there is more to the XIAO ESP32C3 than just support for the 24GHz mmWave Human Static Presence Module Lite in Home Assistant, and you can find more tutorials for your own use in this document.

Get your creative juices flowing!

Troubleshooting

FAQ1: I got the following error while uploading firmware using ESPhome Web tool, how can I fix it?

A: If this prompt appears while uploading, disconnect the XIAO ESP32C3 from the PC. Then, hold the BOOT BUTTON, connect the board to your PC while holding the BOOT button, and then release it to enter bootloader mode. At this point it is sufficient to reconnect and upload the firmware again.

FAQ2: I can't install esphome flasher under Linux following the tutorial of esphome flasher?

A: When executing the following commands, you need to select your system version, otherwise an error will occur. For example, my computer is Ubuntu 22.04, then the command that should be executed is as follows.

sudo apt install python3

pip3 install -U \
-f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-22.04/ \
wxPython

pip3 install esphomeflasher

FAQ3: I filled in the correct WiFi and password, why don't I see the IP address of the XIAO ESP32C3?

A: When you encounter this problem, please check that the XIAO ESP32C3's antenna is connected in place. If the antenna is already connected, please make sure that the XIAO is not further than 3m from the LinkStar if possible (unless you have replaced the antenna with a more powerful one). If you still do not see XIAO, you can use the esphome flasher software to check the XIAO log information and check the XIAO connection through the logs. You can re-plug the xiao to let it try to search for WiFi and connect again.

When you are using the Jlink flash firmware and this error occurs, then you may be in any one of the following situations.

  1. Your sensor is no longer working properly at all and you cannot receive any messages from it.
  2. You are trying to use an invalid or incorrect firmware.
caution

If your radar was originally working properly, check again that you are using the correct firmware! The firmware used varies from radar to radar and from sensor model to sensor model! And the firmware upgrade via UART is not the same as the firmware upgrade via Jlink! Please stop proceeding with the following steps.

I have confirmed that my product gets this error message in case of an exception

If your radar is not working at all, then it may be normal to have this error message.

Because the abnormal operation of the radar has allowed the radar to trigger the read/write protection mechanism, the user is no longer allowed to flash program the product in general, so we need to unlock the radar's read/write protection mechanism.

Due to the high risk of unprotecting reads and writes, we do not disclose the method of unprotecting reads and writes separately to the public here, we will place the method in the zip file here for those who need it. Once the abnormal radar is unprotected, the firmware can be updated again to restore normal operation.

Tech Support & Product Discussion

Thank you for choosing our products! We are here to provide you with different support to ensure that your experience with our products is as smooth as possible. We offer several communication channels to cater to different preferences and needs.

Loading Comments...