mmWave Target Tracking - fully customized ESPHome support!

Wait what? I have 18 ESP32’s and every single one of them will let me configure UART RX/TX incorrectly and still boot fine. Can’t help you there.

uart:

Not with mine, for some reason… :slight_smile:

You agree that RX/TX works since I can enable/disable detection?

Disagree. detection_enabled is what controls the “give me target data” requests from the ESP to the K-LD7. When you turn it off, no requests are sent to the sensor. When you turn it on, requests are sent.

You need a working UART configuration for all of that to happen work as expected. That not only includes “my config compiles,” but that it is wired appropriately as well.

Perhaps a picture of your wiring may help.

[edit] - clarity

As you can see, I use the default TX (GPIO1) & RX (GPIO3) from ESP32 Wemos D1 Mini.
Btw; the GND looks red but are actually purple - not to be confused.

YELLOW - VCC
WHITE - GND
PURPLE - PULLDOWN
BLUE - RX (ESP)
GREEN - TX (ESP)

Indeed you’re right, I have problems receiving UART debugging…

Code:

esphome:
  name: rfbeam
  on_boot:
    priority: 700
    then:
      - wait_until: 
            api.connected:
      - script.execute: get_all_params_script
      - switch.template.publish:
          id: detection_enabled
          state: ON
      - switch.template.publish:
          id: enable_logging
          state: OFF          

  includes:
    - kld7.h
    
esp32:
  board: esp32dev
  framework:
    type: arduino

substitutions:
  device_name: rfbeam

button:
  - platform: restart
    name: Restart $device_name  
  
  - platform: template
    name: factory_reset_kld7 # RFSE
    id: factory_reset_kld7
    on_press:
      - uart.write: [0x52, 0x46, 0x53, 0x45, 0x00, 0x00, 0x00, 0x00]
      - delay: 2s
      - uart.write: [0x49,0x4E,0x49,0x54,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00] # perform kld7 INIT

  - platform: template
    name: get_all_params # GRPS
    id: get_all_params
    on_press:
      - script.execute: get_all_params_script

script:
  - id: get_all_params_script
    then:
      - uart.write: [0x47, 0x52, 0x50, 0x53, 0x00, 0x00, 0x00, 0x00]

web_server:
  port: 80
  version: 2
  include_internal: true
  ota: false

# Enable logging
logger:
  # baud_rate: 0 # disable logging over uart
  logs:
    sensor: ERROR

# Enable Home Assistant API
api:

mdns:
  disabled: false

ota:
  password: "yadda"

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

switch:
  - platform: safe_mode
    name: use_safe_mode $device_name

  - platform: template
    name: enable_logging
    id: enable_logging
    optimistic: true

  - platform: template
    name: detection_enabled
    id: detection_enabled
    optimistic: true
    restore_state: true
    turn_on_action:
      - uart.write: [0x49,0x4E,0x49,0x54,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00] # perform kld7 INIT
      - logger.log: "INIT sent"
    turn_off_action:
      - uart.write: [0x47, 0x42, 0x59, 0x45, 0x00, 0x00, 0x00, 0x00] # perform kld7 GBYE

