LD2410 esphome tips

ok…i am under Android

And for those having problems with ld2410 component in EspHome 2023.2.1, add this to your node did the trick :

external_components:
  - source: github://esphome/esphome@dev
    components: [ ld2410 ]

i dont understand why i am the only one who having trouble with LD2410 component in the last EspHome 2023.2.1 or 2023.2.2 of today, same problem…

I use the “standard” AddOn : EspHome, not “Beta” or “Dev” version, and it seems that LD2410 is, for the moment, only on the Dev version of the EspHome AddOn, that why the component LD2410 is not found on the basic version of EspHome :smile:

I’m not using any DEV or Beta only the stable version of ESPhome and the sensor works fine just adding the yaml configuration nothing more.
ESPhome 2023.2.2

lucky you, not me, and dont understand why, if someone has an idea…im interested in

can you please point us to a working yaml config?

The code that works for me on the D1 mini is used from the natively supported LD2410 sensor in the ESPhome documentation.
Use the hardware UART and set the sensor to the default values according to the table. The sample code is not working properly. Don’t forget to set the logger baud rate to 0

I have just moved one of my sensors over to using the above code from this code

All working fine here. So the other 2 will be changed today.

For your information:

  • sample code was just for reference and MUST be adapted to your particular conditions and requirements ( I assume it should have been mentioned in the doc)
  • a newer version enabling configuration of threshold within HA is on the way…
3 Likes

Yes, I understand that it must always be configured according to its own environment, but it can be confusing for many users when they insert the sample code and it works wrong. Maybe it would be better if the sample code was in the default values of the sensor.

2 Likes

Looking forward to the second point. Thanks in advance

Has anyone made a comparison between using the LD2410 via esphome, and using the LD2410BLE integration?

2 Likes

Yes, I tried the HLK-LD2410BLE integration, which works, but the sensor is unstable if not close to the HA (BT) and often disconnects.
The sensor loaded in the integration will not connect to the BT phone app for setup, you need to stop the integration in HA, set up the sensor in the phone and turn on the HA integration again.
I moved the LD2410B to esp D1 mini and it works there without problem and stable.

2 Likes

Hello all,

i played with 4 ld2410 with Wemos D1 Mini and it works great for almost a year.

I see that LD2410B is now integrate in HA with the LD2410BLE integration. So i buy 3 “B” version.

The integration is really simple and work great.

There is not a lot of infos here https://www.home-assistant.io/integrations/ld2410_ble/

is someone can tell how many LD2410 can be connect on a bluethooth-proxy node on EspHome?

Because on the doc of the bluethooth-proxy in EspHome, its says only 2 or 3 BLE device can be add maximum to a node, if they are connected all the time. I have 3 xiaomi_lywsd03mmc “reflashed” with the moded firmware and it works.

The first LD2410B was discovered in my office, where i have this bluethooth-proxy, so i suppose he is connect to this node? there is nothing in the logs of the bluethooth-proxy about the LD2410B…

What about if i put it in another room where there is another bluethooth-proxy? does it will connect to the new bluethooth-proxy or does it will provide a new device discovered?

If nobody have a answer, i will test.

Last question : is the OUT pin is capable to drain a led? Because i use a RGB led with green/red light to know visualy if the move/occupency is ok when i am in the same room. Thanks

EDIT : if you want to repair on another bluetooth proxy, you have to remove the integration for the device. Then it will be discovered on the other one or add manually work too.

Hey, since you seem to have it working with a d1 mini I’m wondering if you can help with my setup… I’m using the minimal examples from the esphome documentation and it’s still giving me unknown for the sensors. I know the device is working as I can see it in the bluetooth app. TX on the LD2410 is wired to RX on the d1 mini and RX on the LD2410 is wired to TX on the v3 d1_mini as per the above examples.

esphome:
  name: living_room_ld2410

# Enable Home Assistant API
api:

esp8266:
  board: d1_mini

logger:
  baud_rate: 0

ota:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  ap:
    ssid: "LD2410 Fallback Hotspot"

captive_portal:

