Esphome hlk-ld2410

hi
i am using esp32 with hlk-ld2410. i hv installed it in remote location from where i want to turn on an switch when presence detected or movement detected. i dont want to use home assistant automation. here is my code

captive_portal:

   

uart:

  id: ld2410uart

  tx_pin: 17

  rx_pin: 16

  baud_rate: 256000

  parity: NONE

  stop_bits: 1

ld2410:

  uart_id: ld2410uart

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

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

binary_sensor:

 

  - platform: ld2410

    has_target:

      name: Male Washroom Presence

      id: Male_Washroom_Presence

             

    has_moving_target:

      name: Male Washroom Moving Target

      id: Male_Washroom_Moving_Target

     

    has_still_target:

      name: Male Washroom Still Target

      id: Male_Washroom_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

 

  - platform: template

    id: sys_esp_temperature

    name: Male Washroom ESP Temperature

    lambda: return temperatureRead();

    unit_of_measurement: °C

    device_class: TEMPERATURE

    update_interval: 5s

    entity_category: "diagnostic"

  - platform: uptime

    name: Male Washroom Uptime

    id: sys_uptime

    update_interval: 10s

  - platform: wifi_signal

    name: Male Washroom  RSSI

    id: wifi_signal_db

    update_interval: 5s

    entity_category: "diagnostic"

  - platform: template

    id: esp_memory

    icon: mdi:memory

    name: Male Washroom ESP Free Memory

    lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;

    unit_of_measurement: 'kB'

    state_class: measurement

    entity_category: "diagnostic"

time:

  - platform: sntp

    id: time_sntp

switch:

  - platform: ld2410

    engineering_mode:

      name: Engineering Mode

    bluetooth:

      name: Control Bluetooth

  - platform: gpio

    id: male_washroom_relay

    name: Male Washroom relay

    pin: 18


button:

  - platform: ld2410

    factory_reset:

      name: Factory Reset

    restart:

      name: Restart

    query_params:

      name: Query Params

 

  - platform: restart

    icon: mdi:power-cycle

    name: "ESP Reboot"

text_sensor:

  - platform: ld2410

    version:

      name: Firmware Version

    mac_address:

      name: MAC 

i want to turn on on switch: male_washroom_relay if ld2410 detected presence or movement and turn it off if not detected anything

I don’t have one of these to test (on order…) but something like this should turn on the relay when presence detected, then turn off the relay 6 seconds after no presence detected.

binary_sensor:
  - platform: ld2410
    has_target:
      name: Male Washroom Presence
      id: male_washroom_presence
      filters:
         - delayed_off: 6s
      on_press:
        then:
          - switch.turn_on: male_washroom_relay
      on_release:
        then:
          - switch.turn_off: male_washroom_relay
1 Like

thanks for replaying but with this code i got an error, i want any one out of three conditions comes true male_washroom_relay turn on. its works but problem is when any one out of these three stop detection it turn of switch

1 Like

i need the same to do in esphome! any suggestions?