mmWave Presence Detection - ESPHome style

This is an excellent strategy.

@phillip1 In an effort to make tuning the DFRobot easier for the masses, perhaps your CPP skills could look over the following lambdas?

I’ve tried about every “float to string” google search and continue to misunderstand the type errors.

number:
  - platform: template
    name: distance
    id: distance
    min_value: 0
    max_value: 127
    initial_value: 9
    step: 1
    restore_value: true
    unit_of_measurement: 15cm
    set_action:
      - uart.write: "sensorStop"
      - uart.write: !lambda
                        std::string cm = to_string(x)
                        return printf("outputLatency -1 0 %c", cm);
      - uart.write: "saveCfg 0x45670123 0xCDEF89AB 0x956128C6 0xDF54AC89"
      - uart.write: "sensorStart"
      
  - platform: template
    name: latency
    id: latency
    min_value: 0
    max_value: 2000
    initial_value: 200
    step: 1
    restore_value: true
    unit_of_measurement: 25ms
    set_action:
      - uart.write: "sensorStop"
      - uart.write: !lambda
                        std::string ms = to_string(x)
                        return printf("outputLatency -1 0 %c", ms);
      - uart.write: "saveCfg 0x45670123 0xCDEF89AB 0x956128C6 0xDF54AC89"
      - uart.write: "sensorStart"

I have this Zigbee Menselijke Aanwezigheid Sensor Tuya Smart Pir Mmwave Radar Bewegingsmelder Fall Detectie Verlichtingssterkte Monitor App Alarm Dc 12V| | - AliExpress

Worked out of the box with zigbee2Mqtt and seems to work well with presence. There are some sensitivity params as well

My DFRobot arrived today so will be getting that hooked up soon, thanks for all the info in this thread as otherwise I’d be a bit lost on where to start!

Am I right in thinking based on the ESPHome yaml in your OP you’ve wired up the TX (to GPIO18), RX(to GPIO19) AND GPIO(to GPIO23) pin to your board? As without the TX/RX you’re unable to modify certain distance settings? Also the esphome code in the OP your most up to date version of code for this?

Thanks once again!

Oh no… And I bought 3 of them! :frowning:

I will still give it a try this weekend but one of my use cases was to reliably turn on and off the lights of the kitchen faster :frowning:

@crlogic what’s your experience with returns to Digikey?

I have five of these DFRobot now, each wired to suit their deployment with other sensors and different dev boards. So be sure to wire them up and adjust the yaml GPIO to suit your actual deployment.

As for UART, yes that is entirely optional. And yes you are correct that without UART you will be using the stock distance and delay parameters setting per the DFRobot wiki :slight_smile:

I would highly recommend configuring serial as it makes them very versatile.

As for the rest of the yaml - yes it works and works well. If any new developments occur I will be sure to update.

Good luck and have fun!

1 Like

The SeeedStudio or DFRobot?

The DFRobot are excellent for lighting. Especially with a PIR. Sadly the SeeedStudio are not really suitable IMHO. I have never tried to return anything to Digikey - sooo let me know how it goes!

1 Like

SeeedStudio

If that’s the case I think I won’t wast my time and will try to return them, I’ll let you know!

How about something like this?

Then you can just specify the cm and it will convert it for you (rounding up so 1cm => 15cm, 0cm => 0cm, 15cm => 15cm, 16cm => 30cm)

unit_of_measurement: cm
step: 15
min_value: 0
max_value: 1350
initial_value: 500

!lambda
int cm = (int)ceil(x / 15.0);
std::string s = "outputLatency -1 0 " + to_string(cm);
return std::vector<unsigned char>(s.begin(), s.end());
Or you can use code for 15cm increments
unit_of_measurement: 15cm
step: 1

!lambda
std::string s = "outputLatency -1 0 " + std::to_string((int)x);
return std::vector<unsigned char>(s.begin(), s.end());

Also, on the DFRobot page, it seems to show that the range is >9m??
Sensing distance: “16.5m” “detRangeCfg -1 0 110”. Implying the max range is at maybe 1650cm or more.

1 Like

@phillip1 - amazing! That makes this DFRobot fully configurable using sliders (number) in HA !

image

This is what I ended up with. I started with no delay but the commands would sometimes stumble over themselves. A small delay between each worked.

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
    set_action:
      - uart.write: "sensorStop"
      - 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
      - uart.write: "sensorStart"
      
  - 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
    set_action:
      - uart.write: "sensorStop"
      - 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
      - uart.write: "sensorStart"

I will update the OP and give credit where credit is due. Thank you again!

I haven’t tested that far and see no reason to doubt it on my experiences to date.

4 Likes

That is sweet! Just bought the last two digikey had in stock. Now to add a minimum distance setting :wink:

1 Like

I think I bought the other 2 yesterday since it was saying 4 on stock LOL

I can’t imagine the use-case, do tell!

Or better yet, if you are looking for another project, we got some for ya :wink:

Is that for the dfrobot mmwave sensor on digikey?
Are they lower priced there?

In the UK they’re lower priced if you’re buying more than 1 and then qualify for free shipping. Otherwise I found if you really just want the one then pimoroni was the cheapest option.

In Ireland it was almost 35€ each even with free shipping due to import tax

I paid the equiv of €36 for one in the UK so not far off!

BTW, I found that if you have access to a card that has no fees on currency transactions (like revolut) it’s slightly cheaper to pay in dollars!

Hello @crlogic , @all
I received the sensor as well and do the wiring + take the example of code.
So far so good :slight_smile: !

I added a “device_class: motion” into the binary_sensor.

It’s wired with nodemcu. GPIO13 and GPIO15 for UART and GPIO16 (which is the only one apparently with a pull_down resistor) for connecting the IO2 from the sensor.

I don’t understand exactly the latency. I need to play a bit with the config :slight_smile: What is the usecase ?

Probably a bad description on my part :man_shrugging: :slight_smile:

It is the duration after motion is no longer detected and the sensor reporting off. No different to the delayed_off: filter that ESPHome offers.

1 Like

I’m not sure about my reasoning:

Modify values are saved into the sensor flash. It means that is maintain after a complete shutdown and restart. Supposed true.

But HA states will not be aligned with the real value of the sensor after the restart. There are may be a way to maintain the value saved in HA as well to keep the same. (There is no API code to read the data after save).

It’s correct ?