dedup logs and published states

This commit is contained in:
David 2024-07-24 14:05:23 +02:00 committed by GitHub
parent 06f5726673
commit 11519a1373
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,6 @@
# screek f2 yaml code # screek f2 yaml code
# main ld1125h code from: https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome # main ld1125h code from: https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome
# #
substitutions: substitutions:
devicename: "" devicename: ""
upper_devicename: "" upper_devicename: ""
@ -13,7 +13,7 @@ esphome:
platformio_options: platformio_options:
board_build.flash_mode: dio board_build.flash_mode: dio
# board_build.f_cpu: 80000000L # board_build.f_cpu: 80000000L
project: project:
name: Screek.Human_Presence_Sensor name: Screek.Human_Presence_Sensor
version: F2 version: F2
on_boot: on_boot:
@ -57,7 +57,7 @@ external_components:
type: git type: git
url: https://github.com/ssieb/custom_components #Thanks for @ssieb components. url: https://github.com/ssieb/custom_components #Thanks for @ssieb components.
components: [ serial ] components: [ serial ]
esp32: esp32:
board: lolin_c3_mini board: lolin_c3_mini
framework: framework:
@ -96,8 +96,10 @@ globals:
initial_value: "false" initial_value: "false"
improv_serial: improv_serial:
logger: logger:
logs:
bh1750.sensor: INFO
debug: debug:
update_interval: 30s update_interval: 30s
@ -123,7 +125,7 @@ captive_portal:
web_server: web_server:
port: 80 port: 80
text_sensor: text_sensor:
- platform: debug - platform: debug
reset_reason: reset_reason:
@ -148,10 +150,46 @@ 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 (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) { 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) {
@ -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);
@ -226,7 +264,7 @@ sensor:
name: ESP Uptime name: ESP Uptime
id: sys_uptime id: sys_uptime
update_interval: 60s update_interval: 60s
- platform: wifi_signal - platform: wifi_signal
name: RSSI name: RSSI
id: wifi_signal_db id: wifi_signal_db
update_interval: 60s update_interval: 60s
@ -247,15 +285,17 @@ sensor:
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 - 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
@ -415,4 +455,3 @@ number:
min_value: 0.5 min_value: 0.5
max_value: 10 max_value: 10
step: 0.5 step: 0.5