mmWave Presence Detection - ESPHome style

Get rid of everything but the mmWave and report back.

You got it. For some reason I didnā€™t think of that, of all things! Running on just the mmwave sensor now and will check back for any crashes tomorrow morning.

Is there any way that I could tweak the code to display American measurements?

About 12 hours and no reboots! Sorry, I posted in the wrong thread. It is not an mmwave sensor issue. So I still have some troubleshooting to do. My guess is the combination of sensors is consuming too much memory for the ESP32 because I was getting some out of memory errors before each crash. But thatā€™s a topic for another forum.

Thanks for the obvious troubleshooting step that I missed

1 Like

I did have some reboots with the latest code and a D1 mini.

I attribute it to the mini being a bit weak so Iā€™ve removed completely the UART parsing for motion target total number and it seems to be fixed.

I didnā€™t have the target tracking feature enabled as that did reboot the mini frequently anyhow.

Iā€™ve made the modified code that Iā€™m using for the D1 mini, plus wiring and a sample 3d case available here:

1 Like

Just came back to this thread to ask about the frequent reboots. Iā€™m also using a d1 mini and the detection seems to be pretty reliable (in a small room) but I am getting frequent reboots if I look at the history in HA. I donā€™t use any of the num_targets information as itā€™s way too unreliable to do anything meaningful with so Iā€™ll try out your stripped down version and hope it solves it!

Edit: Itā€™s been an hour without a reboot so looks like itā€™s going strong!

1 Like

Nice guide. I like the idea of putting it into a smaller package.

Iā€™ve been using an ESP32 devkit v1. I havenā€™t had any reboots running the sensor alone, but when I add a BLE tracker and PIR sensor it reboots quite often. I havenā€™t had time yet to troubleshoot what the problem with that might be.

1 Like

wow fantastic, glad to have helped! Mine havenā€™t rebooted at all over the past couple of days that Iā€™ve got them running continually, so hopefully this version solves this issue. I believe that as the D1 Mini doesnā€™t have hardware support for UART communication, that reading the UART continually overloads it and it restarts. Iā€™ve disabled these and it appears that it is stable like that.

you could try a few things - firstly you could remove completely the .h file and do all the command sending directly to the UART port from the YAML file. That should remove quite a lot of the code burden on the ESP (but equally will remove the functionality of reading the sensor values for HA to use). You could also try the version of the code above without the target tracking features in it to see if it is more stable for you.

Definitely doesnā€™t help things. Disabling of the web_server does also help stability; especially multi-sensor deployments.

While the parsing is removed, the mmWave is still configured to send the target data to the ESP. Might want to disable it as well given goals of your build. Command parameters found in the datasheet in the docs linked in the OP.

Might be worth doing a ā€˜liteā€™ release for ESP8266ā€™s w/ no target_data/web_server while retaining the configuration options since the latter are very lightweight.

1 Like

But if I disable uart wonā€™t it stop the code from reading get sensor values , like distance, etc? Iā€™d like to keep these off possible.

Good idea to disable the web server! On it.

Config params are polled by the ESP. Presence/targets are continuous serial output by the sensor during detection. So donā€™t disable the ESP UART section, you want to configure the sensor to stop spamming the ESP with target data.

Ah gotcha thank you!

Thank you for the pointers! Iā€™ve trimmed down the code and set the sensor to not output presence messages at all to the UART as the IO2 pin is doing the same trick for HA. Also refactored the code to remove the now defunct mmWave radar switch code in the .h file. Finally created a lambda function to flag the radar as on if there is motion detection by the IO2 pin.

Iā€™ve kept the web server as I like having lower level access to the device but may remove it if thereā€™s a need to trim down the code further for stability purposes.

binary_sensor:
  - platform: gpio
    name: "${device_name_pretty}"
    id: mmwave_presence_detection
    device_class: motion
    pin:
      number: ${gpio_pin}
      mode: INPUT_PULLDOWN
    # when motion is detected, the radar sensor is on so publish radar state to HA
    on_press:
      then:
        lambda: !lambda |-
          if (!id(mmwave_sensor).state) {
            id(mmwave_sensor).publish_state(true);
          }
    
sensor:      
  - platform: custom
    lambda: |-
      auto s = new leapmmw(id(uart_bus));
      App.register_component(s);
      return {};
    sensors:
      
switch:
  - platform: safe_mode
    name: use_safe_mode

  - platform: template
    name: mmwave_sensor
    id: mmwave_sensor # do not change
    entity_category: config
    optimistic: true
    turn_on_action:
      - uart.write: "setUartOutput 1 0"
      - delay: 1s
      - uart.write: "saveConfig"
      - delay: 4s 
      - uart.write: "sensorStart"
    turn_off_action:
      - uart.write: "sensorStop"
      - delay: 2s

1 Like

Can you detect if thereā€™s movement in a specific area? So to say cover two areas with only one sensor like with the Aqara FP1 and have different automations for these areas.

Nope, it is a single area detector.

Do you have to use capacitors with the SEN0395 as well?

Nope (Post must be at least 10 characters)

It was actually a soldering issue, you have a solder pad above the rx pin and it was connected which caused the issues

I have two of these setup with the SEN0395 so far. One with a D1 mini and one with an ESP32-POE-ISO and the one with the D1 works fine but the one with the ESP32-POE-ISO works for a bit then stays stuck on detected and wonā€™t switch back until I restart it. Any ideas?

Iā€™m using these pins:
uart_tx_pin: GPIO4
uart_rx_pin: GPIO36
gpio_pin: GPIO16