Skip to content

fix(victron, ferroamp_modbus): no meter or PV zeros from failed reads (2.2.1) - #270

Merged
frahlg merged 2 commits into
mainfrom
fix-258
Nov 22, 2026
Merged

frahlg merged 2 commits into
mainfrom
fix-258

Conversation

@frahlg

@frahlg frahlg commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

What was wrong

victron 2.2.0 and ferroamp_modbus 2.2.0 started every meter and PV
field at 0 and emitted both streams whether or not their reads answered.
docs/WRITING-A-DRIVER.md ("Never fabricate") says a field that did not
answer is left out, and a stream whose defining reading did not answer is
not emitted. A 0 W meter reading from a failed read looks like a site in
balance. #254 fixed the battery side of both drivers; this does the meter
and PV sides.

Change

victron 2.2.1

  • Meter: emitted only when the grid power read (820-822) answers, with
    all three phases. Its metrics likewise.
  • PV: the sum of the AC-coupled (808-810) and DC-coupled (850) parts that
    answered. A GX with no DC-coupled MPPT does not answer 850, so PV is the
    AC part alone; with neither, there is no PV reading. So a one-off
    failure of 808 while 850 answers sends a PV figure without the
    AC-coupled part until the next poll. That trade-off is kept and noted
    in the CHANGELOG.

ferroamp_modbus 2.2.1

  • Meter: emitted only when the grid power (3100) answers. Frequency (2016),
    voltages (2032), currents (3112) and energy counters (3064) are each set
    only when their read answered. Per-phase watts (V x I) need both.
  • PV: emitted only when the solar power (5100) answers; the energy counter
    (5064) only when it answered.
  • A reply with fewer registers than asked for counts as failed for these
    reads. decode_f32_ws_at turned the missing word into 0, and the
    invented-number probe does not catch that, since the value was read in
    its healthy phase.
  • Fields that answered still go to history as metrics, also when the meter
    stream is left out.

Both drivers leave drivers/tests/invented-number-baseline.json
(victron was 5, ferroamp_modbus 15); make invented-number-report now
finds nothing for either. make absent-register-report settles every
register for both.

Tests

  • drivers/tests/test_victron_meter_pv.py, 6 scenarios: all answer, grid
    read fails, both PV reads fail, no DC PV, no AC PV, nothing answers.
  • drivers/tests/test_ferroamp_modbus_meter_pv.py, 9 scenarios: all answer,
    grid power fails, voltage fails, current fails, frequency and energy fail,
    PV power fails, PV energy fails, short reply, nothing answers.
  • 11 of the 15 fail on main and pass here. The 4 that pass on main
    (each driver's "all answer", and victron's "no DC PV" and "no AC PV")
    check behaviour that must not change.
  • make test-driver ID=victron: 117 passed, 10 skipped.
    make test-driver ID=ferroamp_modbus: 65 passed, 4 skipped.
  • make check on main 2cf08cb: 5258 passed, 928 skipped.

Not verified on hardware

Neither driver has been run against a real GX or EnergyHub for this
change. On a healthy device the readings are the same as before; the
difference shows only when a read fails.

Found on the way, not changed here

decode_f32_ws_at in ferroamp_modbus also returns 0 for a register that
answers with NaN or infinity, which the driver treats as "not present".
That is a reply, not a failed read, and it reaches the battery fields too.

A parallel change to fronius, alphaess, kstar and goodwe may also edit
invented-number-baseline.json. The lines sit next to each other, so
whichever lands second may need a one-line merge.

Refs #258

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T12:31:12.545580Z b904044 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

frahlg and others added 2 commits November 22, 2026 13:46
… (2.2.1)

Both drivers sent 0 on the meter and PV streams when a read failed. A
0 W meter reading looks like a site in balance. Each field now comes
only from a register that answered, and the meter and PV streams only
from their power reads: 820-822 and 808/850 on victron, 3100 and 5100
on ferroamp_modbus. ferroamp_modbus also treats a reply with fewer
registers than asked for as failed, since the missing word decoded as
0. Harness tests cover each failed read; both drivers leave the
invented-number baseline. Not checked on hardware.

Refs #258

Signed-off-by: Fredrik Ahlgren <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A one-off failure of the AC-coupled PV read (808) while 850 answers sends
a PV figure without the AC-coupled part until the next poll. Keep that
trade-off and say so.

Refs #258

Signed-off-by: Fredrik Ahlgren <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@frahlg
frahlg merged commit 0b8cc26 into main Nov 22, 2026
5 checks passed
@frahlg
frahlg deleted the fix-258 branch November 22, 2026 12:50
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