Fix IUVolume: skip first tick to avoid unreliable flow rate at valve … - #245
Open
Kolia56 wants to merge 1 commit into
Open
Fix IUVolume: skip first tick to avoid unreliable flow rate at valve …#245Kolia56 wants to merge 1 commit into
Kolia56 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a zone starts,
IUVolume._read_sensorcalculates the flow rate usingthe first two sensor ticks. With a pulse-based flow meter (e.g. 1 pulse/litre),
this first interval produces a wildly inflated flow rate.
Root cause
A pulse counter has a fixed resolution: each pulse represents a fixed volume.
At the moment the valve opens, the counter may be anywhere within the current
pulse interval. The first tick therefore represents only the remaining fraction
of that interval, not a full pulse volume of actual flow since opening.
Example with 1 litre/pulse resolution:
The effect is amplified on low-flow circuits: a line running at 3 l/min
accumulates 1 litre every ~20 s, so the ratio between the erroneous
volume_deltaand the very shorttime_deltais much larger than on ahigh-flow circuit (17 l/min, 1 pulse every ~3.5 s).
This was confirmed experimentally: the spike only appears at the start of a
zone (after
start_record), and the first reliable sensor value arrivesexactly after the first full litre has been consumed since opening.
![Flow rate spike before fix]

Fix
In
_read_sensor, when_total_readings == 1(i.e. the second tick, firstinterval), reset
_first_readingto the current tick and discard thecalculation. This ensures all subsequent flow rate calculations start from a
clean, reliable baseline where a complete pulse interval has elapsed since
the valve opened.
_total_readingsis reset to0by_reset_readings()on everystart_recordcall, so_total_readings == 1unambiguously identifies thefirst interval of a new recording — not a tick in the middle of an ongoing run.
Base
This PR is based on release tag
2025.12.0, not on the current HEAD ofmaster, to avoid any dependency on unreleased development work. It may be integratedit into the next release at your convenience.
Testing
Tested on a production system with: