Repository navigation
feat(victron_mqtt, victron, ferroamp_modbus, zap): what the battery can do now - #254
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| 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") |
There was a problem hiding this comment.
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]>
e75b4f0 to
7452ae4
Compare
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
mainafter #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
available_charge_WN/+/battery/<inst>/Info/MaxChargeCurrent(A) ×.../Dc/0/Voltagefrom the same BMSavailable_discharge_W.../Info/MaxDischargeCurrent(A) × the same voltage. DCL 0 sends 0 Wtemperature_CN/+/system/0/Dc/Battery/Temperature, which the driver already subscribed tobattery_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.../System/MinCellTemperatureandMaxCellTemperaturesystem/0/ActiveBmsInstance(dbus-systemcalc-pydelegates/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.{"value": null}or an empty payload (the device left the D-Bus) clears the value.ActiveBmsInstanceyet, no limits are sent, and that the driver needs another client to keep the GX publishing.victron 2.2.0: a wrong temperature removed, no new fields
com.victronenergy.system, 844 is/Dc/Battery/State(0 idle, 1 charging, 2 discharging). The driver read it as 0.1 °C, sotemp_candbattery_temp_cshowed 0.0 to 0.2 °C. The system service has no temperature register. The driver now reads 840–843 and reports no temperature.com.victronenergy.battery. The GX serves that service on its own unit ID.host.modbus_readhas no unit-ID argument, so this one-unit driver cannot reach it. Source: Victrondbus_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:
tempis "Measured inside ESO". That is the converter, not the battery. The HA integration calls it "PCB Temperature".ratedPoweris a rating.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
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
temp_cnow comes only from batterytemperature_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 batteryheatsink_Cwas 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 fromsrcful-zap-x-firmware).inverter_temp_ccomes from the inverter DER'stemperature_C.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_*_Whare derived from the SoC window and capacity. None is a battery-reported limit.Found, not fixed (out of scope)
Wsign. 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/Poweras positive when charging, and the Modbus driver passes 842 through unchanged. The review agrees thatmainvery likely inverts it. It goes in its own issue, which needs a GX measurement.R/<portal>/keepalive). dbus-flashmq publishes only while some client keeps it alive. Values that seldom change, such as a fixed CCL orActiveBmsInstance, arrive only on a full republish.invented-number-baseline.json, which drops from 10 to 5 and from 18 to 15.Tests
test_victron_mqtt_battery_limits: scale; DCL 0; no voltage; null and empty payloads; BMS selection; ranges; nothing invented.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.maindrivers.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
components/data_models/README.md,fw_controller/API.md(private).The new public URLs are in each manifest's
upstream_docs.🤖 Generated with Claude Code