Skip to content

[cpap] Add invert water logic and auto refill for CPAP filling use case#28

Merged
Bunton33 merged 3 commits intobetafrom
cpap-invert-water-logic
Mar 3, 2026
Merged

[cpap] Add invert water logic and auto refill for CPAP filling use case#28
Bunton33 merged 3 commits intobetafrom
cpap-invert-water-logic

Conversation

@bharvey88
Copy link
Contributor

@bharvey88 bharvey88 commented Mar 1, 2026

Version: 25.12.18.1

What does this implement/fix?

Adds inverted water logic and auto refill support for CPAP humidifier tank filling use case.

  • Adds Invert Water Logic switch (off by default): flips the meaning of the input sensor so that DRY = destination is low = start pumping, and WET = destination is full = stop pumping. Correct behavior for CPAP auto-fill where sensor 1 is placed at the low-level mark inside the CPAP tank.
  • Adds Auto Refill switch (off by default): when both Auto Refill and Invert Water Logic are enabled, the pump automatically triggers pumpUntilFull whenever the input sensor goes DRY (tank level drops below sensor 1).
  • Guards the existing Stop Pump When Input Dry check so it does not fire in inverted mode.
  • All existing behavior is unchanged when Invert Water Logic is OFF.

CPAP Setup Instructions

  1. Place Sensor 1 at the LOW water level mark inside CPAP tank → plug into Input port
  2. Place Sensor 2 at the FULL/MAX water level mark inside CPAP tank → plug into Output port
  3. Enable Invert Water Logic in Home Assistant
  4. Enable Stop Pump When Output Wet
  5. Enable Auto Refill for fully automatic operation
  6. Set Max Safe Run Time as a safety backstop

Closes #22

Types of changes

  • Bugfix (fixed change that fixes an issue)
  • New feature (thanks!)
  • Breaking change (repair/feature that breaks existing functionality)
  • Dependency Update - Does not publish
  • Other - Does not publish
  • Website of github readme file update - Does not publish
  • Github workflows - Does not publish

Checklist / Checklijst:

  • The code change has been tested and works locally
  • The code change has not yet been tested

If user-visible functionality or configuration variables are added/modified:

  • Added/updated documentation for the web page

Summary by CodeRabbit

Release Notes

  • New Features

    • Added invert water logic switch to support alternative pump operation mode
    • Added auto-refill switch for automatic system replenishment based on sensor conditions
  • Improvements

    • Enhanced pump activation logic to function in both normal and inverted modes
    • Strengthened pump safety mechanisms with improved dry-protection handling

Adds two new optional config switches (off by default):
- Invert Water Logic: flips input sensor meaning so DRY = destination low = start pump, WET = destination full = stop pump
- Auto Refill: automatically triggers pumpUntilFull when input sensor goes dry in inverted mode

Resolves #22
@coderabbitai
Copy link

coderabbitai bot commented Mar 1, 2026

Warning

Rate limit exceeded

@bharvey88 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 27 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 2b6250e and 0519e65.

📒 Files selected for processing (1)
  • Integrations/ESPHome/Core.yaml

Walkthrough

This PR adds automated CPAP reservoir refill logic by introducing two new template switches (invert_water_logic and auto_refill) to the ESPHome configuration. It modifies pump activation conditions to support both normal and inverted water detection modes, and adds an auto-refill trigger that activates the pump when the fluid input sensor is released under specific conditions.

Changes

Cohort / File(s) Summary
ESPHome Pump Control Configuration
Integrations/ESPHome/Core.yaml
Adds two new template switches (invert_water_logic, auto_refill) and extends pump activation/stop logic to support inverted water detection mode. Adds on_release trigger to fluid_input_sensor for automatic refill when both auto_refill and invert_water_logic are active. Updates pump safety conditions to handle both normal and inverted modes.

Sequence Diagram

sequenceDiagram
    participant FIS as Fluid Input Sensor
    participant AR as Auto Refill Switch
    participant IWL as Invert Water Logic Switch
    participant PC as Pump Control
    participant Pump as Pump System
    
    FIS->>AR: on_release event triggered
    AR->>AR: Check if auto_refill is on
    AR->>IWL: Check if invert_water_logic is on
    IWL->>PC: Check if pump_control is off
    PC->>Pump: Conditions met: execute pumpUntilFull
    Pump->>Pump: Log action and refill reservoir
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • PR #21: Modifies the same pump/input "dry" logic by flipping the fluid_input_sensor check; this PR extends that same logic with conditional inversion support and auto-refill functionality.

Suggested reviewers

  • TrevorSchirmer

Poem

🐰 A pump that thinks, a logic reversed,
Water flows where thirst is immersed,
Auto-refill hops with gentle grace,
CPAP dreams find their perfect place! 💧

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding invert water logic and auto refill for CPAP filling, which matches the primary objectives of the changeset.
Linked Issues check ✅ Passed The pull request successfully implements all coding requirements from issue #22: Sensor 1 detects low levels via inverted logic, Sensor 2 stops pump when full, and automatic refill is enabled via auto_refill switch.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the CPAP automated refill feature: adding invert_water_logic and auto_refill switches, modifying pump activation logic, and extending safety conditions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cpap-invert-water-logic

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Integrations/ESPHome/Core.yaml`:
- Around line 420-427: The inverted-mode branch currently stops the pump when
invert_water_logic is true and fluid_input_sensor goes wet, which can
prematurely stop pumpUntilFull; update the condition in that branch so it checks
the actual full-level sensor (the full-stop sensor used by pumpUntilFull) rather
than fluid_input_sensor (or add an additional check requiring the full-level
sensor to be on) before calling switch.turn_off on pump_control; locate the
branch using invert_water_logic, fluid_input_sensor and pump_control and
replace/augment the condition to reference the full-level sensor used by
pumpUntilFull.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d73a082 and 2b6250e.

📒 Files selected for processing (1)
  • Integrations/ESPHome/Core.yaml

When stop_pump_when_full is ON, the output sensor already handles full
detection. Skip the inverted-mode input sensor stop to prevent the pump
from stopping as water passes the low-level sensor on the way to full.
@Bunton33 Bunton33 merged commit 1d3fc49 into beta Mar 3, 2026
8 checks passed
@Bunton33 Bunton33 deleted the cpap-invert-water-logic branch March 3, 2026 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants