From ab51496573ccec3f465ee5b357586955fdd0386e Mon Sep 17 00:00:00 2001 From: Brandon Harvey Date: Tue, 10 Mar 2026 12:01:04 -0500 Subject: [PATCH 1/3] feat: add Pump Activity event entity for HA logbook Replaces the homeassistant.action logbook.log approach from #32 with an ESPHome event entity, which surfaces natively in the HA logbook without requiring API actions to be enabled on the device. Fires three event types: - auto_refill_triggered: CPAP auto refill + invert water logic triggers pump - pump_started: pump_control turns on and conditions are met - pump_stopped: pump_control turns off --- Integrations/ESPHome/Core.yaml | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index 1dc1635..4335d9e 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -173,6 +173,9 @@ switch: - switch.is_off: stop_pump_when_dry then: - logger.log: "Pump turning on - conditions met" + - event.trigger: + id: pump_activity_event + event_type: pump_started - lambda: |- id(pump_start_time) = millis(); id(safety_alert_active) = false; @@ -186,6 +189,9 @@ switch: id(pump_start_time) = 0; id(safety_alert_active) = false; - logger.log: "Pump turned off" + - event.trigger: + id: pump_activity_event + event_type: pump_stopped binary_sensor: - platform: status @@ -245,11 +251,9 @@ binary_sensor: - switch.is_off: pump_control then: - logger.log: "Auto refill triggered - tank level low" - - homeassistant.action: - action: logbook.log - data: - name: "PUMP-1" - message: "Auto refill triggered - tank level low" + - event.trigger: + id: pump_activity_event + event_type: auto_refill_triggered - script.execute: pumpUntilFull - platform: gpio @@ -333,6 +337,16 @@ light: min_brightness: 50% max_brightness: 100% +event: + - platform: template + name: "Pump Activity" + id: pump_activity_event + icon: mdi:pump + event_types: + - auto_refill_triggered + - pump_started + - pump_stopped + text_sensor: - platform: wifi_info ip_address: From dd9cb47fbde60d335b8fa51e06120d631efd2820 Mon Sep 17 00:00:00 2001 From: Brandon Harvey Date: Tue, 10 Mar 2026 12:11:02 -0500 Subject: [PATCH 2/3] fix: guard pump_stopped event and log against rejected starts pump_start_time is only set when the pump actually starts successfully. Checking != 0 before logging and emitting pump_stopped prevents false logbook entries when a start is rejected and switch.turn_off is called from the else branch of on_turn_on. --- Integrations/ESPHome/Core.yaml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index 4335d9e..0ecf95c 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -185,13 +185,17 @@ switch: - switch.turn_off: pump_control on_turn_off: then: + - if: + condition: + lambda: 'return id(pump_start_time) != 0;' + then: + - logger.log: "Pump turned off" + - event.trigger: + id: pump_activity_event + event_type: pump_stopped - lambda: |- id(pump_start_time) = 0; id(safety_alert_active) = false; - - logger.log: "Pump turned off" - - event.trigger: - id: pump_activity_event - event_type: pump_stopped binary_sensor: - platform: status From 9a9644a257192dd1dd8f628bce856e3d4517cb69 Mon Sep 17 00:00:00 2001 From: Brandon Harvey Date: Tue, 10 Mar 2026 13:02:40 -0500 Subject: [PATCH 3/3] fix: replace event entity with text sensor for readable HA logbook entries ESPHome event entities show only a generic 'detected an event' string in the HA logbook. Replaces the Pump Activity event entity with a Last Pump Action text sensor whose state changes (Auto Refill Triggered, Pump Started, Pump Stopped) appear verbatim in the HA logbook. --- Integrations/ESPHome/Core.yaml | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index 0ecf95c..022b2c8 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -173,9 +173,9 @@ switch: - switch.is_off: stop_pump_when_dry then: - logger.log: "Pump turning on - conditions met" - - event.trigger: - id: pump_activity_event - event_type: pump_started + - text_sensor.template.publish: + id: last_pump_action + state: "Pump Started" - lambda: |- id(pump_start_time) = millis(); id(safety_alert_active) = false; @@ -190,9 +190,9 @@ switch: lambda: 'return id(pump_start_time) != 0;' then: - logger.log: "Pump turned off" - - event.trigger: - id: pump_activity_event - event_type: pump_stopped + - text_sensor.template.publish: + id: last_pump_action + state: "Pump Stopped" - lambda: |- id(pump_start_time) = 0; id(safety_alert_active) = false; @@ -255,9 +255,9 @@ binary_sensor: - switch.is_off: pump_control then: - logger.log: "Auto refill triggered - tank level low" - - event.trigger: - id: pump_activity_event - event_type: auto_refill_triggered + - text_sensor.template.publish: + id: last_pump_action + state: "Auto Refill Triggered" - script.execute: pumpUntilFull - platform: gpio @@ -341,17 +341,11 @@ light: min_brightness: 50% max_brightness: 100% -event: +text_sensor: - platform: template - name: "Pump Activity" - id: pump_activity_event + name: "Last Pump Action" + id: last_pump_action icon: mdi:pump - event_types: - - auto_refill_triggered - - pump_started - - pump_stopped - -text_sensor: - platform: wifi_info ip_address: name: "IP Address"