number:
  - platform: template
    name: WLED_return_to_normal
    id: WLED_return_to_normal
    min_value: 1
    max_value: 15
    initial_value: 1
    step: 1
    restore_value: true
    optimistic: true

  - platform: template
    name: LEDs_per_Meter
    id: LEDs_per_Meter
    min_value: 30
    max_value: 144
    initial_value: 60
    step: 1
    restore_value: true
    optimistic: true
    mode: box

  - platform: template
    name: distance_offset
    id: distance_offset
    min_value: -255
    max_value: 255
    initial_value: 0
    step: 1
    restore_value: true
    unit_of_measurement: cm
    optimistic: true
    mode: box

  - platform: template
    name: max_speed # RSPI 0 = 12.5km/h, 1 = 25km/h, 2 = 50km/h, 3 = 100km/h
    id: max_speed
    min_value: 0
    max_value: 3
    initial_value: 1
    step: 1
    restore_value: true
    unit_of_measurement: kph
    set_action:
      - uart.write: !lambda
          return {0x52, 0x53, 0x50, 0x49, 0x04, 0x00, 0x00, 0x00, (unsigned char)x, 0x00, 0x00, 0x00};

  - platform: template
    name: max_range # RRAI 0 = 5m, 1 = 10m, 2 = 30m, 3 = 100m
    id: max_range
    min_value: 0
    max_value: 3
    initial_value: 1
    step: 1
    restore_value: true
    set_action:
      - uart.write: !lambda
          return {0x52, 0x52, 0x41, 0x49, 0x04, 0x00, 0x00, 0x00, (unsigned char)x, 0x00, 0x00, 0x00};

  - platform: template
    name: threshold_offset # THOF 10-60 dB
    id: threshold_offset
    min_value: 10
    max_value: 60
    initial_value: 30
    step: 1
    restore_value: true
    unit_of_measurement: dB
    set_action:
      - uart.write: !lambda
          return {0x54, 0x48, 0x4F, 0x46, 0x04, 0x00, 0x00, 0x00, (unsigned char)x, 0x00, 0x00, 0x00};

  - platform: template
    name: tracking_filter # TRFT 0 = Standard, 1 = Fast detection, 2 = Long visibility
    id: tracking_filter
    min_value: 0
    max_value: 2
    initial_value: 0
    step: 1
    restore_value: true
    set_action: 
      - uart.write: !lambda
          return {0x54, 0x52, 0x46, 0x54, 0x04, 0x00, 0x00, 0x00, (unsigned char)x, 0x00, 0x00, 0x00};

  - platform: template
    name: vibration_suppression # VISU 0-16, 0 = No suppression, 16 = High suppression
    id: vibration_suppression
    min_value: 0
    max_value: 16
    initial_value: 2
    step: 1
    restore_value: true
    set_action:
      - uart.write: !lambda
          return {0x56, 0x49, 0x53, 0x55, 0x04, 0x00, 0x00, 0x00, (unsigned char)x, 0x00, 0x00, 0x00};

  - platform: template
    name: min_detection_dist # MIRA
    id: min_detection_dist
    min_value: 0
    max_value: 100
    initial_value: 0
    step: 1
    restore_value: true
    unit_of_measurement: "%"
    mode: box
    set_action:
      - uart.write: !lambda
          return {0x4d, 0x49, 0x52, 0x41, 0x04, 0x00, 0x00, 0x00, (unsigned char)x, 0x00, 0x00, 0x00};
          
  - platform: template
    name: max_detection_dist # MARA
    id: max_detection_dist
    min_value: 0
    max_value: 100
    initial_value: 50
    step: 1
    restore_value: true
    unit_of_measurement: "%"
    mode: box
    set_action:
      - uart.write: !lambda
          return {0x4d, 0x41, 0x52, 0x41, 0x04, 0x00, 0x00, 0x00, (unsigned char)x, 0x00, 0x00, 0x00};

  - platform: template
    name: min_detection_angle # MIAN -90° to +90°
    id: min_detection_angle
    min_value: -90
    max_value: 90
    initial_value: -90
    step: 1
    restore_value: true
    unit_of_measurement: "°"
    mode: box
    set_action:
      - uart.write: !lambda
          return {0x4d, 0x49, 0x41, 0x4e, 0x04, 0x00, 0x00, 0x00, (unsigned char)x, 0x00, 0x00, 0x00};

  - platform: template
    name: max_detection_angle # MAAN -90° to +90°
    id: max_detection_angle
    min_value: -90
    max_value: 90
    initial_value: 90
    step: 1
    restore_value: true
    unit_of_measurement: "°"
    mode: box
    set_action:
      - uart.write: !lambda
          return {0x4d, 0x41, 0x41, 0x4e, 0x04, 0x00, 0x00, 0x00, (unsigned char)x, 0x00, 0x00, 0x00};

  - platform: template
    name: min_detection_speed # MISP 0 – 100% of speed setting
    id: min_detection_speed
    min_value: 0
    max_value: 100
    initial_value: 0
    step: 1
    restore_value: true
    unit_of_measurement: "%"
    mode: box
    set_action:
      - uart.write: !lambda
          return {0x4d, 0x49, 0x53, 0x50, 0x04, 0x00, 0x00, 0x00, (unsigned char)x, 0x00, 0x00, 0x00};

  - platform: template
    name: max_detection_speed # MASP 0 – 100% of speed setting
    id: max_detection_speed
    min_value: 0
    max_value: 100
    initial_value: 100
    step: 1
    restore_value: true
    unit_of_measurement: "%"
    mode: box
    set_action:
      - uart.write: !lambda
          return {0x4d, 0x41, 0x53, 0x50, 0x04, 0x00, 0x00, 0x00, (unsigned char)x, 0x00, 0x00, 0x00};

  - platform: template
    name: detection_direction # DEDI 0 = Receding, 1 = Approaching, 2 = Both
    id: detection_direction
    min_value: 0
    max_value: 2
    initial_value: 2
    step: 1
    restore_value: true
    set_action:
      - uart.write: !lambda
          return {0x44, 0x45, 0x44, 0x49, 0x04, 0x00, 0x00, 0x00, (unsigned char)x, 0x00, 0x00, 0x00};

  - platform: template
    name: range_threshold # RATH 0 – 100% of range setting
    id: range_threshold
    min_value: 0
    max_value: 100
    initial_value: 10
    step: 1
    restore_value: true
    unit_of_measurement: "%"
    mode: box
    set_action:
      - uart.write: !lambda
          return {0x52, 0x41, 0x54, 0x48, 0x04, 0x00, 0x00, 0x00, (unsigned char)x, 0x00, 0x00, 0x00};
          
  - platform: template
    name: angle_threshold # ANTH -90° to +90°
    id: angle_threshold
    min_value: -90
    max_value: 90
    initial_value: 0
    step: 1
    restore_value: true
    unit_of_measurement: "°"
    mode: box
    set_action:
      - uart.write: !lambda
          return {0x41, 0x4e, 0x54, 0x48, 0x04, 0x00, 0x00, 0x00, (unsigned char)x, 0x00, 0x00, 0x00};

  - platform: template
    name: speed_threshold # SPTH 0 – 100% of speed setting
    id: speed_threshold
    min_value: 0
    max_value: 100
    initial_value: 50
    step: 1
    restore_value: true
    unit_of_measurement: "%"
    mode: box
    set_action:
      - uart.write: !lambda
          return {0x53, 0x50, 0x54, 0x48, 0x04, 0x00, 0x00, 0x00, (unsigned char)x, 0x00, 0x00, 0x00};

  - platform: template
    name: hold # HOLD 0 – 7200s 484f4c44
    id: hold
    min_value: 1
    max_value: 7200
    initial_value: 1
    unit_of_measurement: sec
    step: 1
    restore_value: true
    mode: box
    set_action:
      - uart.write: !lambda
          return {0x48, 0x4f, 0x4c, 0x44, 0x04, 0x00, 0x00, 0x00, (unsigned char)x, 0x00, 0x00, 0x00};

