diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index a5e0790..c9fac47 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -76,6 +76,10 @@ globals: initial_value: "true" - id: testCycleCount type: int + - id: debounce_restart + type: bool + restore_value: no + initial_value: 'false' captive_portal: @@ -183,29 +187,39 @@ switch: then: - if: condition: - or: - # Normal mode: input has water - - and: - - switch.is_off: tank_refill_mode - - binary_sensor.is_on: fluid_input_sensor - # Inverted mode: input is dry (destination is low, needs filling) - - and: - - switch.is_on: tank_refill_mode - - binary_sensor.is_off: fluid_input_sensor - # Bypass: dry protection not enabled - - switch.is_off: stop_pump_when_dry + - lambda: 'return id(debounce_restart);' then: - - logger.log: "Pump turning on - conditions met" - - text_sensor.template.publish: - id: last_pump_action - state: "Pump Started" - lambda: |- - id(pump_start_time) = millis(); + id(debounce_restart) = false; id(safety_alert_active) = false; + - logger.log: "Pump restarting after debounce verification" - script.execute: pump_safety_check else: - - logger.log: "Pump blocked - water conditions not met" - - switch.turn_off: pump_control + - if: + condition: + or: + # Normal mode: input has water + - and: + - switch.is_off: tank_refill_mode + - binary_sensor.is_on: fluid_input_sensor + # Inverted mode: input is dry (destination is low, needs filling) + - and: + - switch.is_on: tank_refill_mode + - binary_sensor.is_off: fluid_input_sensor + # Bypass: dry protection not enabled + - switch.is_off: stop_pump_when_dry + then: + - logger.log: "Pump turning on - conditions met" + - text_sensor.template.publish: + id: last_pump_action + state: "Pump Started" + - lambda: |- + id(pump_start_time) = millis(); + id(safety_alert_active) = false; + - script.execute: pump_safety_check + else: + - logger.log: "Pump blocked - water conditions not met" + - switch.turn_off: pump_control on_turn_off: then: - if: @@ -270,9 +284,11 @@ binary_sensor: inverted: true on_release: then: + - delay: !lambda 'return (int)id(sensor_debounce_seconds).state * 1000;' - if: condition: and: + - binary_sensor.is_off: fluid_input_sensor - switch.is_on: auto_refill - switch.is_on: tank_refill_mode - switch.is_off: pump_control @@ -285,7 +301,7 @@ binary_sensor: - platform: gpio name: Fluid Output - id: fulid_output_sensor + id: fluid_output_sensor icon: mdi:water device_class: moisture pin: @@ -321,6 +337,20 @@ number: unit_of_measurement: "s" restore_value: true mode: box + - platform: template + name: "Sensor Debounce Seconds" + id: sensor_debounce_seconds + icon: mdi:timer-sand + entity_category: config + disabled_by_default: true + optimistic: true + min_value: 0 + max_value: 30 + step: 1 + initial_value: 0 + unit_of_measurement: "s" + restore_value: true + mode: box sensor: - platform: internal_temperature @@ -438,14 +468,31 @@ script: condition: - switch.is_on: pump_control then: + # Stop when full (output wet) - stop first, verify after - if: condition: - and: - switch.is_on: stop_pump_when_full - - binary_sensor.is_on: fulid_output_sensor + - binary_sensor.is_on: fluid_output_sensor then: - - logger.log: "Pump stopping - tank full" - switch.turn_off: pump_control + - if: + condition: + - lambda: 'return id(sensor_debounce_seconds).state > 0;' + then: + - delay: !lambda 'return (int)id(sensor_debounce_seconds).state * 1000;' + - if: + condition: + - binary_sensor.is_off: fluid_output_sensor + then: + - logger.log: "Debounce: tank full was false alarm, restarting pump" + - lambda: 'id(debounce_restart) = true;' + - switch.turn_on: pump_control + else: + - logger.log: "Pump stopped - tank full (confirmed)" + else: + - logger.log: "Pump stopping - tank full" + # Safety timeout (unchanged) - if: condition: - lambda: |- @@ -455,6 +502,7 @@ script: then: - logger.log: "Pump stopping - safety" - switch.turn_off: pump_control + # Destination full in inverted mode (input wet) - if: condition: - and: @@ -462,8 +510,24 @@ script: - switch.is_off: stop_pump_when_full - binary_sensor.is_on: fluid_input_sensor then: - - logger.log: "Pump stopping - destination full (inverted mode)" - switch.turn_off: pump_control + - if: + condition: + - lambda: 'return id(sensor_debounce_seconds).state > 0;' + then: + - delay: !lambda 'return (int)id(sensor_debounce_seconds).state * 1000;' + - if: + condition: + - binary_sensor.is_off: fluid_input_sensor + then: + - logger.log: "Debounce: destination full was false alarm, restarting pump" + - lambda: 'id(debounce_restart) = true;' + - switch.turn_on: pump_control + else: + - logger.log: "Pump stopped - destination full (confirmed)" + else: + - logger.log: "Pump stopping - destination full (inverted mode)" + # Stop when dry (input dry) - if: condition: - and: @@ -471,8 +535,23 @@ script: - switch.is_off: tank_refill_mode - binary_sensor.is_off: fluid_input_sensor then: - - logger.log: "Pump stopping - input dry" - switch.turn_off: pump_control + - if: + condition: + - lambda: 'return id(sensor_debounce_seconds).state > 0;' + then: + - delay: !lambda 'return (int)id(sensor_debounce_seconds).state * 1000;' + - if: + condition: + - binary_sensor.is_on: fluid_input_sensor + then: + - logger.log: "Debounce: input dry was false alarm, restarting pump" + - lambda: 'id(debounce_restart) = true;' + - switch.turn_on: pump_control + else: + - logger.log: "Pump stopped - input dry (confirmed)" + else: + - logger.log: "Pump stopping - input dry" - delay: 1s - id: testScript then: