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..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: @@ -28,21 +33,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 @@ -125,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" @@ -150,8 +175,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 +211,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 +231,6 @@ text_sensor: id: LD1125F_Occupancy icon: "mdi:motion-sensor" - binary_sensor: - platform: status name: Online @@ -247,16 +287,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 +350,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; @@ -339,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 @@ -357,6 +407,10 @@ number: data: !lambda |- std::string th2st = "mth2=" + str_sprintf("%.0f",x) +"\r\n"; return std::vector(th2st.begin(), th2st.end()); + - delay: 100ms + - uart.write: # save + id: LD1125F_UART_BUS + data: "save\r\n" - platform: template name: ${upper_devicename} mth3 #mth3 is above 8m Sensitivity. id: LD1125F_mth3 @@ -375,6 +429,10 @@ number: data: !lambda |- std::string th3st = "mth3=" + str_sprintf("%.0f",x) +"\r\n"; return std::vector(th3st.begin(), th3st.end()); + - delay: 100ms + - uart.write: # save + 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 +452,33 @@ number: data: !lambda |- std::string rmaxst = "rmax=" + str_sprintf("%.1f",x) +"\r\n"; return std::vector(rmaxst.begin(), rmaxst.end()); + - delay: 100ms + - uart.write: # save + 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: 100ms + - uart.write: # save + id: LD1125F_UART_BUS + data: "save\r\n" - platform: template name: ${upper_devicename} Clearence Time id: LD1125F_Clear_Time