From 565e7147b71f146b2f4110731d8e3454c60f40e4 Mon Sep 17 00:00:00 2001 From: sen Date: Fri, 26 Jul 2024 21:24:16 +0800 Subject: [PATCH 1/2] bug fixed --- .../human-sensor-f2-beta-github.yaml | 87 +++++++++++++++++-- 1 file changed, 78 insertions(+), 9 deletions(-) diff --git a/f2/yaml/beta-version/human-sensor-f2-beta-github.yaml b/f2/yaml/beta-version/human-sensor-f2-beta-github.yaml index 8ef7527..6b1ddeb 100644 --- a/f2/yaml/beta-version/human-sensor-f2-beta-github.yaml +++ b/f2/yaml/beta-version/human-sensor-f2-beta-github.yaml @@ -28,21 +28,34 @@ esphome: data: !lambda |- std::string th1st = "mth1=" + str_sprintf("%.0f",id(LD1125F_mth1).state) +"\r\n"; return std::vector(th1st.begin(), th1st.end()); + - delay: 100ms - uart.write: id: LD1125F_UART_BUS data: !lambda |- std::string th2st = "mth2=" + str_sprintf("%.0f",id(LD1125F_mth2).state) +"\r\n"; return std::vector(th2st.begin(), th2st.end()); + - delay: 100ms - uart.write: id: LD1125F_UART_BUS data: !lambda |- std::string th3st = "mth3=" + str_sprintf("%.0f",id(LD1125F_mth3).state) +"\r\n"; return std::vector(th3st.begin(), th3st.end()); + - delay: 100ms - uart.write: id: LD1125F_UART_BUS data: !lambda |- std::string rmaxst = "rmax=" + str_sprintf("%.1f",id(LD1125F_rmax).state) +"\r\n"; return std::vector(rmaxst.begin(), rmaxst.end()); + - delay: 100ms + - uart.write: + id: LD1125F_UART_BUS + data: !lambda |- + std::string utonsst = "utons=" + str_sprintf("%.1f",id(LD1125F_utons).state) +"\r\n"; + return std::vector(utonsst.begin(), utonsst.end()); + + +safe_mode: + disabled: true preferences: flash_write_interval: 5s @@ -150,8 +163,24 @@ text_sensor: internal: False #If Don't Want to See UART Receive Data, Set To True on_value: lambda: |- - float distance = atof(id(LD1125F_UART_Text).state.substr(9).c_str()); - if (id(LD1125F_UART_Text).state.substr(0,3) == "occ" && distance > 0) { + std::string uart_text = id(LD1125F_UART_Text).state; + + if (uart_text == "null"){ + return; + } + + float distance = -1; + std::string uart_state = ""; + if (uart_text.length() > 3){ + uart_state = id(LD1125F_UART_Text).state.substr(0,3); + if (uart_text.length() >= 9) { + if (uart_state == "occ" || uart_state =="mov") { + distance = std::stof(uart_text.substr(9)); + } + } + } + + if (uart_state == "occ" && distance > 0) { id(LD1125F_Distance).publish_state(distance); if ((time(NULL)-id(LD1125F_Last_Mov_Time))>id(LD1125F_Mov_Time).state) { id(LD1125F_Occupancy).publish_state("Occupancy"); @@ -170,7 +199,7 @@ text_sensor: id(LD1125F_Clearence_Status) = false; } } - else if (id(LD1125F_UART_Text).state.substr(0,3) == "mov" && distance > 0) { + else if (uart_state == "mov" && distance > 0) { id(LD1125F_Distance).publish_state(distance); id(LD1125F_Occupancy).publish_state("Movement"); if (id(LD1125F_MovOcc_Binary).state == false) { @@ -190,7 +219,6 @@ text_sensor: id: LD1125F_Occupancy icon: "mdi:motion-sensor" - binary_sensor: - platform: status name: Online @@ -247,16 +275,18 @@ sensor: 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 + # filters: # Use Fliter To Debounce + # - sliding_window_moving_average: + # window_size: 8 + # send_every: 2 + # - heartbeat: 0.2s - platform: bh1750 name: "Illuminance" accuracy_decimals: 1 id: bh1750_light update_interval: 1s + filters: + - delta: 0.1 light: - platform: status_led @@ -308,6 +338,10 @@ interval: then: lambda: |- if ((time(NULL)-id(LD1125F_Last_Time))>id(LD1125F_Clear_Time).state) { + // 清理距离。 + if (id(LD1125F_Distance).state != 0){ + id(LD1125F_Distance).publish_state(0); + } if ((id(LD1125F_Clearence_Status) == false) || (id(LD1125F_Occupancy).state != "Clearance")) { id(LD1125F_Occupancy).publish_state("Clearance"); id(LD1125F_Clearence_Status) = true; @@ -357,6 +391,10 @@ number: data: !lambda |- std::string th2st = "mth2=" + str_sprintf("%.0f",x) +"\r\n"; return std::vector(th2st.begin(), th2st.end()); + - delay: 200ms + - uart.write: # 保存用 + id: LD1125F_UART_BUS + data: "save\r\n" - platform: template name: ${upper_devicename} mth3 #mth3 is above 8m Sensitivity. id: LD1125F_mth3 @@ -375,6 +413,10 @@ number: data: !lambda |- std::string th3st = "mth3=" + str_sprintf("%.0f",x) +"\r\n"; return std::vector(th3st.begin(), th3st.end()); + - delay: 200ms + - uart.write: # 保存用 + id: LD1125F_UART_BUS + data: "save\r\n" - platform: template name: ${upper_devicename} Max Distance #rmax is max detection distance. id: LD1125F_rmax @@ -394,6 +436,33 @@ number: data: !lambda |- std::string rmaxst = "rmax=" + str_sprintf("%.1f",x) +"\r\n"; return std::vector(rmaxst.begin(), rmaxst.end()); + - delay: 200ms + - uart.write: # 保存用 + id: LD1125F_UART_BUS + data: "save\r\n" + - platform: template + name: ${upper_devicename} LD1125F Refresh Rate + id: LD1125F_utons + icon: "mdi:refresh" + entity_category: config + optimistic: true + unit_of_measurement: ms + restore_value: true + initial_value: "100" + min_value: 100 + max_value: 5000 + step: 50 + set_action: + then: + - uart.write: + id: LD1125F_UART_BUS + data: !lambda |- + std::string utonsst = "utons=" + std::to_string(x) + "\r\n"; + return std::vector(utonsst.begin(), utonsst.end()); + - delay: 200ms + - uart.write: # 保存用 + id: LD1125F_UART_BUS + data: "save\r\n" - platform: template name: ${upper_devicename} Clearence Time id: LD1125F_Clear_Time From 1b251de387a35b92267bdbbfb83e47b4404e7c17 Mon Sep 17 00:00:00 2001 From: sen Date: Fri, 26 Jul 2024 21:34:49 +0800 Subject: [PATCH 2/2] add save to config --- .../human-sensor-f2-beta-github.yaml | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/f2/yaml/beta-version/human-sensor-f2-beta-github.yaml b/f2/yaml/beta-version/human-sensor-f2-beta-github.yaml index 6b1ddeb..0c44f4b 100644 --- a/f2/yaml/beta-version/human-sensor-f2-beta-github.yaml +++ b/f2/yaml/beta-version/human-sensor-f2-beta-github.yaml @@ -21,6 +21,11 @@ esphome: then: lambda: |- id(cpu_speed) = ESP.getCpuFreqMHz(); + - priority: 300 + then: + # 写入版本号,未来使用公共变量!(23年7月17日_13时29分_) + lambda: |- + id(screek_version).publish_state("V24.7.4_beta"); - priority: -200 then: - uart.write: @@ -138,6 +143,13 @@ web_server: port: 80 text_sensor: + - platform: template + name: "SCREEK Version" + id: screek_version + icon: mdi:information-outline + entity_category: "diagnostic" + update_interval: never + - platform: debug reset_reason: name: "ESP Reset Reason" @@ -373,6 +385,10 @@ number: data: !lambda |- std::string th1st = "mth1=" + str_sprintf("%.0f",x) +"\r\n"; return std::vector(th1st.begin(), th1st.end()); + - delay: 100ms + - uart.write: # save + id: LD1125F_UART_BUS + data: "save\r\n" - platform: template name: ${upper_devicename} mth2 #mth2 is 2.8~8m Sensitivity. id: LD1125F_mth2 @@ -391,8 +407,8 @@ number: data: !lambda |- std::string th2st = "mth2=" + str_sprintf("%.0f",x) +"\r\n"; return std::vector(th2st.begin(), th2st.end()); - - delay: 200ms - - uart.write: # 保存用 + - delay: 100ms + - uart.write: # save id: LD1125F_UART_BUS data: "save\r\n" - platform: template @@ -413,8 +429,8 @@ number: data: !lambda |- std::string th3st = "mth3=" + str_sprintf("%.0f",x) +"\r\n"; return std::vector(th3st.begin(), th3st.end()); - - delay: 200ms - - uart.write: # 保存用 + - delay: 100ms + - uart.write: # save id: LD1125F_UART_BUS data: "save\r\n" - platform: template @@ -436,8 +452,8 @@ number: data: !lambda |- std::string rmaxst = "rmax=" + str_sprintf("%.1f",x) +"\r\n"; return std::vector(rmaxst.begin(), rmaxst.end()); - - delay: 200ms - - uart.write: # 保存用 + - delay: 100ms + - uart.write: # save id: LD1125F_UART_BUS data: "save\r\n" - platform: template @@ -459,8 +475,8 @@ number: data: !lambda |- std::string utonsst = "utons=" + std::to_string(x) + "\r\n"; return std::vector(utonsst.begin(), utonsst.end()); - - delay: 200ms - - uart.write: # 保存用 + - delay: 100ms + - uart.write: # save id: LD1125F_UART_BUS data: "save\r\n" - platform: template