mmWave Presence Detection - ESPHome style

adding the line - uart.write: “saveConfig” , is when it fails

If I use it like bellow, works, and visiting the page of the esp, the value changes, but I think it actually writes the value, is just for show.

number:
  - platform: template
    name: mmWave Distance
    id: mmwave_distance
    min_value: 0
    max_value: 800
    initial_value: 315
    optimistic: true
    step: 15
    restore_value: False
    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
      - switch.turn_on: mmwave_sensor

removing the line bellow, no error.

      - uart.write: "saveCfg 0x45670123 0xCDEF89AB 0x956128C6 0xDF54AC89"

Pretty old code. Without saving the changes, a reboot of the mmWave will revert to saved values.

Try, - uart.write: "saveConfig"

with the - uart.write: “saveConfig” it doesnt boot. I did found anothe code, I guess I have ti adapt it to mine

Replace

number:
  - platform: template
    name: mmWave Distance
    id: mmwave_distance
    min_value: 0
    max_value: 800
    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

WITH

number:
  - platform: template
    name: distance
    id: distance # do not change
    entity_category: config
    min_value: 0.15
    max_value: 9.45
    step: 0.15
    unit_of_measurement: M
    mode: box
    lambda: |-
      leapmmw(id(uart_bus)).getmmwConf("getRange");
      return {};
    set_action:
      - switch.turn_off: mmwave_sensor
      - delay: 2s
      - uart.write: !lambda
          std::string range = "setRange 0 " + str_sprintf("%.2f", x);
          return std::vector<unsigned char>(range.begin(), range.end());
      - delay: 3s
      - switch.turn_on: mmwave_sensor 

