# Enable Home Assistant API api: encryption: key: "eBrxqMp+lU7nOEmQBcl5hZsexSr+NcdhF6xa/0HPbig=" ota: password: "7ca0ac054d39eec0e41ab0e28b7916ee" wifi: ssid: !secret wifi_ssid password: !secret wifi_password # Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "Mmwave-Detector3" password: "xNAPBrJVQfuy" captive_portal: substitutions: devicename: "mmwave-detector3" #Rename the device what you want. upper_devicename: ESP Radar #Rename the device what you want. esphome: name: $devicename friendly_name: $devicename on_boot: #LD1125H Initial Setting priority: -200 then: - uart.write: id: LD1125H_UART_BUS data: !lambda |- std::string th1stm = "mth1_mov=" + str_sprintf("%.0f",id(LD1125H_mth1_mov).state) +"\r\n"; return std::vector(th1stm.begin(), th1stm.end()); - uart.write: id: LD1125H_UART_BUS data: !lambda |- std::string th2stm = "mth2_mov=" + str_sprintf("%.0f",id(LD1125H_mth2_mov).state) +"\r\n"; return std::vector(th2stm.begin(), th2stm.end()); - uart.write: id: LD1125H_UART_BUS data: !lambda |- std::string th3stm = "mth3_mov=" + str_sprintf("%.0f",id(LD1125H_mth3_mov).state) +"\r\n"; return std::vector(th3stm.begin(), th3stm.end()); - uart.write: id: LD1125H_UART_BUS data: !lambda |- std::string th1sto = "mth1_occ=" + str_sprintf("%.0f",id(LD1125H_mth1_occ).state) +"\r\n"; return std::vector(th1sto.begin(), th1sto.end()); - uart.write: id: LD1125H_UART_BUS data: !lambda |- std::string th2sto = "mth2_occ=" + str_sprintf("%.0f",id(LD1125H_mth2_occ).state) +"\r\n"; return std::vector(th2sto.begin(), th2sto.end()); - uart.write: id: LD1125H_UART_BUS data: !lambda |- std::string th3sto = "mth3_occ=" + str_sprintf("%.0f",id(LD1125H_mth3_occ).state) +"\r\n"; return std::vector(th3sto.begin(), th3sto.end()); - uart.write: id: LD1125H_UART_BUS data: !lambda |- std::string rmaxst = "rmax=" + str_sprintf("%.1f",id(LD1125H_rmax).state) +"\r\n"; return std::vector(rmaxst.begin(), rmaxst.end()); - uart.write: id: LD1125H_UART_BUS data: !lambda |- std::string getallst = "get_all\r\n"; return std::vector(getallst.begin(), getallst.end()); esp32: board: nodemcu-32s framework: type: arduino external_components: - source: type: git url: https://github.com/ssieb/custom_components #Thanks for @ssieb components. components: [ serial ] logger: level: DEBUG #You Can Use "INFO" Level baud_rate: 0 uart: id: LD1125H_UART_BUS rx_pin: GPIO16 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang tx_pin: GPIO17 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang baud_rate: 115200 data_bits: 8 stop_bits: 1 parity: NONE # debug: # direction: BOTH # dummy_receiver: false # after: # delimiter: "\n" # sequence: # - lambda: UARTDebug::log_string(direction, bytes); globals: - id: LD1125H_Last_Time type: time_t restore_value: no initial_value: time(NULL) - id: LD1125H_Last_Mov_Time type: time_t restore_value: no initial_value: time(NULL) - id: LD1125H_Clearence_Status type: bool restore_value: no initial_value: "false" status_led: pin: number: GPIO2 #ESP32 OnBroad LED inverted: false #web_server: #Avoid Using Web Server To Prevent Hang # port: 80 interval: - interval: 1s #Clearance Scan Time setup_priority: -200 then: lambda: |- if ((time(NULL)-id(LD1125H_Last_Time))>id(LD1125H_Clear_Time).state) { if ((id(LD1125H_Clearence_Status) == false) || (id(LD1125H_Occupancy).state != "Clearance")) { id(LD1125H_Occupancy).publish_state("Clearance"); id(LD1125H_Clearence_Status) = true; } if (id(LD1125H_MovOcc_Binary).state == true) { id(LD1125H_MovOcc_Binary).publish_state(false); } if (id(LD1125H_Mov_Binary).state == true) { id(LD1125H_Mov_Binary).publish_state(false); } } number: - platform: template name: ${upper_devicename} LD1125H mth1 mov #mth1 mov is 0~2.8m motion detection threshold. id: LD1125H_mth1_mov icon: "mdi:cogs" optimistic: true restore_value: true #If you don't want to store the setting at ESP, set it to false. initial_value: "30.0" #Default mth1_mov Setting min_value: 10.0 max_value: 600.0 step: 5.0 set_action: then: - uart.write: id: LD1125H_UART_BUS data: !lambda |- std::string th1st = "mth1_mov=" + str_sprintf("%.0f",x) +"\r\n"; return std::vector(th1st.begin(), th1st.end()); - platform: template name: ${upper_devicename} LD1125H mth2 mov #mth2 mov is 2.8~8m motion detection threshold. id: LD1125H_mth2_mov icon: "mdi:cogs" optimistic: true restore_value: true #If you don't want to store the setting at ESP, set it to false. initial_value: "15" #Default mth2_mov Setting min_value: 5 max_value: 300 step: 5 set_action: then: - uart.write: id: LD1125H_UART_BUS data: !lambda |- std::string th2st = "mth2_mov=" + str_sprintf("%.0f",x) +"\r\n"; return std::vector(th2st.begin(), th2st.end()); - platform: template name: ${upper_devicename} LD1125H mth3 mov #mth3 mov is above 8m motion detection threshold. id: LD1125H_mth3_mov icon: "mdi:cogs" optimistic: true restore_value: true #If you don't want to store the setting at ESP, set it to false. initial_value: "6" #Default mth3_mov Setting min_value: 5 max_value: 200 step: 5 set_action: then: - uart.write: id: LD1125H_UART_BUS data: !lambda |- std::string th3st = "mth3_mov=" + str_sprintf("%.0f",x) +"\r\n"; return std::vector(th3st.begin(), th3st.end()); - platform: template name: ${upper_devicename} LD1125H mth1 occ #mth1 occ is 0~2.8m detection threshold. id: LD1125H_mth1_occ icon: "mdi:cogs" optimistic: true restore_value: true #If you don't want to store the setting at ESP, set it to false. initial_value: "30.0" #Default mth1_mov Setting min_value: 10.0 max_value: 600.0 step: 5.0 set_action: then: - uart.write: id: LD1125H_UART_BUS data: !lambda |- std::string th1st = "mth1_occ=" + str_sprintf("%.0f",x) +"\r\n"; return std::vector(th1st.begin(), th1st.end()); - platform: template name: ${upper_devicename} LD1125H mth2 occ #mth2 occ is 2.8~8m detection threshold. id: LD1125H_mth2_occ icon: "mdi:cogs" optimistic: true restore_value: true #If you don't want to store the setting at ESP, set it to false. initial_value: "15" #Default mth2_mov Setting min_value: 5 max_value: 300 step: 5 set_action: then: - uart.write: id: LD1125H_UART_BUS data: !lambda |- std::string th2st = "mth2_occ=" + str_sprintf("%.0f",x) +"\r\n"; return std::vector(th2st.begin(), th2st.end()); - platform: template name: ${upper_devicename} LD1125H mth3 occ #mth3 occ is above 8m detection threshold. id: LD1125H_mth3_occ icon: "mdi:cogs" optimistic: true restore_value: true #If you don't want to store the setting at ESP, set it to false. initial_value: "6" #Default mth3_mov Setting min_value: 5 max_value: 200 step: 5 set_action: then: - uart.write: id: LD1125H_UART_BUS data: !lambda |- std::string th3st = "mth3_occ=" + str_sprintf("%.0f",x) +"\r\n"; return std::vector(th3st.begin(), th3st.end()); - platform: template name: ${upper_devicename} LD1125H rmax #rmax is max detection distance. id: LD1125H_rmax icon: "mdi:cogs" optimistic: true restore_value: true #If you don't want to store the setting at ESP, set it to false. initial_value: "8" #Default rmax Setting min_value: 0.4 max_value: 12 step: 0.2 set_action: then: - uart.write: id: LD1125H_UART_BUS data: !lambda |- std::string rmaxst = "rmax=" + str_sprintf("%.1f",x) +"\r\n"; return std::vector(rmaxst.begin(), rmaxst.end()); - platform: template name: ${upper_devicename} LD1125H Clearence Time id: LD1125H_Clear_Time icon: "mdi:cogs" optimistic: true restore_value: true #If you don't want to store the setting at ESP, set it to false. initial_value: "5" #LD1125H Mov/Occ > Clearence Time Here min_value: 0.5 max_value: 60 step: 0.5 - platform: template name: ${upper_devicename} LD1125H Movement Time id: LD1125H_Mov_Time icon: "mdi:cogs" optimistic: true restore_value: true #If you don't want to store the setting at ESP, set it to false. initial_value: "1" #LD1125H Mov > Occ Time Here min_value: 0.5 max_value: 10 step: 0.5 sensor: - platform: template name: ${upper_devicename} LD1125H Distance id: LD1125H_Distance icon: "mdi:signal-distance-variant" unit_of_measurement: "m" accuracy_decimals: 2 filters: # Use Fliter To Debounce - sliding_window_moving_average: window_size: 8 send_every: 2 - heartbeat: 0.2s text_sensor: - platform: serial uart_id: LD1125H_UART_BUS name: ${upper_devicename} LD1125H UART Text id: LD1125H_UART_Text icon: "mdi:format-text" internal: False #If Don't Want to See UART Receive Data, Set To True on_value: lambda: |- if (id(LD1125H_UART_Text).state.substr(0,3) == "occ") { id(LD1125H_Distance).publish_state(atof(id(LD1125H_UART_Text).state.substr(9).c_str())); if ((time(NULL)-id(LD1125H_Last_Mov_Time))>id(LD1125H_Mov_Time).state) { id(LD1125H_Occupancy).publish_state("Occupancy"); if (id(LD1125H_MovOcc_Binary).state == false) { id(LD1125H_MovOcc_Binary).publish_state(true); } if (id(LD1125H_Mov_Binary).state == true) { id(LD1125H_Mov_Binary).publish_state(false); } } if (id(LD1125H_MovOcc_Binary).state == false) { id(LD1125H_MovOcc_Binary).publish_state(true); } id(LD1125H_Last_Time) = time(NULL); if (id(LD1125H_Clearence_Status) == true) { id(LD1125H_Clearence_Status) = false; } } else if (id(LD1125H_UART_Text).state.substr(0,3) == "mov") { id(LD1125H_Distance).publish_state(atof(id(LD1125H_UART_Text).state.substr(9).c_str())); id(LD1125H_Occupancy).publish_state("Movement"); if (id(LD1125H_MovOcc_Binary).state == false) { id(LD1125H_MovOcc_Binary).publish_state(true); } if (id(LD1125H_Mov_Binary).state == false) { id(LD1125H_Mov_Binary).publish_state(true); } id(LD1125H_Last_Mov_Time) = time(NULL); id(LD1125H_Last_Time) = time(NULL); if (id(LD1125H_Clearence_Status) == true) { id(LD1125H_Clearence_Status) = false; } } - platform: template name: ${upper_devicename} LD1125H Occupancy Status id: LD1125H_Occupancy icon: "mdi:motion-sensor" binary_sensor: - platform: template name: ${upper_devicename} LD1125H Occupancy or Movement id: LD1125H_MovOcc_Binary device_class: occupancy - platform: template name: ${upper_devicename} LD1125H Movement id: LD1125H_Mov_Binary device_class: motion