uart:
  id: uart1
  tx_pin: 3
  rx_pin: 1
  baud_rate: 256000
  parity: NONE
  stop_bits: 1

ld2410:
  timeout: 150s
  max_move_distance : 6m
  max_still_distance: 0.75m
  g0_move_threshold: 10
  g0_still_threshold: 20
  g1_move_threshold: 10
  g1_still_threshold: 20
  g2_move_threshold: 20
  g2_still_threshold: 21
  g3_move_threshold: 30
  g3_still_threshold: 31
  g4_move_threshold: 40
  g4_still_threshold: 41
  g5_move_threshold: 50
  g5_still_threshold: 51
  g6_move_threshold: 60
  g6_still_threshold: 61
  g7_move_threshold: 70
  g7_still_threshold: 71
  g8_move_threshold: 80
  g8_still_threshold: 81

sensor:
  - platform: ld2410
    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

binary_sensor:
  - platform: ld2410
    has_target:
      name: Presence
    has_moving_target:
      name: Moving Target
    has_still_target:
      name: Still Target

Hello @burg93

i have 4 LD2410 (no BLE version) working, this is the version from the non official LD2410 but a custom one:

esphome:
  name: capteur-presence-dressing
  includes:
    - /config/esphome/custom_components/ld2410/ld2410_uart.h
  on_boot:
    priority: 600
    # ...
    then:
      - lambda: |-
          auto uart_component = static_cast<LD2410 *>(ld2410);
          uart_component->setNumbers(maxMovingDistanceRange, maxStillDistanceRange, noneDuration);

esp8266:
  board: d1_mini

# Enable logging
logger:
  level: WARN
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

ota:
  password: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_pwd
  manual_ip:
    static_ip: 192.168.1.96
    gateway: 192.168.1.1
    subnet: 255.255.255.0
    dns1: 192.168.1.1
  fast_connect: on
  power_save_mode: none

uart:
  id: uart1
  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]

status_led:
  pin:
    number: GPIO2 #ESP8266 OnBroad LED
    inverted: false

custom_component:
  - lambda: |-
      return {new LD2410(id(uart1))};
    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"
  - platform: gpio
    pin: D1
    name: "Dressing occupancy"
    id: dressing_occupancy
    device_class: occupancy
    on_press:
      then:
        - light.turn_on:
            id: led_presence_dressing
            brightness: 25%
            red: 100%
            green: 0%
            blue: 0%
    on_release:
      then:
        - light.turn_on:
            id: led_presence_dressing
            brightness: 25%
            red: 0%
            green: 100%
            blue: 0%

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
    initial_value: 4
    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
    initial_value: 4
    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
    initial_value: 5
    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);'
light:
  - platform: neopixelbus
    type: GRB
    variant: WS2812x
    pin: D2
    num_leds: 1
    name: "Led Presence Dressing"
    id: led_presence_dressing
    effects:
      - strobe:
      - addressable_rainbow:
      - addressable_scan:
      - addressable_twinkle:
      - addressable_random_twinkle:
      - addressable_fireworks:
      - addressable_flicker:

and this is the working one with LD2410 “official” in EspHome:

esphome:
  name: capteur-presence-sejournew
  friendly_name: capteur-presence-sejournew

external_components:
  - source: github://esphome/esphome@dev
    components: [ ld2410 ]  

esp8266:
  board: d1_mini
  

# Enable logging
logger:
  level: WARN
  baud_rate: 0
  
# Enable Home Assistant API
api:
  encryption:
    key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

ota:
  password: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_pwd
  manual_ip:
    static_ip: 192.168.1.88
    gateway: 192.168.1.1
    subnet: 255.255.255.0
    dns1: 192.168.1.1
  fast_connect: on
  power_save_mode: none

uart:
  id: uart1
  tx_pin: TX
  rx_pin: RX
  baud_rate: 256000
  parity: NONE
  stop_bits: 1