sensor:
  - platform: custom
    lambda: |-
      auto s = new kld7(id(uart_bus0));
      App.register_component(s);
      return {s->distance_sensor, s->speed_sensor, s->angle_sensor, s->db_sensor};
      
    sensors:
    - name: distance_sensor
      id: distance_sensor
      internal: false
      unit_of_measurement: cm
    - name: speed_sensor
      id: speed_sensor
      internal: true
      unit_of_measurement: kph
    - name: angle_sensor
      id: angle_sensor
      internal: false
      unit_of_measurement: deg
    - name: db_sensor
      id: db_sensor
      internal: true
      unit_of_measurement: dB

uart:
  id: uart_bus0
  tx_pin: GPIO01
  rx_pin: GPIO03
  baud_rate: 115200
  parity: EVEN
  debug:
    direction: RX
    after:
      delimiter: [0x52, 0x45, 0x53, 0x50, 0x01, 0x00, 0x00, 0x00, 0x00] 
    sequence:
      - lambda: UARTDebug::log_hex(direction, bytes, ':');
        
binary_sensor:
  - platform: gpio
    name: kld7_detection
    id: kld7_detection
    pin:
      number: GPIO16
      mode: INPUT_PULLDOWN
    on_state:
      then:
        while:
          condition:
            - binary_sensor.is_on: kld7_detection
            - switch.is_on: detection_enabled
          then:
            - uart.write: [0x47,0x4E,0x46,0x44,0x04,0x00,0x00,0x00,0x08,0x00,0x00,0x00] # Get TDAT
            - delay: !lambda
                if (id(max_speed).state == 0) {
                  return 250;
                } else if (id(max_speed).state == 1) {
                  return 125;
                } else if (id(max_speed).state == 2) {
                  return 65;
                } else if (id(max_speed).state == 3) {
                  return 35;
                } else {
                  return 250;
                }

