LD2410C 'Presence sensor' settings get reset when powered off

Hi

I’m trying to use a LD2410 Humand Presence Sensor, but its movement and static threshold values get reset to zero every time I power cycle it.

The values don’t go back to the factory settings, all the thresholds get set to zero

Here is my YAML

esphome:
    name: ld2410-esp32
    friendly_name: Motion Sensor LED
  # ...
 
            
esp32:
  variant: esp32s3
  framework:
    type: esp-idf

# Enable logging
logger:
    level: DEBUG
# Enable Home Assistant API
api:

ota:
  - platform: esphome
    password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  
  
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:

captive_portal:



  
  
light:

  - platform: monochromatic
    name: "White Light"
    output: light_output_white
    id: white_light 
    
 
output:
  - platform: ledc
    pin: GPIO8
    id: light_output_white


 
uart:
  id: ld2410_uart
  tx_pin: GPIO17
  rx_pin: GPIO18
  baud_rate: 256000
  parity: NONE
  stop_bits: 1
 
ld2410:
  uart_id: ld2410_uart
  #throttle: 1500ms
  id: ld2410_comp

 
select:
  - platform: ld2410
    distance_resolution:
      name: distance resolution
    baud_rate:
      name: baud rate
    light_function:
      name: light function
    out_pin_level:
      name: out pin level
 
button:
  - platform: ld2410
    factory_reset:
      name: "factory reset"
    restart:
      name: "restart"
    query_params:
      name: query params
 
number:
  - platform: ld2410
    timeout: 
      name: "Timeout"
      id: ld2410_timeout

    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
    light_threshold:
      name: light threshold
 
text_sensor:
  - platform: ld2410
    version:
      name: "presenece sensor version"
    mac_address:
      name: "presenece sensor mac address"
 
switch:
  - platform: ld2410
    engineering_mode:
      name: "engineering mode"
    bluetooth:
      name: control Bluetooth
    
 
sensor:
  - platform: ld2410
    moving_distance:
      # internal: true
      name: "Moving distance (cm)"
    still_distance:
      # internal: true
      name: "Still Distance (cm)"
    moving_energy:
      # internal: true
      name: "Move Energy (%)"
    still_energy:
      # internal: true
      name: "Still Energy (%)"
    detection_distance:
      # internal: true    
      name: "Distance Detection (cm)"
    g0:
      move_energy:
        # internal: true
        name: g0 move energy
      still_energy:
        # internal: true   
        name: g0 still energy
    g1:
      move_energy:
        # internal: true         
        name: g1 move energy
      still_energy:
        # internal: true         
        name: g1 still energy
    g2:
      move_energy:
        # internal: true         
        name: g2 move energy
      still_energy:
        # internal: true         
        name: g2 still energy
    g3:
      move_energy:
        # internal: true         
        name: g3 move energy
      still_energy:
        # internal: true         
        name: g3 still energy
    g4:
      move_energy:
        # internal: true         
        name: g4 move energy
      still_energy:
        # internal: true   
        name: g4 still energy
    g5:
      move_energy:
        # internal: true   
        name: g5 move energy
      still_energy:
        # internal: true   
        name: g5 still energy
    g6:
      move_energy:
        # internal: true   
        name: g6 move energy
      still_energy:
        # internal: true         
        name: g6 still energy
    g7:
      move_energy:
        # internal: true         
        name: g7 move energy
      still_energy:
        # internal: true         
        name: g7 still energy
    g8:
      move_energy:
        # internal: true   
        name: g8 move energy
      still_energy:
        # internal: true   
        name: g8 still energy
    light:
      name: light
      # internal: true   

 
binary_sensor:

  - platform: gpio
    pin: GPIO9
    id: ld2410_gpio_out
           
              
  - platform: ld2410
    has_target:
      name: Presence
      on_press:
        then:
          light.turn_on: 
            id: white_light
            brightness: 100%
            transition_length: 0s

      on_release:
        then:
          light.turn_off:
            id: white_light
            transition_length: 0s

    
    has_moving_target:
      # internal: true
      name: Moving Target

    has_still_target:
      name: Still Target
      # internal: true
    out_pin_presence_status:
      name: Out Pin Status
      id: ld2410_out_pin
      

Initiallu I thought it was because I had set the current energy values as ‘internal’ to stop them being displayed on the HA dashboard, but even enabling these again, didn’t fix the problem.

The code is virtually the same as all the boilerplate code for this device that other people have posted e.g. as gists, except I am turning a ‘light’ on and off based on the ‘has_target’ property

Surely its not necessary to set all these values in code, in the on_boot section ?

I would comment out the factory reset button code for now, just in case that is getting triggered somehow.
What does the debug logs say?

After some experimentation, it seems that the HA config page for the LD2410, is not initially querying the device, and hence displays zero on all sliders

However, if I press the ‘Query Parameters’ button on the Diagnostic panel

Then all the sliders get updated with the correct values.

So IMO this seems to be a bug in the HA side of things, because when the ‘Device info’ page on the HA server is loaded, it should automatically query the device paramaters.

I thought because the device was not working correctly, that the problem was that the config sliders were being reset, but this doesn’t seem to be the case.

I’ll see if I can post a bug report for the parameters not being queried, but I’m not sure where to post the bug on GitHub, i.e is this bug in HA or EspHome, or perhaps the ESPHome repo contains the HA HTML display code etc???

To answer my own question.

If you add this to the YAML

  on_boot:
    - priority: 600
      then:
        lambda: return(id(ld2410_comp).restart_and_read_all_info());

It forces the code to read the parameters from the device.

i.e this looks like a bug in the ESPHome code, as HA must just be requesting teh parameters, but the ESPHome device itself has not populated these values.

I will post this as a potential bug