Skip to content

Fix IUVolume: skip first tick to avoid unreliable flow rate at valve … - #245

Open
Kolia56 wants to merge 1 commit into
rgc99:masterfrom
Kolia56:fix/iuvolume-skip-first-tick-v2
Open

Fix IUVolume: skip first tick to avoid unreliable flow rate at valve …#245
Kolia56 wants to merge 1 commit into
rgc99:masterfrom
Kolia56:fix/iuvolume-skip-first-tick-v2

Conversation

@Kolia56

@Kolia56 Kolia56 commented Jul 7, 2026

Copy link
Copy Markdown

Problem

When a zone starts, IUVolume._read_sensor calculates the flow rate using
the 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:

  • Counter is at 0.99 L into the current pulse when the valve opens
  • The first tick fires after only 0.01 L of actual flow (~0.6 s on a 3 l/min circuit)
  • Yet it is counted as 1 L → apparent flow = 100 l/min instead of 3 l/min

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_delta and the very short time_delta is much larger than on a
high-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 arrives
exactly after the first full litre has been consumed since opening.

![Flow rate spike before fix]
image

Fix

In _read_sensor, when _total_readings == 1 (i.e. the second tick, first
interval), reset _first_reading to the current tick and discard the
calculation. 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_readings is reset to 0 by _reset_readings() on every
start_record call, so _total_readings == 1 unambiguously identifies the
first 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 of
master, to avoid any dependency on unreleased development work. It may be integrated
it into the next release at your convenience.

Testing

Tested on a production system with:

  • 1 pulse/litre flow meter on the main supply line
  • 15 circuits in sequence, ranging from 3 l/min to 17 l/min
  • Spike completely eliminated on all circuits after fix
  • Flow rate stabilises correctly from the third tick onward

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