Skip to content

feat(victron_mqtt, victron, ferroamp_modbus, zap): what the battery can do now - #254

Merged
frahlg merged 2 commits into
mainfrom
battery-limits-g4
Nov 22, 2026
Merged

frahlg merged 2 commits into
mainfrom
battery-limits-g4

Conversation

@frahlg

@frahlg frahlg commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Drivers now report what the battery can do now, per the contract in #250 (docs/WRITING-A-DRIVER.md, "What a battery can do now"). This PR covers victron, victron_mqtt, ferroamp, ferroamp_modbus and zap.

The branch is rebased on main after #250 and #251 (sungrow 1.7.0). The second commit addresses the review: victron_mqtt now ages cached BMS values, and ferroamp_modbus sends whatever battery field answered.

Refs #250

Per driver

victron_mqtt 1.1.0: new fields

Field / metric Source Confidence
available_charge_W BMS CCL N/+/battery/<inst>/Info/MaxChargeCurrent (A) × .../Dc/0/Voltage from the same BMS High for the path. Medium for "live" (see below)
available_discharge_W BMS DCL .../Info/MaxDischargeCurrent (A) × the same voltage. DCL 0 sends 0 W Same as above
temperature_C N/+/system/0/Dc/Battery/Temperature, which the driver already subscribed to High
battery_temp_c, battery_charge_limit_a, battery_discharge_limit_a, battery_available_charge_w, battery_available_discharge_w, battery_cell_temp_min_c, battery_cell_temp_max_c The values above, plus .../System/MinCellTemperature and MaxCellTemperature High for the path
  • Which BMS. The GX names the BMS it uses for DVCC in system/0/ActiveBmsInstance (dbus-systemcalc-py delegates/batteryservice.py). The driver uses that BMS. Until the GX names one, it uses the only service that sent a limit. If two or more did, it uses none. This avoids mixing a single Lynx BMS's limit with the parallel service's.
  • Freshness. Venus publishes a value only when it changes and never repeats it on its own. So a quiet topic is not a stale one: a fixed CCL, or a full pack's 100 % SoC, can stand for hours.
    • {"value": null} or an empty payload (the device left the D-Bus) clears the value.
    • The watts need the BMS's own voltage from the last 60 s. That voltage moves in 0.01 V steps and changes within seconds once current flows. A pack at rest can hold its voltage longer; then the watts are left out.
    • The BMS's CCL/DCL and cell temperatures count only while that BMS has sent something in the last 60 s, in practice its voltage. A fixed CCL stays valid while its BMS keeps talking and goes with it.
    • 60 s with no message at all forgets every battery value: SoC, V, A, temperature and all BMS values. Venus stops publishing 60 s after the last keep-alive (dbus-flashmq README), and a null sent while the driver was not listening is lost.
    • I did not give SoC or the system temperature an age cap of their own. A sane one needs the driver to send a keep-alive that asks for a full republish every 30 s or so. Without that, a cap would drop a full pack's SoC. The driver sends no keep-alive; I did not add one here.
    • Limits and metrics go out only with a fresh battery power message, the driver's existing rule, so an idle poll emits nothing.
  • Manifest note. The GX-devices entry says that with several battery services and no ActiveBmsInstance yet, no limits are sent, and that the driver needs another client to keep the GX publishing.
  • Fabricated zeros fixed. SoC, V, A and temperature started at 0. A GX that sent only power showed an empty pack at 0 °C.
  • Unconfirmed: is CCL/DCL live? Victron's DVCC page says the BMS sends CCL as "the maximum charge current requested by the battery". It also says some makes send dynamic values and others a fixed one, and gives no update rate. It is the BMS's own value, not a rating the driver knows. I noted this in the code.

victron 2.2.0: a wrong temperature removed, no new fields

  • Register 844 is not a temperature. On com.victronenergy.system, 844 is /Dc/Battery/State (0 idle, 1 charging, 2 discharging). The driver read it as 0.1 °C, so temp_c and battery_temp_c showed 0.0 to 0.2 °C. The system service has no temperature register. The driver now reads 840–843 and reports no temperature.
  • Failed reads. A failed battery read now sends no battery reading and no battery metrics. Before, it sent 0 V / 0 A / 0 W / 0 %.
  • Why no new fields. CCL/DCL (307/308), battery temperature (262) and cell temperatures (318/319) are on com.victronenergy.battery. The GX serves that service on its own unit ID. host.modbus_read has no unit-ID argument, so this one-unit driver cannot reach it. Source: Victron dbus_modbustcp/attributes.csv, the source of the CCGX register list xlsx.

ferroamp: unchanged, nothing documented

Ferroamp External API Rev E (2021-03-22, the MQTT spec Ferroamp links today) has no battery temperature or live limit:

  • ESO temp is "Measured inside ESO". That is the converter, not the battery. The HA integration calls it "PCB Temperature".
  • ESM ratedPower is a rating.
  • ehub has no inverter temperature or grid headroom.

The control "Max allowed power" appears only as NAK text. The undocumented iavbl* load-balancing currents ("PB1, separate branch not described here") are fuse headroom for loads, not inverter headroom. The driver had no fabricated battery zeros. This differs from the brief, which expected ESO limits on MQTT. I found none in the spec.

ferroamp_modbus 2.2.0: fabricated zeros only

  • Ferroamp Modbus TCP Rev D (2024-06-03) has no battery temperature, no live limit and no inverter temperature. Import/export thresholds 8002/8012 are written settings, so they are not used.
  • Each battery field now comes only from a register that answered. The driver sends whatever answered, so a failed power read (6100) no longer drops a good SoC and energy counters. With nothing answered, it sends no battery reading. This follows the doc's "emit the battery DER when at least one of them did".
  • The float decoder now works on 16-bit halves. It compared the word with 0x80000000, which is negative under 32-bit Lua integers, so every float decoded wrong in the harness. FTW (gopher-lua) and Blixt L1 were not affected. This was needed to test scale and sign.