ld2410:
  timeout: 150s
  max_move_distance : 6m
  max_still_distance: 0.75m
  g0_move_threshold: 10
  g0_still_threshold: 20
  g1_move_threshold: 10
  g1_still_threshold: 20
  g2_move_threshold: 20
  g2_still_threshold: 21
  g3_move_threshold: 30
  g3_still_threshold: 31
  g4_move_threshold: 40
  g4_still_threshold: 41
  g5_move_threshold: 50
  g5_still_threshold: 51
  g6_move_threshold: 60
  g6_still_threshold: 61
  g7_move_threshold: 70
  g7_still_threshold: 71
  g8_move_threshold: 80
  g8_still_threshold: 81

status_led:
  pin:
    number: GPIO2 #ESP8266 OnBroad LED
    inverted: false
      
binary_sensor:
  - platform: ld2410
    has_target:
      name: Presence
    has_moving_target:
      name: Moving Target
    has_still_target:
      name: Still Target
  - platform: gpio
    pin: D1
    name: "Sejour occupancy"
    id: sejour_occupancy
    device_class: occupancy
    on_press:
      then:
        - light.turn_on:
            id: led_presence_sejour
            brightness: 25%
            red: 100%
            green: 0%
            blue: 0%
    on_release:
      then:
        - light.turn_on:
            id: led_presence_sejour
            brightness: 25%
            red: 0%
            green: 100%
            blue: 0%

sensor:
  - platform: ld2410
    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


light:
  - platform: neopixelbus
    type: GRB
    variant: WS2812x
    pin: D2
    num_leds: 1
    name: "Led Presence Sejour"
    id: led_presence_sejour
    effects:
      - strobe:
      - addressable_rainbow:
      - addressable_scan:
      - addressable_twinkle:
      - addressable_random_twinkle:
      - addressable_fireworks:
      - addressable_flicker:

both works great.

And for the BLE version, i dont tweak anything and it works out of the box! like the integration, so simple, so small! just need a 5V 200mA power supply and a special pitch connector with cable like this one : length 15cm, 10PCS 5P, 1.25MM Single head https://fr.aliexpress.com/item/1005003249553842.html?spm=a2g0o.order_list.order_list_main.280.10f45e5bcGOseQ&gatewayAdapt=glo2fra

2 Likes

Thanks, I can’t see any difference between mine and your “official” one so I suspect some dodgy soldering has been done. I’ll crack it back open and take a look :frowning:

Just to check… I’m pretty sure as I’ve seen this posted… wiring wise it’s TX to RX and RX to TX isn’t it.

1 Like

@burg93 buy this to avoid some dodgy soldering :wink: https://fr.aliexpress.com/item/1005003249553842.html?spm=a2g0o.order_list.order_list_main.280.10f45e5bcGOseQ&gatewayAdapt=glo2fra

1 Like

I don’t think I can face another 20 day wait but I’ll check Amazon/ebay thanks! I don’t think it’s the soldering as the power and ground are working fine, I guess there’s a chance the other two have come undone…

yes, crossed RX and TX between LD2410 and Wemos D1 mini

Do you buy direct from Shenzhen Hi-Link Electronic co.,Ltd Store ? https://fr.aliexpress.com/store/345286?spm=a2g0o.order_list.order_list_main.20.395e5e5b5YnVcK
the quality and the packaging are perfect, i had 6 LD2410 and 3 LD2410B and they working perfect…

EDIT : are you using 5V for VCC? 3.3V is not the good one power supply.

A lot of POST says to power up with 3.3V and i have a lot of problems at the begining because i follow this recommandation. Its definitively 5V power on the docs.

1 Like

Cool, got that right at least ha. That’s even with the pins defined in this order. 5V power from the mini.

Yeah bought direct, the board itself is working as I can access it via bluetooth in the app and it all reports fine. The blueooth range is pretty poor which is why I’m looking at connecting it up to the D1 mini (annoyingly) so I can position it the other side of the room.

tx_pin: TX
rx_pin: RX

Cable connections are all solid, no budge there and all are soldered well :frowning: Perhaps there’s an issue with the latest v3 D1 boards, I’ll try and dig up one of the older ones that I’ve seen a few pictured here.