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 0c44f4b..87564b4 100644 --- a/f2/yaml/beta-version/human-sensor-f2-beta-github.yaml +++ b/f2/yaml/beta-version/human-sensor-f2-beta-github.yaml @@ -1,6 +1,6 @@ # screek f2 yaml code # main ld1125h code from: https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome -# +# substitutions: devicename: "" upper_devicename: "" @@ -13,7 +13,7 @@ esphome: platformio_options: board_build.flash_mode: dio # board_build.f_cpu: 80000000L - project: + project: name: Screek.Human_Presence_Sensor version: F2 on_boot: @@ -23,9 +23,8 @@ esphome: id(cpu_speed) = ESP.getCpuFreqMHz(); - priority: 300 then: - # 写入版本号,未来使用公共变量!(23年7月17日_13时29分_) lambda: |- - id(screek_version).publish_state("V24.7.4_beta"); + id(screek_version).publish_state("Beta_V240708_1"); - priority: -200 then: - uart.write: @@ -75,7 +74,7 @@ external_components: type: git url: https://github.com/ssieb/custom_components #Thanks for @ssieb components. components: [ serial ] - + esp32: board: lolin_c3_mini framework: @@ -114,8 +113,10 @@ globals: initial_value: "false" improv_serial: - + logger: + logs: + bh1750.sensor: INFO debug: update_interval: 30s @@ -141,7 +142,7 @@ captive_portal: web_server: port: 80 - + text_sensor: - platform: template name: "SCREEK Version" @@ -173,6 +174,13 @@ text_sensor: icon: "mdi:format-text" entity_category: "diagnostic" 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: lambda: |- std::string uart_text = id(LD1125F_UART_Text).state; @@ -183,10 +191,10 @@ text_sensor: float distance = -1; std::string uart_state = ""; - if (uart_text.length() > 3){ + 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") { + if (uart_state == "occ" || uart_state == "mov") { distance = std::stof(uart_text.substr(9)); } } @@ -194,7 +202,7 @@ text_sensor: 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"); if (id(LD1125F_MovOcc_Binary).state == false) { id(LD1125F_MovOcc_Binary).publish_state(true); @@ -239,10 +247,12 @@ binary_sensor: name: ${upper_devicename} Occupancy or Movement id: LD1125F_MovOcc_Binary device_class: occupancy + publish_initial_state: True - platform: template name: ${upper_devicename} Movement id: LD1125F_Mov_Binary device_class: motion + publish_initial_state: True sensor: - platform: template @@ -259,7 +269,7 @@ sensor: id: sys_esp_temperature name: ESP Temperature lambda: return temperatureRead(); - unit_of_measurement: °C + unit_of_measurement: "°C" device_class: TEMPERATURE update_interval: 45s entity_category: "diagnostic" @@ -267,7 +277,7 @@ sensor: name: ESP Uptime id: sys_uptime update_interval: 60s - - platform: wifi_signal + - platform: wifi_signal name: RSSI id: wifi_signal_db update_interval: 60s @@ -289,8 +299,8 @@ sensor: accuracy_decimals: 2 # filters: # Use Fliter To Debounce # - sliding_window_moving_average: - # window_size: 8 - # send_every: 2 + # window_size: 8 + # send_every: 2 # - heartbeat: 0.2s - platform: bh1750 name: "Illuminance" @@ -350,7 +360,6 @@ 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); } @@ -501,4 +510,3 @@ number: min_value: 0.5 max_value: 10 step: 0.5 - diff --git a/f2/yaml/human-sensor-f2-stable-github.yaml b/f2/yaml/human-sensor-f2-stable-github.yaml index fe1db10..1987269 100644 --- a/f2/yaml/human-sensor-f2-stable-github.yaml +++ b/f2/yaml/human-sensor-f2-stable-github.yaml @@ -1,6 +1,6 @@ # screek f2 yaml code # main ld1125h code from: https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome -# +# substitutions: devicename: "" upper_devicename: "" @@ -13,7 +13,7 @@ esphome: platformio_options: board_build.flash_mode: dio # board_build.f_cpu: 80000000L - project: + project: name: Screek.Human_Presence_Sensor version: F2 on_boot: @@ -21,6 +21,10 @@ esphome: then: lambda: |- id(cpu_speed) = ESP.getCpuFreqMHz(); + - priority: 300 + then: + lambda: |- + id(screek_version).publish_state("V240708_1"); - priority: -200 then: - uart.write: @@ -28,21 +32,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 @@ -57,7 +74,7 @@ external_components: type: git url: https://github.com/ssieb/custom_components #Thanks for @ssieb components. components: [ serial ] - + esp32: board: lolin_c3_mini framework: @@ -96,10 +113,8 @@ globals: initial_value: "false" improv_serial: - + logger: - logs: - bh1750.sensor: INFO debug: update_interval: 30s @@ -125,8 +140,15 @@ captive_portal: 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,39 +172,20 @@ text_sensor: icon: "mdi:format-text" entity_category: "diagnostic" 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: lambda: |- - std::string uart_text = id(LD1125F_UART_Text).state; - 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); - } + 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) { + 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") { + if (uart_state == "occ" || uart_state =="mov") { distance = std::stof(uart_text.substr(9)); } } @@ -190,7 +193,7 @@ text_sensor: 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"); if (id(LD1125F_MovOcc_Binary).state == false) { id(LD1125F_MovOcc_Binary).publish_state(true); @@ -235,12 +238,10 @@ binary_sensor: name: ${upper_devicename} Occupancy or Movement id: LD1125F_MovOcc_Binary device_class: occupancy - publish_initial_state: True - platform: template name: ${upper_devicename} Movement id: LD1125F_Mov_Binary device_class: motion - publish_initial_state: True sensor: - platform: template @@ -257,7 +258,7 @@ sensor: id: sys_esp_temperature name: ESP Temperature lambda: return temperatureRead(); - unit_of_measurement: "°C" + unit_of_measurement: °C device_class: TEMPERATURE update_interval: 45s entity_category: "diagnostic" @@ -265,7 +266,7 @@ sensor: name: ESP Uptime id: sys_uptime update_interval: 60s - - platform: wifi_signal + - platform: wifi_signal name: RSSI id: wifi_signal_db update_interval: 60s @@ -285,13 +286,11 @@ sensor: icon: "mdi:signal-distance-variant" unit_of_measurement: "m" accuracy_decimals: 2 - update_interval: 0.2s - filters: # Use Fliter To Debounce - #- heartbeat: 0.2s - #- sliding_window_moving_average: - # window_size: 8 - # send_every: 2 - - delta: 0% + # 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 @@ -349,7 +348,10 @@ interval: setup_priority: -200 then: 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")) { id(LD1125F_Occupancy).publish_state("Clearance"); id(LD1125F_Clearence_Status) = true; @@ -370,7 +372,7 @@ number: optimistic: true entity_category: config restore_value: true #If you don't want to store the setting at ESP, set it to false. - initial_value: 60 #Default mth1 Setting + initial_value: "60.0" #Default mth1 Setting min_value: 10.0 max_value: 600.0 step: 5.0 @@ -381,6 +383,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 @@ -388,7 +394,7 @@ number: optimistic: true entity_category: config 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 max_value: 300 step: 5 @@ -399,6 +405,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 @@ -406,7 +416,7 @@ number: entity_category: config optimistic: true 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 max_value: 200 step: 5 @@ -417,6 +427,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 @@ -425,7 +439,7 @@ number: optimistic: true unit_of_measurement: m 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 max_value: 12 step: 0.2 @@ -436,6 +450,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 @@ -443,7 +484,7 @@ number: optimistic: true entity_category: config 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 max_value: 20 step: 0.5 @@ -454,7 +495,8 @@ number: optimistic: true entity_category: config 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 max_value: 10 step: 0.5 +