kld7.h has not been modified.




Here is your hint :wink:

Do you see the conflict?

Changed the config:

uart:
  id: uart_bus0
  tx_pin: GPIO16
  rx_pin: GPIO17
  baud_rate: 115200
  parity: EVEN
  debug:
    direction: RX
    after:
      delimiter: [0x52, 0x45, 0x53, 0x50, 0x01, 0x00, 0x00, 0x00, 0x00] 
    sequence:
      - lambda: UARTDebug::log_hex(direction, bytes, ':');

# Enable logging
logger:
  # baud_rate: 0 # disable logging over uart
  logs:
    sensor: DEBUG

All good :slight_smile:
Thank you @crlogic

Once you have confirmed target data being received I would recommend disabling the UART debug and setting sensor logging to INFO in order to prevent the ESP from being swamped and potentially resetting.

1 Like

can you report on the differences? ie if my wife has a different resting heart vs me (via esphome)?

K-LD7 does not measure heart rate.

but can you report on the different subjects consistently?

What does ‘report’ mean to you? This is not an occupancy sensor.

It reports distance, angle, speed reliably. It doesn’t do that for “static” things. Only moving things within the vast number of configuration parameters.

I would recommend reviewing the datasheet for a better understanding of the parameters.

For that you need to look at the Seeed 60GHz Heart and Breath version…

Think I will make some adjustments. When binary_sensor.kld7_detection are off, the state of the sensors remains what was last registered. When it goes to off, they should be ‘reset’ to 0. Don’t you agree?

Think I will make a doll’s head follow me when I walk in and through the room, should be piece of cake and a fun start using the angle detection.

Makes sense. You could implement a lambda that clears all values.

Eg.

    on_state:
      then:
        - if:
            condition:
              - binary_sensor.is_off: kld7_detection
            then:
              - lambda: |-
                  id(distance_sensor).publish_state(0);
                  id(speed_sensor).publish_state(0);

I think you are onto something. The perfect Halloween display! The eyes glow red right?? :astonished:

Link perhaps? does it work w/ esphome?

Seriously? It is the first google entry if you search for < Seeed 60GHz Heart and Breath >

1 Like

seriously? cant answer both questions??? mainly curious about my last question…

Please keep it civil folks.

The interface is serial, and documented.

1 Like

Hi David,

I see you got the link.
I’ve only tested these with ESP32 and Arduino, but with some work it will work with ESPHome,
Unfortunately I will not have the time to do this in the near future.