You are the only report of this symptom, suspect you have a wonky ESP('s).

Without saving the setting the sensor will revert on any sensor reboot. Dunno why you are re-inventing the wheel.

i, m not trying to reinvent the wheel, just understand why the ESP8266 will stop working after few flashes. Like I said, with a new esp8266 works fine, until eventually dies again. I already have 2 boards, with the same problem

Have you tried two ESP32’s? Have you tried two different brand of ESP8266’s? Are the ones you have from the same manufacturing batch? Have you reverted to an ESPHome version before recent changes to saving PSRAM? Have you tried different power supplies?

Removing saveConfig is not the end solution here. It is mandatory to ensure the setting the “ESP tells you is in use” is the “setting the sensor has saved which ensures it is actually in use.”

esp32 works fine, I have few boards, and no problem in any, the esp8266 I tries D1 mini V4 usb c, d1 mini v3 usb C and a regular d1 mini mini usb. On the regular one I removed the shield and it have a ESP8266EX, some sort of bios chip, a crystal, few resistors, and few capacitors, cant see any branding. They from Ali express, from different sellers. maybe I should get better boards.

I can only vouch for running this on ESP32’s so your mileage will definitely vary.

Nice to read that you got it to work. But it is not clear to me how. You write “switched off the LED” like it’s obvious but how did you switch it off?
(I have my TX → RX and RX → TX right)

Thank you. Got it working. changing the logger to level: none, works, with all the numbers and sensors. If the logger is none will the uart values are still written to the 8266?

I see it now, ha.

hardware_uart (Optional, string): The Hardware UART to use for logging. Defaults to UART0.

seems like it now can be integrated standalone by bluetooth LD2410 BLE - Home Assistant

1 Like

Where have u seen discussion that the upcoming Aqara is using a sensor from Acconeer? About the angel, It is 65 in horizontal and 53 in vertical. So if it is an a121, then it might be 2 sensors?

That 3d printed case looks like exactly the kind of thing I’m looking for. Would you be willing to share the source for it?

It has a few issues I was going to fix but never got around to it as I designed a new one with different parts instead. Do you want to install it in the wall? It’s a tight fit to get it acually installed is the main issue but it does work. I uploaded the files here: Printables

1 Like

Hello Thank You very much for sharing your knowledge :slight_smile:
I try to use this code

substitutions:

  # change device name to match your desired name

  device_name: smmwave

  # change sensor name below to the one you want to see in Home Assistant

  device_name_pretty: Bureau Occupancy Sensor

  # UART Pin configured for a D1 Mini stacked setup

  uart_tx_pin: TX

 

  # This will vary based on your board

  uart_rx_pin: RX

 

  # This will vary based on your board

  gpio_pin: D0

 

  # (Optional) Path to the leapmmw_sensor.h file relative to your esphome configuration directory.

  header_file: leapmmw_sensor.h

# include the yml file with the sensor configuration

packages:

  inclusions: !include packages/leapmmw_sensor.yml

esphome:

  name: esphome-web-b6084c

  friendly_name: ESPHome Web b6084c

esp8266:

  board: d1_mini

# Enable logging

logger:

# Enable Home Assistant API

api:

  encryption:

    key: "Bhi/N4kTW12duvgnoa3YIbiVQgH9MLsyFThNixFFUWQ="

ota:

wifi:

  ssid: !secret wifi_ssid

  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails

  ap:

    ssid: "Esphome-Web-B6084C"

    password: "IVahUg0NXY67"

captive_portal:

web_server:

  port: 80

  version: 2

  include_internal: true

http_request:

  useragent: esphome/$device_name

  timeout: 2s

with file copied from here GitHub - hjmcnew/esphome-hs2xx3a-custom-component at release
/ components/hs2xx3a
/ packages
leapmmw_sensor.h

when i try to install I have this error:

INFO Reading configuration /config/esphome-web-b6084c.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing esphome-web-b6084c (board: d1_mini; framework: arduino; platform: platformio/espressif8266 @ 3.2.0)
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- ESPAsyncTCP-esphome @ 1.2.3
|-- ESPAsyncWebServer-esphome @ 2.1.0
|   |-- ESPAsyncTCP-esphome @ 1.2.3
|   |-- Hash @ 1.0
|   |-- ESP8266WiFi @ 1.0
|-- DNSServer @ 1.1.1
|-- ESP8266WiFi @ 1.0
|-- ESP8266mDNS @ 1.2
|-- noise-c @ 0.1.4
|   |-- libsodium @ 1.10018.1
|-- ArduinoJson @ 6.18.5
|-- ESP8266HTTPClient @ 1.2
Compiling .pioenvs/esphome-web-b6084c/src/main.cpp.o
/config/packages/leapmmw_sensor.yml: In lambda function:
/config/packages/leapmmw_sensor.yml:109:14: error: 'clearTargets' was not declared in this scope
  109 |       - lambda: 'return clearTargets();'
      |              ^~~~~~~~~~~~
/config/packages/leapmmw_sensor.yml: In lambda function:
/config/packages/leapmmw_sensor.yml:44:14: error: 'clearTargets' was not declared in this scope
   44 |                 return clearTargets();
      |              ^  ~~~~~~~~~
*** [.pioenvs/esphome-web-b6084c/src/main.cpp.o] Error 1
========================== [FAILED] Took 5.99 seconds ==========================

Hello,

I have a seeedstudio Human Static Presence Module Lite ( MR24HPC1 ) and was trying to use this code but i cannot compile it because i’m missing the radar.h library, can you help me on where to find this ?

Thank you in advance.

This might have what you need:

Has anyone tried to add a PIR sensor to the mmwave sensor while using the seeed xaio esp32-C3? I programmed one in and it works great. . . .only everything else quite working. Any thoughts? The board isn’t programmed as the correct board, but the pinouts work exactly as I hooked it up and point to the correct pins. I got most of the code from here: XIAO ESP32C3 accesses Home Assistant via ESPHome service | Seeed Studio Wiki . The binary sensor code I got from here: GPIO Binary Sensor — ESPHome . Before I input the Binary Sensor code and got the PIR sensor working all other mmwave sensor info worked in Home Assistant. Since adding the Binary Sensor, none of it works and shows as Unavailable. My yaml code below:

# part 1:

esphome:

  name: xiao_motion_sensor

  platformio_options:

    board_build.flash_mode: dio

    board_build.mcu: esp32c3

  includes:

  - R24dvd.h

esp32:

  board: esp32-c3-devkitm-1

  variant: esp32c3

  framework:

    type: esp-idf

# Enable logging

logger:

  hardware_uart: USB_SERIAL_JTAG

  level: DEBUG

   

# 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: "Redacted"

    password: "Redacted"

#Test code for PIR Sensor

binary_sensor:

  - platform: gpio

    pin: 8

    name: "APIR Motion-Presence"

    device_class: motion

# part 3:

uart:

  id: uart_bus

  baud_rate:  115200

  rx_pin: 5

  tx_pin: 4

 

select:

  - platform: template

    name: "Standard Scene mode"

    id: scene_mode

    icon: mdi:hoop-house

    optimistic: true

    options:

      - "Living room"

      - "Area detection"

      - "Washroom"

      - "Bedroom"

    initial_option: "Living room"

    set_action:

      - logger.log:

            format: "set action option: %s"

            args: ["x.c_str()"]

      - uart.write: !lambda

                  auto index = id(scene_mode).index_of(x);

                  uint8_t value = (uint8_t)index.value() + 1;

                  uint8_t crc = value + 0xB9;

                  return {0x53,0x59,0x05,0x07,0x00,0x01,value,crc,0x54,0x43};

  - platform: template

    name: "Standard unmanned time"

    id: unmanned_time

    icon: mdi:timeline-clock

    optimistic: true

    options:

      - "None"

      - "10s"

      - "30s"

      - "1min"

      - "2min"

      - "5min"

      - "10min"

      - "30min"

      - "1hour"

    initial_option: "None"

    set_action:

      - logger.log:

            format: "Chosen option: %s"

            args: ["x.c_str()"]

      - uart.write: !lambda

                  auto index = id(unmanned_time).index_of(x);

                  uint8_t value = (uint8_t)index.value();

                  uint8_t crc = value + 0x37;

                  return {0x53,0x59,0x80,0x0a,0x00,0x01,value,crc,0x54,0x43};

 

  - platform: template

    name: "Custom Presence of perception boundary"

    id: custom_presence_of_perception_boundary

    optimistic: true

    options:

      - "0.5m"

      - "1.0m"

      - "1.5m"

      - "2.0m"

      - "2.5m"

      - "3.0m"

      - "3.5m"

      - "4.0m"

      - "4.5m"

      - "5.0m"

    set_action:

      - logger.log:

            format: "Chosen option: %s"

            args: ["x.c_str()"]

      - uart.write: !lambda

                  auto index = id(unmanned_time).index_of(x);

                  uint8_t value = (uint8_t)index.value() + 1;

                  uint8_t crc = value + 0xBF;

                  return {0x53,0x59,0x08,0x0a,0x00,0x01,value,crc,0x54,0x43};

 

  - platform: template

    name: "Custom Motion trigger boundary"

    id: custom_motion_trigger_boundary

    optimistic: true

    options:

      - "0.5m"

      - "1.0m"

      - "1.5m"

      - "2.0m"

      - "2.5m"

      - "3.0m"

      - "3.5m"

      - "4.0m"

      - "4.5m"

      - "5.0m"

    set_action:

      - logger.log:

            format: "Chosen option: %s"

            args: ["x.c_str()"]

      - uart.write: !lambda

                  auto index = id(unmanned_time).index_of(x);

                  uint8_t value = (uint8_t)index.value() + 1;

                  uint8_t crc = value + 0xC0;

                  return {0x53,0x59,0x08,0x0b,0x00,0x01,value,crc,0x54,0x43};

 

number:

  - platform: template

    id: sensitivity

    name: "Standard sensitivity"

    icon: mdi:archive-check-outline

    min_value: 0

    max_value: 3

    optimistic: false

    step: 1

    update_interval: 2s

    set_action:

      - uart.write: !lambda

                    uint8_t crc = x + 0xBA;

                    return {0x53,0x59,0x05,0x08,0x00,0x01,(uint8_t)x,crc,0x54,0x43};

 

  - platform: template

    name: "Standard Maximum detectable range of moving target"

    id: moving_target_detection_max_distance

    icon: mdi:map-marker-path

    unit_of_measurement: "cm"

    min_value: 0

    max_value: 65536

    step: 500

    set_action:

      - uart.write: !lambda

                    int h_num = (int)x >> 8;

                    int l_num = (int)x & 0xff;

                    int crc = 0xB6 + h_num + l_num;

                    return {0x53,0x59,0x07,0x01,0x00,0x02,(uint8_t)(h_num),(uint8_t)(l_num),(uint8_t)crc,0x54,0x43};

 

  - platform: template

    name: "Standard Maximum detectable range of stationary target"

    id: static_target_detection_max_distance

    icon: mdi:map-marker-path

    unit_of_measurement: cm

    min_value: 0

    max_value: 65536

    step: 500

    set_action:

      - uart.write: !lambda

                    int h_num = (int)x >> 8;

                    int l_num = (int)x & 0xff;

                    int crc = 0xB9 + h_num + l_num;

                    return {0x53,0x59,0x07,0x04,0x00,0x02,(uint8_t)(h_num),(uint8_t)(l_num),(uint8_t)crc,0x54,0x43};

 

  - platform: template

    name: "Custom Judgment threshold exists"

    id: custom_judgment_threshold_exists

    min_value: 0

    max_value: 250

    step: 1

    set_action:

      - uart.write: !lambda

                    int crc = 0xBD + (int)x;

                    return {0x53,0x59,0x08,0x08,0x00,0x01,(uint8_t)x,(uint8_t)crc,0x54,0x43};

 

  - platform: template

    name: "Custom Motion amplitude trigger threshold"

    id: custom_motion_amplitude_trigger_threshold

    min_value: 0

    max_value: 250

    step: 1

    set_action:

      - uart.write: !lambda

                    int crc = 0xBE + (int)x;

                    return {0x53,0x59,0x08,0x09,0x00,0x01,(uint8_t)x,(uint8_t)crc,0x54,0x43};

 

  - platform: template

    name: "Custom Mode Settings"

    id: custom_mode_settings

    icon: mdi:cog

    min_value: 0

    max_value: 250

    step: 1

    set_action:

      - uart.write: !lambda

                    int crc = 0xBB + (int)x;

                    return {0x53,0x59,0x05,0x09,0x00,0x01,(uint8_t)x,(uint8_t)crc,0x54,0x43};

 

  - platform: template

    name: "Custom Mode Settings End"

    id: custom_mode_setting_completed

    icon: mdi:cog

    min_value: 0

    max_value: 250

    step: 1

    set_action:

      - uart.write: !lambda

                    int crc = 0xBC + (int)x;

                    return {0x53,0x59,0x05,0x0a,0x00,0x01,(uint8_t)x,(uint8_t)crc,0x54,0x43};

 

  - platform: template

    name: "Custom Custom Mode Query"

    icon: mdi:cog

    id: custom_mode_query

    min_value: 0

    max_value: 250

    step: 1

    set_action:

      - uart.write: !lambda

                    int crc = 0x3B + (int)x;

                    return {0x53,0x59,0x05,0x89,0x00,0x01,(uint8_t)x,(uint8_t)crc,0x54,0x43};

 

  - platform: template

    name: "Custom Motion trigger time"

    id: custom_motion_trigger_time

    icon: mdi:camera-timer

    unit_of_measurement: "ms"

    min_value: 0

    max_value: 4294967295

    step: 5000

    set_action:

      - uart.write: !lambda

                    int crc = 0xC4 + (int)x;

                    int h24_num = ((int)x >> 24) & 0xff;

                    int h16_num = ((int)x >> 16) & 0xff;

                    int h8_num = ((int)x >> 8) & 0xff;

                    int l8_num = (int)x & 0xff;

                    return {0x53,0x59,0x08,0x0c,0x00,0x04,(uint8_t)h24_num,(uint8_t)h16_num,(uint8_t)h8_num,(uint8_t)l8_num,(uint8_t)crc,0x54,0x43};

 

  - platform: template

    name: "Custom Movement to rest time"

    id: custom_movement_to_rest_time

    icon: mdi:camera-timer

    unit_of_measurement: "ms"

    min_value: 0

    max_value: 4294967295

    step: 5000

    set_action:

      - uart.write: !lambda

                    int crc = 0xC5 + (int)x;

                    int h24_num = ((int)x >> 24) & 0xff;

                    int h16_num = ((int)x >> 16) & 0xff;

                    int h8_num = ((int)x >> 8) & 0xff;

                    int l8_num = (int)x & 0xff;

                    return {0x53,0x59,0x08,0x0d,0x00,0x04,(uint8_t)h24_num,(uint8_t)h16_num,(uint8_t)h8_num,(uint8_t)l8_num,(uint8_t)crc,0x54,0x43};

 

  - platform: template

    name: "Custom Time of entering unmanned state"

    id: custom_time_of_enter_unmanned

    icon: mdi:camera-timer

    unit_of_measurement: "ms"

    min_value: 0

    max_value: 4294967295

    step: 5000

    set_action:

      - uart.write: !lambda

                    int crc = 0xC6 + (int)x;

                    int h24_num = ((int)x >> 24) & 0xff;

                    int h16_num = ((int)x >> 16) & 0xff;

                    int h8_num = ((int)x >> 8) & 0xff;

                    int l8_num = (int)x & 0xff;

                    return {0x53,0x59,0x08,0x0e,0x00,0x04,(uint8_t)h24_num,(uint8_t)h16_num,(uint8_t)h8_num,(uint8_t)l8_num,(uint8_t)crc,0x54,0x43};

 

text_sensor:

- platform: custom

  lambda: |-

    auto my_custom_sensor = new MyCustomTextSensor();

    App.register_component(my_custom_sensor);

    return {my_custom_sensor->Heartbeat};

 

  text_sensors:

    - name: "Standard Heartbeat"

      icon: mdi:connection

 

- platform: template

  name: "Standard Product model"

  id: product_mode

  icon: mdi:information-outline

  on_raw_value:

    then:

      - logger.log: text_sensor on_raw_value

 

- platform: template

  name: "Standard Product ID"

  id: product_id

  icon: mdi:information-outline

 

- platform: template

  name: "Standard Hardware model"

  id: hardware_model

  icon: mdi:information-outline

 

- platform: template

  name: "Standard Firmware version"

  id: firmware_version

  icon: mdi:information-outline

 

- platform: template

  name: "Standard protocol type"

  id: protocol_type

  icon: mdi:information-outline

 

- platform: template

  name: "Standard moving direction"

  id: keep_away

  icon: mdi:walk

 

- platform: template

  name: "Standard Sports information"

  id: motion_status

  icon: mdi:human-greeting

 

- platform: template

  name: "Standard Presence information"

  id: someoneExists

  icon: "mdi:motion-sensor"

 

- platform: template

  name: "Custom Presence of detection"

  id: custom_presence_of_detection

  icon: mdi:signal-distance-variant

 

# - platform: template

#   name: "Custom Motion distance"

#   id: custom_motion_distance

 

# - platform: template

#   name: "Custom Static distance"

#   id: custom_static_distance

 

# - platform: template

#   name: "Custom Spatial static value"

#   id: custom_spatial_static_value

 

# - platform: template

#   name: "Custom Spatial motion value"

#   id: custom_spatial_motion_value

 

# - platform: template

#   name: "Custom Motion speed"

#   id: custom_motion_speed

  

button:

  - platform: template

    name: "Standard reset"

    id: "reset"

    icon: mdi:reload

    on_press:

      then:

        - logger.log: Button Pressed

        - uart.write: [0x53,0x59,0x01,0x02,0x00,0x01,0x0F,0xBF,0x54,0x43]

 

switch:

  - platform: template

    id: output_info_switch

    name: "Custom Infor output switch"

    icon: mdi:electric-switch

    assumed_state: true

    turn_on_action:

      - uart.write: [0x53,0x59,0x08,0x00,0x00,0x01,0x01,0xB6,0x54,0x43]

      - delay: 1s

      - lambda: !lambda |-

          id(product_mode).publish_state("");

          id(product_id).publish_state("");

          id(hardware_model).publish_state("");

          id(firmware_version).publish_state("");

          id(protocol_type).publish_state("");

    turn_off_action:

      - uart.write: [0x53,0x59,0x08,0x00,0x00,0x01,0x00,0xB5,0x54,0x43]

sensor:

- platform: custom

  lambda: |-

    auto my_custom_sensor = new UartReadLineSensor(id(uart_bus));

    App.register_component(my_custom_sensor);

    return {

      my_custom_sensor->movementSigns,

      my_custom_sensor->inited,

    };

  sensors:

    - name: "Standard body movement"

      id: movementSigns

      icon: "mdi:human-greeting-variant"

      device_class: "temperature"

      state_class: "measurement"

    - name: "Standard inited"

      id: inited

      icon: mdi:all-inclusive

 

- platform: template

  name: "Custom Motion distance"

  id: custom_motion_distance

  icon: mdi:signal-distance-variant

  on_value:

    then:

      # - logger.log: Custom Motion distance on_value

      - logger.log:

            format: "Custom Motion distance on_value : %d"

            args: ["x"]

  on_raw_value:

    then:

      - logger.log:

            format: "Custom Motion distance on_raw_value : %d"

            args: ["x"]

  

- platform: template

  name: "Custom Static distance"

  id: custom_static_distance

  icon: mdi:signal-distance-variant

- platform: template

  name: "Custom Spatial static value"

  id: custom_spatial_static_value

  icon: mdi:counter

- platform: template

  name: "Custom Spatial motion value"

  id: custom_spatial_motion_value

  icon: mdi:counter

- platform: template

  name: "Custom Motion speed"

  id: custom_motion_speed

  icon: mdi:run-fast