Voorbereiding: ESPHome Builder Integratie
Om de LD2410 sensor te kunnen gebruiken in ESPHome is een extra bestand nodig dat hier gedownload kan worden:
https://github.com/NicoOosterwijk/ESPHome-LD2410/blob/main/ld2410_uart.h
Kopieer dit bestand naar Home Assistant in de directory /config/esphome, bijvoorbeeld met scp:
scp ./ld2410_uart.h homeassistant.local:/config/esphome/ld2410_uart.h
Indien de docker-versie van HA gebruikt wordt staat de configuratie wellicht in een docker volume. Deze vindt je terug in /var/lib/docker/volumes op de docker host.
Als ESP-module gebruik ik hier de Wemos D1 mini v3 . Installeer deze in ESPHome met default instellingen.
Als presence sensor gebruik ik de LD2410C:
Er zijn verschillende modellen van deze module en de LD2410C heeft ‘normale’ pin aansluitingen, de LD2410 en LD2410B zijn voorzien van mini-pins en dat is minder handig om aan te sluiten. Daarnaast zijn de modellen B en C tevens voorzien van bluetooth.
Wijzig nu de configuratie zodat de LD2410 opties er ook in staan, bijvoorbeeld:
esphome:
name: wemos-01
includes:
- ld2410_uart.h
on_boot:
priority: 600
#
then:
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setNumbers(maxMovingDistanceRange, maxStillDistanceRange, noneDuration);
esp8266:
board: esp01_1m
# Enable logging
logger:
baud_rate: 0
# Enable Home Assistant API
api:
encryption:
key: !secret api-password
ota:
password: !secret ota-password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Wemos-01 Fallback Hotspot"
password: !secret ap-password
captive_portal:
uart:
id: uart_0
tx_pin: TX
rx_pin: RX
baud_rate: 256000 # Change this according to your setting
parity: NONE
stop_bits: 1
debug:
direction: BOTH
dummy_receiver: false
after:
delimiter: [0xF8,0xF7,0xF6,0xF5]
custom_component:
- lambda: |-
return {new LD2410(id(uart_0))};
components:
- id: ld2410
binary_sensor:
- platform: custom
lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
return {uart_component->hasTarget,uart_component->hasMovingTarget,uart_component->hasStillTarget,uart_component->lastCommandSuccess};
binary_sensors:
- name: "Has Target"
- name: "Has Moving Target"
- name: "Has Still Target"
- name: "Last Command Success"
sensor:
- platform: custom
lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
return {uart_component->movingTargetDistance,uart_component->movingTargetEnergy,uart_component->stillTargetDistance,uart_component->stillTargetEnergy,uart_component->detectDistance};
sensors:
- name: "Moving Target Distance"
unit_of_measurement: "cm"
accuracy_decimals: 0
- name: "Moving Target Energy"
unit_of_measurement: "%"
accuracy_decimals: 0
- name: "Still Target Distance"
unit_of_measurement: "cm"
accuracy_decimals: 0
- name: "Still Target Energy"
unit_of_measurement: "%"
accuracy_decimals: 0
- name: "Detect Distance"
unit_of_measurement: "cm"
accuracy_decimals: 0
number:
- platform: template
name: "Max Moving Distance Range"
id: maxMovingDistanceRange
min_value: 1
max_value: 8
step: 1
update_interval: never
optimistic: true
set_action:
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setMaxDistancesAndNoneDuration(x,id(maxStillDistanceRange).state,id(noneDuration).state);
- platform: template
name: "Max Still Distance Range"
id: maxStillDistanceRange
min_value: 1
max_value: 8
step: 1
update_interval: never
optimistic: true
set_action:
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setMaxDistancesAndNoneDuration(id(maxMovingDistanceRange).state,x,id(noneDuration).state);
- platform: template
name: "None Duration"
id: noneDuration
min_value: 0
max_value: 32767
step: 1
mode: box
update_interval: never
optimistic: true
set_action:
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setMaxDistancesAndNoneDuration(id(maxMovingDistanceRange).state,id(maxStillDistanceRange).state,x);
button:
- platform: template
name: "Reboot LD2410"
on_press:
lambda: 'static_cast<LD2410 *>(ld2410)->reboot();'
- platform: template
name: "Turn on config mode"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(true);'
- platform: template
name: "Turn off config mode"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(false);'
- platform: template
name: "Get config"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
- platform: template
name: "Set baud rate to 256000"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->setBaudrate(7);'
- platform: template
name: "Set baud rate to 115200"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->setBaudrate(5);'
- platform: template
name: "Set baud rate to 9600"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->setBaudrate(1);'
De wachtwoorden en keys staan in de ESPHome secrets (rechtsboven)
Kies voor INSTALL om de configuratie in de ESP te schrijven, dit kan ‘Wirelessly‘.
Hierna kan de LD2410C gekoppeld worden aan de ESP-module, let op dat de Rx aan Tx op de ESP en Tx aan Rx op de ESP moet worden aangesloten!
ESP8266 <-> LD2410
5V <-> VCC
GND <-> GND
TX <-> RX
RX <-> TX
Voorzie de ESP32 van spanning middels een usb-kabel en Home Assistant komt dan met een melding dat er een nieuw device is gevonden:
Met CONFIGUREREN worden de sensors aangemaakt en deze kunnen dan in een Dashboard gebruikt worden of in Automatiseringen, Scènes of Scripts.





