bug fixed

This commit is contained in:
sen 2024-07-26 21:24:16 +08:00
parent 06f5726673
commit 565e7147b7

View File

@ -28,21 +28,34 @@ esphome:
data: !lambda |- data: !lambda |-
std::string th1st = "mth1=" + str_sprintf("%.0f",id(LD1125F_mth1).state) +"\r\n"; std::string th1st = "mth1=" + str_sprintf("%.0f",id(LD1125F_mth1).state) +"\r\n";
return std::vector<uint8_t>(th1st.begin(), th1st.end()); return std::vector<uint8_t>(th1st.begin(), th1st.end());
- delay: 100ms
- uart.write: - uart.write:
id: LD1125F_UART_BUS id: LD1125F_UART_BUS
data: !lambda |- data: !lambda |-
std::string th2st = "mth2=" + str_sprintf("%.0f",id(LD1125F_mth2).state) +"\r\n"; std::string th2st = "mth2=" + str_sprintf("%.0f",id(LD1125F_mth2).state) +"\r\n";
return std::vector<uint8_t>(th2st.begin(), th2st.end()); return std::vector<uint8_t>(th2st.begin(), th2st.end());
- delay: 100ms
- uart.write: - uart.write:
id: LD1125F_UART_BUS id: LD1125F_UART_BUS
data: !lambda |- data: !lambda |-
std::string th3st = "mth3=" + str_sprintf("%.0f",id(LD1125F_mth3).state) +"\r\n"; std::string th3st = "mth3=" + str_sprintf("%.0f",id(LD1125F_mth3).state) +"\r\n";
return std::vector<uint8_t>(th3st.begin(), th3st.end()); return std::vector<uint8_t>(th3st.begin(), th3st.end());
- delay: 100ms
- uart.write: - uart.write:
id: LD1125F_UART_BUS id: LD1125F_UART_BUS
data: !lambda |- data: !lambda |-
std::string rmaxst = "rmax=" + str_sprintf("%.1f",id(LD1125F_rmax).state) +"\r\n"; std::string rmaxst = "rmax=" + str_sprintf("%.1f",id(LD1125F_rmax).state) +"\r\n";
return std::vector<uint8_t>(rmaxst.begin(), rmaxst.end()); return std::vector<uint8_t>(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<uint8_t>(utonsst.begin(), utonsst.end());
safe_mode:
disabled: true
preferences: preferences:
flash_write_interval: 5s flash_write_interval: 5s
@ -150,8 +163,24 @@ text_sensor:
internal: False #If Don't Want to See UART Receive Data, Set To True internal: False #If Don't Want to See UART Receive Data, Set To True
on_value: on_value:
lambda: |- lambda: |-
float distance = atof(id(LD1125F_UART_Text).state.substr(9).c_str()); std::string uart_text = id(LD1125F_UART_Text).state;
if (id(LD1125F_UART_Text).state.substr(0,3) == "occ" && distance > 0) {
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); id(LD1125F_Distance).publish_state(distance);
if ((time(NULL)-id(LD1125F_Last_Mov_Time))>id(LD1125F_Mov_Time).state) { if ((time(NULL)-id(LD1125F_Last_Mov_Time))>id(LD1125F_Mov_Time).state) {
id(LD1125F_Occupancy).publish_state("Occupancy"); id(LD1125F_Occupancy).publish_state("Occupancy");
@ -170,7 +199,7 @@ text_sensor:
id(LD1125F_Clearence_Status) = false; 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_Distance).publish_state(distance);
id(LD1125F_Occupancy).publish_state("Movement"); id(LD1125F_Occupancy).publish_state("Movement");
if (id(LD1125F_MovOcc_Binary).state == false) { if (id(LD1125F_MovOcc_Binary).state == false) {
@ -190,7 +219,6 @@ text_sensor:
id: LD1125F_Occupancy id: LD1125F_Occupancy
icon: "mdi:motion-sensor" icon: "mdi:motion-sensor"
binary_sensor: binary_sensor:
- platform: status - platform: status
name: Online name: Online
@ -247,16 +275,18 @@ sensor:
icon: "mdi:signal-distance-variant" icon: "mdi:signal-distance-variant"
unit_of_measurement: "m" unit_of_measurement: "m"
accuracy_decimals: 2 accuracy_decimals: 2
filters: # Use Fliter To Debounce # filters: # Use Fliter To Debounce
- sliding_window_moving_average: # - sliding_window_moving_average:
window_size: 8 # window_size: 8
send_every: 2 # send_every: 2
- heartbeat: 0.2s # - heartbeat: 0.2s
- platform: bh1750 - platform: bh1750
name: "Illuminance" name: "Illuminance"
accuracy_decimals: 1 accuracy_decimals: 1
id: bh1750_light id: bh1750_light
update_interval: 1s update_interval: 1s
filters:
- delta: 0.1
light: light:
- platform: status_led - platform: status_led
@ -308,6 +338,10 @@ interval:
then: then:
lambda: |- lambda: |-
if ((time(NULL)-id(LD1125F_Last_Time))>id(LD1125F_Clear_Time).state) { 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")) { if ((id(LD1125F_Clearence_Status) == false) || (id(LD1125F_Occupancy).state != "Clearance")) {
id(LD1125F_Occupancy).publish_state("Clearance"); id(LD1125F_Occupancy).publish_state("Clearance");
id(LD1125F_Clearence_Status) = true; id(LD1125F_Clearence_Status) = true;
@ -357,6 +391,10 @@ number:
data: !lambda |- data: !lambda |-
std::string th2st = "mth2=" + str_sprintf("%.0f",x) +"\r\n"; std::string th2st = "mth2=" + str_sprintf("%.0f",x) +"\r\n";
return std::vector<uint8_t>(th2st.begin(), th2st.end()); return std::vector<uint8_t>(th2st.begin(), th2st.end());
- delay: 200ms
- uart.write: # 保存用
id: LD1125F_UART_BUS
data: "save\r\n"
- platform: template - platform: template
name: ${upper_devicename} mth3 #mth3 is above 8m Sensitivity. name: ${upper_devicename} mth3 #mth3 is above 8m Sensitivity.
id: LD1125F_mth3 id: LD1125F_mth3
@ -375,6 +413,10 @@ number:
data: !lambda |- data: !lambda |-
std::string th3st = "mth3=" + str_sprintf("%.0f",x) +"\r\n"; std::string th3st = "mth3=" + str_sprintf("%.0f",x) +"\r\n";
return std::vector<uint8_t>(th3st.begin(), th3st.end()); return std::vector<uint8_t>(th3st.begin(), th3st.end());
- delay: 200ms
- uart.write: # 保存用
id: LD1125F_UART_BUS
data: "save\r\n"
- platform: template - platform: template
name: ${upper_devicename} Max Distance #rmax is max detection distance. name: ${upper_devicename} Max Distance #rmax is max detection distance.
id: LD1125F_rmax id: LD1125F_rmax
@ -394,6 +436,33 @@ number:
data: !lambda |- data: !lambda |-
std::string rmaxst = "rmax=" + str_sprintf("%.1f",x) +"\r\n"; std::string rmaxst = "rmax=" + str_sprintf("%.1f",x) +"\r\n";
return std::vector<uint8_t>(rmaxst.begin(), rmaxst.end()); return std::vector<uint8_t>(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<uint8_t>(utonsst.begin(), utonsst.end());
- delay: 200ms
- uart.write: # 保存用
id: LD1125F_UART_BUS
data: "save\r\n"
- platform: template - platform: template
name: ${upper_devicename} Clearence Time name: ${upper_devicename} Clearence Time
id: LD1125F_Clear_Time id: LD1125F_Clear_Time