Skip to content

feat: implement ThrottledSensorMixin to reduce Home Assistant write amplification#62

Open
celestinjr wants to merge 2 commits intoCrewski:mainfrom
celestinjr:feat/throttled-sensor-mixin
Open

feat: implement ThrottledSensorMixin to reduce Home Assistant write amplification#62
celestinjr wants to merge 2 commits intoCrewski:mainfrom
celestinjr:feat/throttled-sensor-mixin

Conversation

@celestinjr
Copy link
Copy Markdown

Problem

High-frequency push-driven sensors (pump speed, power, temps, filter pressure)
cause write amplification in InfluxDB and high update churn in Home Assistant.

Solution

Implement a reusable ThrottledSensorMixin that intelligently throttles state
updates with two modes:

  • Numeric (delta-based): Small changes deferred to interval timer, large
    changes immediate, identical values skipped (pump speed, power, temps)
  • Binary (exact-match): Any value change publishes immediately, identical
    values skipped (pump running state, filter on/off)

Throttle thresholds are configurable per-entity and defined in const.py.

Entities Throttled

  • Pump sensors: speed (RPM), power (W), flow (GPM), running state
  • Temperature sensors: air/pool/spa temps, temp probes
  • Filter sensors: on/off state, pressure (PSI), clean percentage
  • Body temps (pool/spa)

Additional Fix

Also fixes: PumpSpeedSensor max_speed/min_speed tuple bug (now returns scalar).

Testing

  • 26 new tests cover all throttle scenarios and entity types
  • All tests passing

Dependency

This PR is rebased on top of #61 (fix/pump-running-state-regal-modbus).
The running state fix is included in this branch. Recommend reviewing/merging
that fix first, then this enhancement.

…nd==10

PumpOnSensor relied on command==10 to determine if a pump is running.
This is incorrect for Regal Modbus pumps, which emit command=4 while
actively running (e.g. rpm=3450, watts=1406, command=4), causing the
running state sensor to incorrectly toggle off/on with each state update.

Fix: for non-relay pumps, use rpm>0 or watts>0 as the running indicator.
Relay-based pumps retain existing relay>0 logic.

Aligns with the same fix applied in nodejs-poolController-dashPanel.
Implement intelligent throttling for high-frequency push-driven sensors across
the integration (pump, temperature, filter sensors). Reduces HomeAssistant/InfluxDB writes
while preserving responsiveness through configurable delta-based and binary
throttling modes. Also fixes PumpSpeedSensor max_speed scalar bug.
@celestinjr
Copy link
Copy Markdown
Author

Depends on #61 . Please merge that fix first for cleaner history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant