Build a mmWave motion sensor and light sensor with ESPHome

I got a Bambu A1 3d printer a while back and finally put it to good use for this project. I changed almost all motion sensors in the house with this mmWave motion sensor because it has better presence detection than tradition PIR sensor.

Materials

Connect LD2410C motion sensor to the ESP32 board

  • VCC to VIN (#1)
  • GND to GND (#2)
  • TX to RX2 (#6 GPIO16)
  • RX to TX2 (#7 GPIO17)

Connect BH1750 light sensor to the ESP32 board

  • VCC to 3.3V (#1)
  • GND to GND (#2)
  • DAT to SDA (#11 GPIO21)
  • SCL to SCL (#14 GPIO22)
  • ignore ADDR wire (can be cut off)

Software installation

  • Use https://web.esphome.io to install the initial image and connect the device to wifi.
  • Install ESPHome Device Builder as the interface to customize the ESP32 board. See yaml file below.
  • Click Install in the Device Builder to build the image and install it on the ESP32 board. Once it’s installed and connected to wifi, Home Assistant should show it on the Discovery page and be available to add.
#change name to something unique. friendly_name is optional but best to have it
esphome:
  name: ld2410c-bh1750-379a08
  friendly_name: LD2410C BH1750 379a08

esp32:
  board: esp32dev
  framework:
    type: esp-idf

# Enable logging
logger:

# Enable Home Assistant API
api:

# Allow Over-The-Air updates
ota:
- platform: esphome

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

web_server:
  port: 80

ld2410:

uart:
  tx_pin: GPIO17
  rx_pin: GPIO16
  baud_rate: 256000
  parity: NONE
  stop_bits: 1
i2c:
  sda: GPIO21
  scl: GPIO22
  scan: true
  id: bus_a

select:
  - platform: ld2410
    distance_resolution:
      name: Distance Resolution
    baud_rate:
      name: Baud Rate
    light_function:
      name: Light Function

switch:
  - platform: ld2410
    engineering_mode:
      name: Engineering Mode
    bluetooth:
      name: Control Bluetooth

number:
  - platform: ld2410
    timeout:
      name: Radar Timeout
    light_threshold:
      name: Light Threshold
    max_move_distance_gate:
      name: Max Move Distance
    max_still_distance_gate:
      name: Max Still Distance
    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

binary_sensor:
  - platform: ld2410
    has_target:
      name: Presence
    has_moving_target:
      name: Moving Target
    has_still_target:
      name: 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: bh1750
    name: "BH1750 Illuminance"
    address: 0x23
    update_interval: 30s