mmWave Presence Detection - ESPHome style

Ah, I’ve never heard of that one. Looks like there’s one for 100€ on ali express, that is not cheap

Nice catch. I suspect that is a random seller. Their ODM pricing for other products appeared much better than that.

I also suspect that the same mmwave sensor is used since the same parameters are described in the user manual.

I cannot speak for the Zigbee implementation, which as you rightly indicated, can make or break the usefulness of a device as a whole.

Yeah the ZCL is big and complicated, it’s not trivial to implement and a lot of devices aren’t that smart sadly.
I’m hopefull someone will implement something usable for the the ESP H2 if and when it comes out, I’d love to have ESPHome or something similar for Zigbee

I’m with ya there!

Have you tried this? https://ptvo.info/

Just did some more AliExpress browsing and there appears to be a 3X markup on other Leapmmw products compared to even individual pricing direct from Leapmmw.

I hadn’t heard of ptvo, that looks neat. I wonder if you could link a cc2530 to an esp, connect the mmwave uart to the esp with your code to handle all the config but then connect IO2 to the cc, to then bind it directly to the light group.
Might be worth a try, thanks for the tip !

Hoping someone here can help me. I was able to set up the mmwave sensor with a couple other sensors to hopefully create a sensor for my office. It looks like the sensor is detecting presence in the logs but for some reason the binary sensor in home assistant is stuck in the on position. Someone else suggested I make a template sensor from the log information, but honestly I have no idea how to do that… plus I dont understand why its is working in the logs but not in practice… Any help would be great! Thank you!

esphome:
  name: mmwave

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: ""

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

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

captive_portal:

web_server:
  port: 80
  version: 2
  include_internal: true

http_request:
  useragent: esphome/$device_name
  timeout: 2s

i2c:
 sda: 21
 scl: 22
 scan: true
 id: bus_a
 
mdns:
  disabled: false
  
switch:
  - platform: safe_mode
    internal: true
    name: use_safe_mode

  - platform: template
    name: "mmwave_sensor"
    id: "mmwave_sensor"
    optimistic: true
    restore_state: true
    assumed_state: true
    turn_on_action:
      - uart.write: "sensorStart"
      - delay: 1s
    turn_off_action:
      - uart.write: "sensorStop"
      - delay: 1s
    
  - platform: template
    name: "LED"
    id: "led"
    optimistic: true
    restore_state: true
    assumed_state: true
    turn_on_action:
      - switch.turn_off: mmwave_sensor
      - delay: 1s
      - uart.write: "setLedMode 1 0"
      - delay: 1s 
      - uart.write: "saveConfig"
      - delay: 3s
      - switch.turn_on: mmwave_sensor 
    turn_off_action:
      - switch.turn_off: mmwave_sensor
      - delay: 1s
      - uart.write: "setLedMode 1 1"
      - delay: 1s      
      - uart.write: "saveConfig"
      - delay: 3s
      - switch.turn_on: mmwave_sensor     
      
  - platform: template
    name: "uart_presence_output"
    id: "uart_presence_output"
    optimistic: true
    restore_state: true
    assumed_state: true
    turn_on_action:
      - switch.turn_off: mmwave_sensor
      - delay: 1s
      - uart.write: "setUartOutput 1 1"
      - delay: 1s 
      - uart.write: "saveConfig"
      - delay: 3s
      - switch.turn_on: mmwave_sensor 
    turn_off_action:
      - switch.turn_off: mmwave_sensor
      - delay: 1s
      - uart.write: "setUartOutput 1 0"
      - delay: 1s      
      - uart.write: "saveConfig"
      - delay: 3s
      - switch.turn_on: mmwave_sensor     
      
  - platform: template
    name: "uart_target_output"
    id: "uart_target_output"
    optimistic: true
    restore_state: true
    assumed_state: false
    turn_on_action:
      - switch.turn_off: mmwave_sensor
      - delay: 1s
      - uart.write: "setUartOutput 2 1 1 1"
      - delay: 1s 
      - uart.write: "saveConfig"
      - delay: 3s
      - switch.turn_on: mmwave_sensor 
    turn_off_action:
      - switch.turn_off: mmwave_sensor
      - delay: 1s
      - uart.write: "setUartOutput 2 0"
      - delay: 1s      
      - uart.write: "saveConfig"
      - delay: 3s
      - switch.turn_on: mmwave_sensor       

