Merge pull request #25 from durd/durd-patch-1

dedup logs and published states
This commit is contained in:
Screek Worshop 2024-08-08 07:27:23 +08:00 committed by GitHub
commit 34b12bb3fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -98,6 +98,8 @@ globals:
improv_serial: improv_serial:
logger: logger:
logs:
bh1750.sensor: INFO
debug: debug:
update_interval: 30s update_interval: 30s
@ -148,11 +150,47 @@ text_sensor:
icon: "mdi:format-text" icon: "mdi:format-text"
entity_category: "diagnostic" entity_category: "diagnostic"
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
filters:
- lambda: |-
static std::string last;
if (x == last)
return {};
last = x;
return x;
on_value: on_value:
lambda: |- lambda: |-
if (id(LD1125F_UART_Text).state.substr(0,3) == "occ") { std::string uart_text = id(LD1125F_UART_Text).state;
id(LD1125F_Distance).publish_state(atof(id(LD1125F_UART_Text).state.substr(9).c_str())); if (uart_text == "null") {
if ((time(NULL)-id(LD1125F_Last_Mov_Time))>id(LD1125F_Mov_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;
}
if (id(LD1125F_MovOcc_Binary).state == true) {
id(LD1125F_MovOcc_Binary).publish_state(false);
}
if (id(LD1125F_Mov_Binary).state == true) {
id(LD1125F_Mov_Binary).publish_state(false);
}
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"); id(LD1125F_Occupancy).publish_state("Occupancy");
if (id(LD1125F_MovOcc_Binary).state == false) { if (id(LD1125F_MovOcc_Binary).state == false) {
id(LD1125F_MovOcc_Binary).publish_state(true); id(LD1125F_MovOcc_Binary).publish_state(true);
@ -169,8 +207,8 @@ text_sensor:
id(LD1125F_Clearence_Status) = false; id(LD1125F_Clearence_Status) = false;
} }
} }
else if (id(LD1125F_UART_Text).state.substr(0,3) == "mov") { else if (uart_state == "mov" && distance > 0) {
id(LD1125F_Distance).publish_state(atof(id(LD1125F_UART_Text).state.substr(9).c_str())); 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) {
id(LD1125F_MovOcc_Binary).publish_state(true); id(LD1125F_MovOcc_Binary).publish_state(true);
@ -189,7 +227,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
@ -198,10 +235,12 @@ binary_sensor:
name: ${upper_devicename} Occupancy or Movement name: ${upper_devicename} Occupancy or Movement
id: LD1125F_MovOcc_Binary id: LD1125F_MovOcc_Binary
device_class: occupancy device_class: occupancy
publish_initial_state: True
- platform: template - platform: template
name: ${upper_devicename} Movement name: ${upper_devicename} Movement
id: LD1125F_Mov_Binary id: LD1125F_Mov_Binary
device_class: motion device_class: motion
publish_initial_state: True
sensor: sensor:
- platform: template - platform: template
@ -246,16 +285,20 @@ 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
update_interval: 0.2s
filters: # Use Fliter To Debounce filters: # Use Fliter To Debounce
- sliding_window_moving_average: #- heartbeat: 0.2s
window_size: 8 #- sliding_window_moving_average:
send_every: 2 # window_size: 8
- heartbeat: 0.2s # send_every: 2
- delta: 0%
- 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
@ -306,7 +349,7 @@ interval:
setup_priority: -200 setup_priority: -200
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_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;
@ -327,7 +370,7 @@ number:
optimistic: true optimistic: true
entity_category: config entity_category: config
restore_value: true #If you don't want to store the setting at ESP, set it to false. restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "60.0" #Default mth1 Setting initial_value: 60 #Default mth1 Setting
min_value: 10.0 min_value: 10.0
max_value: 600.0 max_value: 600.0
step: 5.0 step: 5.0
@ -345,7 +388,7 @@ number:
optimistic: true optimistic: true
entity_category: config entity_category: config
restore_value: true #If you don't want to store the setting at ESP, set it to false. restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "30" #Default mth2 Setting initial_value: 30 #Default mth2 Setting
min_value: 5 min_value: 5
max_value: 300 max_value: 300
step: 5 step: 5
@ -363,7 +406,7 @@ number:
entity_category: config entity_category: config
optimistic: true optimistic: true
restore_value: true #If you don't want to store the setting at ESP, set it to false. restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "20" #Default mth3 Setting initial_value: 20 #Default mth3 Setting
min_value: 5 min_value: 5
max_value: 200 max_value: 200
step: 5 step: 5
@ -382,7 +425,7 @@ number:
optimistic: true optimistic: true
unit_of_measurement: m unit_of_measurement: m
restore_value: true #If you don't want to store the setting at ESP, set it to false. restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "8" #Default rmax Setting initial_value: 8 #Default rmax Setting
min_value: 0.4 min_value: 0.4
max_value: 12 max_value: 12
step: 0.2 step: 0.2
@ -400,7 +443,7 @@ number:
optimistic: true optimistic: true
entity_category: config entity_category: config
restore_value: true #If you don't want to store the setting at ESP, set it to false. restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "5" #LD1125F Mov/Occ > Clearence Time Here initial_value: 5 #LD1125F Mov/Occ > Clearence Time Here
min_value: 0.5 min_value: 0.5
max_value: 20 max_value: 20
step: 0.5 step: 0.5
@ -411,8 +454,7 @@ number:
optimistic: true optimistic: true
entity_category: config entity_category: config
restore_value: true #If you don't want to store the setting at ESP, set it to false. restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "1" #LD1125F Mov > Occ Time Here initial_value: 1 #LD1125F Mov > Occ Time Here
min_value: 0.5 min_value: 0.5
max_value: 10 max_value: 10
step: 0.5 step: 0.5