From 1a9a91ba15e88bcc6405bebe9b0581fd098e93a0 Mon Sep 17 00:00:00 2001 From: Bernd Schorgers Date: Thu, 14 Nov 2024 19:57:00 +0100 Subject: [PATCH] feat: Return NaN for distance when no target detected --- Integrations/ESPHome/Core.yaml | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index 5ef1209..445b214 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -246,26 +246,10 @@ binary_sensor: has_moving_target: name: Radar Moving Target id: radar_has_moving_target - on_state: - then: - - if: - condition: - binary_sensor.is_off: radar_has_moving_target - then: - - lambda: |- - id(moving_distance).publish_state(0); has_still_target: name: Radar Still Target id: radar_has_still_target - on_state: - then: - - if: - condition: - binary_sensor.is_off: radar_has_still_target - then: - - lambda: |- - id(still_distance).publish_state(0); - + ## Set Up Radar Zones Based On Distance - platform: template @@ -397,6 +381,11 @@ sensor: static float last_reported_value = 0.0; float current_value = x; + // Check if the radar_has_moving_target sensor is off + if (!id(radar_has_moving_target).state) { + return NAN; + } + // Check if the reduce_db_reporting switch is on if (id(reduce_db_reporting).state) { // Apply delta filter: only report if the value has changed by 2 or more @@ -420,6 +409,11 @@ sensor: static float last_reported_value = 0.0; float current_value = x; + // Check if the radar_has_still_target sensor is off + if (!id(radar_has_still_target).state) { + return NAN; + } + // Check if the reduce_db_reporting switch is on if (id(reduce_db_reporting).state) { // Apply delta filter: only report if the value has changed by 2 or more @@ -457,6 +451,11 @@ sensor: static float last_reported_value = 0.0; float current_value = x; + // Check if the radar_has_target sensor is off + if (!id(radar_has_target).state) { + return NAN; + } + // Check if the reduce_db_reporting switch is on if (id(reduce_db_reporting).state) { // Apply delta filter: only report if the value has changed by 2 or more