Build Human Presence Sensor with ESP8266, LD2410 and ESPHome, Integrate into Home Assistant.
|
| My cheap Human Presence Sensor. |
Here is my cheap human presence sensor with ESP8266, LD2410C mmWave radar sensor, and ESPHome. It costs about RM 27.51(ESP8266 - RM 9.9, LD2410C - RM 17.61). I place it on top of my wardrobe and use a tripod to hold it vertically.
This is my first time using ESPHome and LD2410. The LD2410C mmWave radio sensor module comes with Bluetooth connectivity, and Home Assistant has an integration for this sensor module. We can power the LD2410C and directly integrate the sensor module into Home Assistant via Bluetooth.
|
| Home Assistant integration for LD2410 |
Somehow, the Bluetooth connection between the Home Assistant and LD2410C is unstable and breaks every few minutes. Therefore, I use an ESP8266 hook with LD2410C, run ESPHome, and integrate it into Home Assistant via Wi-Fi.
Let's build it.
Parts Required
- Any ESP8266 development board - Also, any ESP32 development
- HLK-LD2410C mmWave Radar Sensor Module - Any LD2410 variant
- A few jumper wires
- Breadboard - if necessary
- USB Cable
Flash ESPHome into ESP8266
First, we need to flash the ESPHome firmware into ESP8266.
ESPHome provides an easy way to flash ESPHome firmware into ESP8266/ESP32/RP2040(Raspberry Pi Pico) through a web page. However, it only works with Chrome and Microsoft Edge browsers. You also may need the USB driver for your development board.
Connect the USB cable with the ESP8266 and computer.
|
|
Instructions for installing ESPHome to ESP8266 via web page. |
Open the ESPHome web page, select "Empty ESPHome device", pick "ESP8266/ESP32" and click the Connect button.
|
|
Select the corresponding USB serial port for ESP8266 |
|
|
Click the INSTALL ESPHOME WEB |
Select the corresponding USB serial port for ESP8266 and start installing ESPHome Web.
|
|
set-up Wi-Fi connection for ESP8266 |
Once the installation is complete, set up the Wi-Fi connection for the ESP8266.
After, we can leave the ESP8266 alone, keep it powered, and upload a new configuration(yaml) through wireless later.
Set up ESPHome Dashbaoard using Docker Compose
Start setting up the ESPHome Dashboard with Docker Compose. Make sure you already installed Docker Compose on your computer. I'm hosting the ESPHome Dashboard on my OrangePi 3 Zero and adopt the ESPHome device later.
Here is the docker-compose.xml(from the official documentation.)
version: '3'
services:
esphome:
container_name: esphome
image: ghcr.io/esphome/esphome
volumes:
- /path/to/esphome/config:/config
- /etc/localtime:/etc/localtime:ro
restart: always
privileged: true
network_mode: host
environment:
- USERNAME=ChangeHere
- PASSWORD=ChangeHere
The commands to start the docker-compose.xml
$ docker compose up -d
Once the ESPHome Dashboard is ready, we can log on and adopt the ESPHome device.
http://<your ip address>:6052/
ESPHome Configuration for Human Presence Sensor
|
|
Adopt the ESP8266 we just created. |
Adopt the ESPHome device we just created. The adoption will take time to flash new firmware to the ESPHome device.
Later, edit and save the YAML file according to the below. All these codes I get it from the ESPHome documentation.
# Append code below the captive_portal #
......
uart:
id: uart_ld2410
tx_pin: GPIO1
rx_pin: GPIO3
baud_rate: 256000
parity: NONE
stop_bits: 1
ld2410:
uart_id: uart_ld2410
binary_sensor:
- platform: ld2410
has_target:
name: Presence
has_moving_target:
name: Moving Target
has_still_target:
name: Still Target
sensor:
- platform: ld2410
light:
name: light
moving_distance:
name : Moving Distance
still_distance:
name: Still Distance
moving_energy:
name: Move Energy
still_energy:
name: Still Energy
detection_distance:
name: Detection Distance
g0:
move_energy:
name: g0 move energy
still_energy:
name: g0 still energy
g1:
move_energy:
name: g1 move energy
still_energy:
name: g1 still energy
g2:
move_energy:
name: g2 move energy
still_energy:
name: g2 still energy
g3:
move_energy:
name: g3 move energy
still_energy:
name: g3 still energy
g4:
move_energy:
name: g4 move energy
still_energy:
name: g4 still energy
g5:
move_energy:
name: g5 move energy
still_energy:
name: g5 still energy
g6:
move_energy:
name: g6 move energy
still_energy:
name: g6 still energy
g7:
move_energy:
name: g7 move energy
still_energy:
name: g7 still energy
g8:
move_energy:
name: g8 move energy
still_energy:
name: g8 still energy
switch:
- platform: ld2410
engineering_mode:
name: "engineering mode"
bluetooth:
name: "control bluetooth"
number:
- platform: ld2410
timeout:
name: timeout
light_threshold:
name: light threshold
max_move_distance_gate:
name: max move distance gate
max_still_distance_gate:
name: max still distance gate
g0:
move_threshold:
name: g0 move threshold
still_threshold:
name: g0 still threshold
g1:
move_threshold:
name: g1 move threshold
still_threshold:
name: g1 still threshold
g2:
move_threshold:
name: g2 move threshold
still_threshold:
name: g2 still threshold
g3:
move_threshold:
name: g3 move threshold
still_threshold:
name: g3 still threshold
g4:
move_threshold:
name: g4 move threshold
still_threshold:
name: g4 still threshold
g5:
move_threshold:
name: g5 move threshold
still_threshold:
name: g5 still threshold
g6:
move_threshold:
name: g6 move threshold
still_threshold:
name: g6 still threshold
g7:
move_threshold:
name: g7 move threshold
still_threshold:
name: g7 still threshold
g8:
move_threshold:
name: g8 move threshold
still_threshold:
name: g8 still threshold
button:
- platform: ld2410
factory_reset:
name: "factory reset"
restart:
name: "restart"
query_params:
name: query params
text_sensor:
- platform: ld2410
version:
name: "firmware version"
mac_address:
name: "mac address"
select:
- platform: ld2410
distance_resolution:
name: "distance resolution"
baud_rate:
name: "baud rate"
light_function:
name: light function
|
| Validate YAML file. |
Validate the YAML file in ⋮(three vertical dots button).
|
|
Install new configuration. |
Then, hit the Install button in ⋮(three vertical dots button) to upload the new configuration into ESP8266.
ESP8266 and LD2410 Assembly
|
| DIY Human Presence sensor Schematic Diagram |
Now, we can unplug the USB cable and wire up the LD2410C sensor module with ESP8266.
Wire the ESP8266 and LD2410 as below:
------------ ---------- | ESP8266 | LD2410 | ------------ ---------- | RX(GPIO3) | TX | ------------ ---------- | TX(GPIO1) | RX | ------------ ---------- | VIN | VCC | ------------ ---------- | GND | GND | ------------ ----------
Home Assistant Integration
The last step is to integrate the ESPHome device into Home Assistant.
|
|
Home Assistant auto discover new ESPHome device. |
We can go to Home Assistant → Settings → Devices and Services → under the Integration tab, and our ESPHome device should be displayed in the Discovered section. Click the Configure button to add the ESPHome device to Home Assistant.
|
|
Get Encryption Key(API Key) in ESPHome Dashboard. |
The Home Assistant will ask for the ESPHome device encryption key. We can get it in the ESPHome Dashboard → ⋮(three vertical dots button) → show API key.
|
| Reading from LD2410 shows in Home Assistant. |
All the sensor readings should be displayed in the Home Assistant → Settings → Devices and Services → Devices tab(on top of the webpage) → Click the ESPHome device.