binary_sensor:
- platform: gpio
  name: mmwave_in_office
  pin:
    number: GPIO22
    mode: INPUT_PULLDOWN

uart:
  id: uart_bus
  tx_pin: GPIO17
  rx_pin: GPIO16
  baud_rate: 115200
  debug:
    direction: BOTH
    dummy_receiver: true
    after:
      delimiter: "\n"
    sequence:
      - lambda: UARTDebug::log_string(direction, bytes);

number:
  - platform: template
    name: distance
    id: distance
    min_value: 0
    max_value: 1350
    initial_value: 315
    optimistic: true
    step: 15
    restore_value: true
    unit_of_measurement: cm
    mode: box
    set_action:
      - switch.turn_off: mmwave_sensor
      - delay: 1s
      - uart.write: !lambda
                      int cm = (int)ceil(x / 15.0);
                      std::string cms = "detRangeCfg -1 0 " + to_string(cm);
                      return std::vector<unsigned char>(cms.begin(), cms.end());
      - delay: 1s
      - uart.write: "saveCfg 0x45670123 0xCDEF89AB 0x956128C6 0xDF54AC89"
      - delay: 1s
      - switch.turn_on: mmwave_sensor  
      
  - platform: template
    name: latency
    id: latency
    min_value: 0
    max_value: 65000
    initial_value: 12500
    optimistic: true
    step: 25
    restore_value: true
    unit_of_measurement: ms
    mode: box
    set_action:
      - switch.turn_off: mmwave_sensor
      - delay: 1s
      - uart.write: !lambda
                      int ms = (int)ceil(x / 25.0);
                      std::string mss = "outputLatency -1 0 " + to_string(ms);
                      return std::vector<unsigned char>(mss.begin(), mss.end());
      - delay: 1s
      - uart.write: "saveCfg 0x45670123 0xCDEF89AB 0x956128C6 0xDF54AC89"
      - delay: 1s
      - switch.turn_on: mmwave_sensor    

  - platform: template
    name: sensitivity
    id: sensitivity
    min_value: 0
    max_value: 9
    initial_value: 7
    optimistic: true
    step: 1
    restore_value: true
    set_action:
      - switch.turn_off: mmwave_sensor
      - delay: 1s
      - uart.write: !lambda
                      std::string mss = "setSensitivity " + to_string((int)x);
                      return std::vector<unsigned char>(mss.begin(), mss.end());
      - delay: 1s
      - uart.write: "saveConfig"
      - delay: 1s
      - switch.turn_on: mmwave_sensor  

button:
  - platform: restart
    name: Restart $device_name

  - platform: template
    name: "factory_reset_dfrobot"

What does the device webpage show?

Staying in the on position despite logs saying otherwise.

In situations like this, I like to;

  1. disconnect the GPIO and confirm the voltage (high/low) at the sensor

  2. try a different pin on the ESP

This situation does demonstrate the usefulness of the log. So that’s a plus.

Its weird I just noticed that even turning the sensor off (from the provided switch) will leave the binary sensor in the on position. Could that still be an issue with the pin it is using?

Would suspect so.

Are we talking about the tx/rx pins? or the pulldown? My pull down pin is also the i2c pin for my temp and light sensors… maybe that is causing problems?

You got it! Needs to be a separate pin.

ahhh I asked about that to someone and they thought it would be fine. I don’t know what other pin would be good for a pull down. I am using a D1 Mini esp32. Do you have an idea?

I don’t know particular board. Good idea to check the datasheet for any board-specific rules. Or guess and choose a free pin then test… :wink:

As well as the usefulness of a multimeter!

I only pull mine out after hooking up everything backwards :slight_smile:

I’m surprised I haven’t burned myself down :man_shrugging:

That was it!! I put it to gpio18 now and it is working perfectly! Thank you! I am still new to all this. Actually only learned how to solder like 2 months ago haha! But I am learning a lot. Thank you for the help!

High five!

2 Likes