zap 3.2.0: temperature fixed, inverter_temp_c added

  • Battery temperature. temp_c now comes only from battery temperature_C. The Zap firmware's data-model README defines it as the battery's own cell or pack temperature (data model 2.7.0). Older firmware's battery heatsink_C was the battery register on Solis, Sungrow, Deye, Huawei and SMA. On Pixii it was the cabinet (TmpCab) and on Ferroamp the ESO converter. The driver cannot tell which, so it is dropped. Confidence: high (read from srcful-zap-x-firmware).
  • New metric. inverter_temp_c comes from the inverter DER's temperature_C.
  • Range. Temperatures outside -40..100 °C are dropped.
  • Not used: upper_limit_W / lower_limit_W. When a profile does not set them, the firmware derives them from ratings, PV and the SoC window, and the payload does not say which. available_*_Wh are derived from the SoC window and capacity. None is a battery-reported limit.
  • No upstream_docs entry. The Zap API page (developer.sourceful.energy) did not resolve from here, and the firmware repo is private. Both are cited in comments.

Found, not fixed (out of scope)

  • victron_mqtt battery W sign. This PR keeps it as it was. The driver negates /Dc/Battery/Power, calling it "positive = discharging". Victron's dbus wiki gives battery /Dc/0/Power as positive when charging, and the Modbus driver passes 842 through unchanged. The review agrees that main very likely inverts it. It goes in its own issue, which needs a GX measurement.
  • victron_mqtt keep-alive. The driver sends no keep-alive (R/<portal>/keepalive). dbus-flashmq publishes only while some client keeps it alive. Values that seldom change, such as a fixed CCL or ActiveBmsInstance, arrive only on a full republish.
  • Meter/PV zeros on failed reads. victron and ferroamp_modbus still send meter and PV zeros on failed reads. They stay in invented-number-baseline.json, which drops from 10 to 5 and from 18 to 15.

Tests

  • New harness tests, each with a Python wrapper:
    • test_victron_mqtt_battery_limits: scale; DCL 0; no voltage; null and empty payloads; BMS selection; ranges; nothing invented.
    • Age cases in the same test: a BMS goes quiet with the link up (limits gone at 61 s, kept at 50 s); a fixed CCL kept for 120 s while the voltage moves; a 61 s link gap forgets everything, with and without an idle poll; a 50 s gap keeps everything.
    • test_victron_battery: 844 is not a temperature; failed read.
    • test_ferroamp_modbus_battery: scale and sign; each failed read, where a failed power read keeps SoC and counters; all reads failed.
  • Four new zap scenarios: v1 heatsink dropped, battery-only temperatures, out of range, edges, null.
  • I checked that the new tests fail against the main drivers.
  • After the rebase and fixes, make test-driver ID= passes for victron, victron_mqtt, ferroamp_modbus and zap. ferroamp is unchanged and passed before the rebase.
  • make check: 5075 passed, 929 skipped.

Not verified on hardware.

Sources

The new public URLs are in each manifest's upstream_docs.

🤖 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-22T09:21:17.480788Z e75b4f0 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e75b4f024e

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread drivers/lua/zap.lua
emit_optional_metric("battery_dc_a" .. tag, dc_side(battery, "A"), "A")
emit_optional_metric("battery_temp_c" .. tag, number(battery.heatsink_C) or number(battery.temperature_C), "°C")
emit_optional_metric("battery_temp_c" .. tag, battery_temperature(battery), "°C")
emit_optional_metric("inverter_temp_c" .. tag, inverter_temperature(data), "°C")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Emit inverter temperature independently of battery telemetry

For a Zap configured with read_pv = true and the default read_battery = false, the new inverter_temp_c metric is never emitted, even when the fetched snapshot contains a valid inverter.temperature_C. This call is inside emit_battery, which driver_poll only invokes when battery reading is enabled; it also requires a discovered battery and a battery payload. I reproduced this with a solar-only device reporting 45 °C: pv_heatsink_c was emitted, but inverter_temp_c was absent. Emit the inverter metric from a shared per-device path so it also works for PV-only inverters without requiring battery opt-in.

Useful? React with 👍 / 👎.

…an do now

victron_mqtt 1.1.0 reports the BMS's charge and discharge current limits
(CCL/DCL) as available_charge_W / available_discharge_W, times the voltage
the same BMS reports, plus battery and cell temperatures, and the matching
metrics. It picks the BMS the GX names in ActiveBmsInstance. Battery SoC,
voltage, current and temperature no longer start at 0, and a null or empty
payload clears a value.

victron 2.2.0 stops reading register 844 as a temperature: it is the
battery state. A failed battery read sends no battery reading.

ferroamp_modbus 2.2.0 leaves out battery fields whose read failed and
decodes floats on 16-bit halves.

zap 3.2.0 takes the battery temperature only from data model 2.7.0's
temperature_C, drops temperatures outside -40..100 °C and adds
inverter_temp_c.

ferroamp is unchanged: its External API (Rev E) publishes no battery
temperature or live limit.

Refs #250

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
…attery field that answered

victron_mqtt: the watts need the BMS's voltage from the last 60 s, the
BMS's limits and cell temperatures count only while that BMS has sent
something in the last 60 s, and 60 s with no message at all forgets every
battery value (Venus stops publishing 60 s after the last keep-alive, and a
null sent meanwhile is lost). The manifest says that several battery
services and no ActiveBmsInstance send no limits.

ferroamp_modbus: a failed power read no longer drops a good SoC and energy
counters; the battery reading carries whatever answered.

Refs #250

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