LD2420 Configures but behaves strangely

As the title suggests I have configured a LD2420 24GHz radar presence sensor via ESPHome (which is running through the HomeAssistant add-on which is running on a Pi 3 1Gb).

Configuration

I have the sensor wired up with to ESP8266 (a NodeMCU 1.0) which is currently connected via USB to the Pi running home assistant.

I’m pretty much just using the boiler plate config for the LD2420 from the ESPHome website but here it is anyway:

esphome:
  name: office-presence
  friendly_name: Office_Presence

esp8266:
  board: esp01_1m

# Enable logging
logger:

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

ota:
  password: "redacted"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Office-Presence Fallback Hotspot"
    password: "redacted"

captive_portal:

# UART required to talk to LD2420 Presence sensor    
uart:
  tx_pin: GPIO1
  rx_pin: GPIO3
  baud_rate: 256000
  #baud_rate: 115200
  parity: NONE
  stop_bits: 1

ld2420: 

text_sensor:
  - platform: ld2420
    fw_version:
      name: LD2420 Firmware

sensor:
  - platform: ld2420
    moving_distance:
      name : Moving Distance

binary_sensor:
  - platform: ld2420
    has_target:
      name: Presence

switch:
  - platform: restart
    name: Restart ESPHome Node

select:
  - platform: ld2420
    operating_mode:
      name: Operating Mode

number:
  - platform: ld2420
    presence_timeout:
      name: Detection Presence Timeout
    min_gate_distance:
      name: Detection Gate Minimum
    max_gate_distance:
      name: Detection Gate Maximum
    gate_select:
      name: Select Gate to Set
    still_threshold:
      name: Set Still Threshold Value
    move_threshold:
      name: Set Move Threshold Value
button:
  - platform: ld2420
    apply_config:
      name: Apply Config
    factory_reset:
      name: Factory Reset
    restart_module:
      name: Restart Module
    revert_config:
      name: Undo Edits

Troubleshooting

Serial port

  1. Finding the Tx pin
    Since there appear to be two different pinnouts depending on the firmware running on the sensor itself I probed it under power with my oscilloscope for serial traffic. I found serial traffic on the OT2 pin so presumably I have a module with firmware >=1.5.3.

  2. Checking the baud rate
    There are two different baud rates in the yaml because I had seen other peoples configs with 115200 even through the manufacturer’s documentation says 256000 (see page 14).

So I tried both and if I use 115200 I get an error early in the install log saying that the HLK module failed to respond. If I do 256000 no such error.

  1. Checking I have Tx & Rx wired correctly
    I did flip Tx/Rx just to confirm I had them correctly.

  2. I did try hooking it up to tio on my linux dekstop via a UART to USB convert but got radio silence.

What does work

The sensor shows up in HA. I’m able to add it to a zone no problem and dump all of the parameters onto a card:

I do get info via the logs but…

The Strangeness

Nothin’ but bytes on the serial terminal

The logs all appear to be byte data? Or am I seeing Unicode?
For example:

[21:51:36]\x9d\xf0W!I@\xa8ޭ\x80ف\x9b\x9a\xb0\xabᗐ\xa1)64\xad\xeb\xc1\x97\xcer' \x9b\xb0Z\xfd\x93""T
[21:51:36]\x89\xb2\xd3`Z\xfd\x93""*

If I change parameters on the HA widget I do see more traffic on the log.
Should I be seeing raw byte traffic?

The GUI will not set to anything but Operating Mode: Simple

No matter what I do, whenever I try to change the operating mode from Simple to anything else (Calibrate or Normal). It immediately flips back to Simple before I can hit the button to Apply the settings.

No useful data seems to be coming back

None of the data the sensor is suppose to report back seems to be making it into HA (everything shows as unknown). Given that I can’t get it into calibration mode this isn’t entirely surprising.

I’m not sure how to proceed further with debugging as I’m not actually sure what I should expect to see from the sensor in the first place.
If others have first hand experience with a working sensor I’d love to know how it should be behaving.

Edit:
Right after making this post I swapped over to the second sensor module I have and on boot got a much clearer message on the logs that included this:

[22:10:23][W][uart.arduino_esp8266:143]:   You're using the same serial port for logging and the UART component. Please disable logging over the serial port by setting logger->baud_rate to 0.

I had forgotten how limited the ESP8266’s serial capabilities are.
I did do a quick test where I disabled the logger to see if I could get anything other than “Unknown” from the sensor in HA but no beans. Everything is still unknown.

I will have to try an ESP32 tomorrow since the second serial port on the 8266 is transmit only.

Alright, it seems the RPi 3 I’m running HA on just doesn’t have the juice to program an ESP32 via the ESPHome add-on. It seems like the supervisor is killing the process at the linking stage.

So I resorted to spinning up a docker container on my desktop PC and programming it that way. The ESP32 gets onto the main network (with the hostname I set in the yaml) however, I can’t seem to get HA to pair with it.

If I go Settinngs>Config>Devices>Add-device>ESPHome I get this:

The yaml I used to program the ESP32 does have the API line (it’s the same yaml as above just with ESP8266 swapped out for 32) along with a key but I am never presented with an opportunity to enter that key. I have double checked that the API is connect and both devices are definitely on the same network.

Am I missing something here? Is there a gotcha when it comes to programming with ESPHome from a computer that isn’t the HA node? When I flash the ESP I don’t see anything in the logs that would indicate an issues but HA doesn’t seem to find the device.

I have similar problems albeit with an ESP32-WROOM. Neither the 1.5.3 configuration nor 1.5.4 version of wiring and baud rate seem to work. No firmware version is detected and the operating mode setting snaps back immediately.

Did you ever figure this out? I’m having the same issue, and have tried different LD2420 modules on both esp8266 and esp32 boards, using both the 1.5.3 and 1.5.4 configs, and neither seems to work

I did but it seems to stop working randomly (no firmware version detected/empty string) but works again after a complete power cycle.

My setup right now is Dupont wires on a solderless breadboard so I suspect that moving out around causes things to disconnect at different times which messes up the serial communication.

I haven’t pinpointed it but that’s my guess so far.