Skip to content

fix(victron_mqtt): keep Victron's battery power sign, charge positive (1.1.1) - #266

Merged
frahlg merged 1 commit into
mainfrom
fix-255
Nov 22, 2026
Merged

frahlg merged 1 commit into
mainfrom
fix-255

Conversation

@frahlg

@frahlg frahlg commented Nov 22, 2026

Copy link
Copy Markdown
Member

What was wrong

victron_mqtt 1.1.0 emitted battery power as W = -bat_w, with the
comment "Victron: positive power = discharging". Victron's own sources say
the opposite, so a charging battery most likely showed as discharging and
the reverse. The driver is read-only, so this affected telemetry, planning
input and the site balance, not commands.

Evidence

  • Victron's Venus D-Bus page (victronenergy/venus wiki, "dbus", in the
    manifest's upstream_docs): on com.victronenergy.battery, /Dc/0/Power
    is "W positive when charged, negative when discharged", and /Dc/0/Current
    the same.
  • victronenergy/dbus-systemcalc-py copies the battery service's
    /Dc/0/Power into system/0/Dc/Battery/Power, the topic this driver
    reads. Its own comment says "battery: Positive: charging battery", and it
    sets the state to charging above +30 W and discharging below -30 W.
  • This repository's victron.lua reads the same D-Bus value through Modbus
    register 842 and does not negate it.

Change

  • drivers/lua/victron_mqtt.lua: pass Dc/Battery/Power through
    unchanged. Version 1.1.1. Battery current was already passed through.
  • drivers/tests/test_victron_mqtt_battery_sign.py: feeds +1500 W and
    -900 W and checks the emitted sign. Both tests fail on main and pass
    here.
  • Two scenarios in test_victron_mqtt_battery_limits.lua asserted the old
    negated value; they now expect Victron's sign.
  • CHANGELOG, manifest and generated files.

Tests

  • make test-driver ID=victron_mqtt: 62 passed, 5 skipped.
  • make check: 5227 passed, 929 skipped.

Not verified on hardware

Nobody has measured this on a real GX. An owner can check it: while the
battery charges and its SoC rises, the battery W in FTW should be
positive; while it discharges and the SoC falls, negative. On the GX itself,
N/<portal id>/system/0/Dc/Battery/Power should have the same sign as FTW
shows.

A keep-alive for this driver (#256) is a separate PR
stacked on this one.

Refs #255

🤖 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:11:51.512569Z a4010bc 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.

… (1.1.1)

The driver negated system/0/Dc/Battery/Power, so a charging battery
showed as discharging. Victron's D-Bus docs give battery power as
"positive when charged, negative when discharged", and
dbus-systemcalc-py copies the battery service's /Dc/0/Power into that
topic. victron.lua reads the same value at Modbus 842 and passes it
through. This driver now does the same. A harness test feeds +1500 W
and -900 W and checks the sign. Not measured on a real GX.

Refs #255

Signed-off-by: Fredrik Ahlgren <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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