Repository navigation
fix(sonnen): report battery power with the site sign (2.0.4) - #232
Conversation
miravoss26
left a comment
There was a problem hiding this comment.
Flips sonnen battery.w to the site sign (+ = charging) by negating Pac_total_W, with a harness test for charge and discharge and a bump to 2.0.4.
- Checked:
sha256andsize_bytesinindex.yamlandmanifests/sonnen.yamlmatch the headdrivers/lua/sonnen.lua(aee7b5ec…, 6734 bytes).battery_pac_wkeeps the vendor sign, driver stays read-only. - Note: the old comment said the sample code was unverified, and the new one cites a live reading (1.40.5, -500 W setpoint). The fix reads right to me.
- Note: no CI reported on this branch, so the new test hasn't run anywhere I can see. Worth a
make checkbefore merge.
Safe to merge from my read, once the test has run.
ad91026 to
b6f0dd9
Compare
|
Rebased onto current main (one CHANGELOG conflict, kept both entries). |
miravoss26
left a comment
There was a problem hiding this comment.
Flips the sonnen battery sign (negates Pac_total_W so charging is positive) and bumps the driver to 2.0.4, with the matching index/manifest/support-status updates and a Lua harness test.
- Logic is a one-line negation, and the raw vendor value stays in
battery_pac_w, so nothing downstream loses information. Tests cover charge (-500 -> +500), discharge (1200 -> -1200), SOC/capacity passthrough and read-only. - Evidence is one unit (software 1.40.5, six reads of a 500 W charge setpoint), so it's a single-device measurement. Worth a note for installs on other firmware.
- Security screen: no secrets, no new hosts or dependencies. The sha256/size_bytes changes follow the lua edit; I didn't recompute them.
Safe to merge from my read, once the checks on the hashes are green.
|
Are this backed by some documentation or could it be that your installer installed it backwards? |
|
Not from documentation. The PR measures it on one unit (software 1.40.5). On 16 Nov, in a 02:00–06:00 charge window, |
|
Adding one independent data point from the same unit's owner: the ioBroker.sonnen adapter |
a53e616 to
8869bdc
Compare
miravoss26
left a comment
There was a problem hiding this comment.
Flips the sign of battery.w in the sonnen driver (2.0.3 → 2.0.4) so charge is positive, matching the site convention. battery_pac_w keeps the vendor sign. Version bumps and index/manifest hashes are updated, and there's a harness test for both directions.
- Evidence is solid: a 500 W charge setpoint read back as
Pac_total_W−495…−504 W, and the old comment admitted the sign was from untested community code. One unit, one firmware (1.40.5), so worth noting in the changelog that other firmware is unverified. Not a blocker. - Security: nothing in the diff. No new deps or hosts, driver stays read-only.
- Needs a rebase: the PR is
CONFLICTING.index.yaml,manifests/sonnen.yaml,SUPPORT_STATUS.mdandsupport-status.jsonare generated, so thesha256/size_bytesvalues will need regenerating after the rebase, not hand-merging. - No CI checks reported, so I couldn't confirm the tests pass.
Content looks right to me. Needs a human to rebase and let CI run before merge.
sonnen's JSON API v2 reports Pac_total_W positive while discharging. The driver passed it through, so FTW showed charge as discharge. Negate it so battery.w is positive while charging. Measured on a sonnenBatterie with software 1.40.5 on 2026-11-13: in manual mode, a 500 W charge setpoint read back over six reads as Pac_total_W -495 to -504 W, SetPoint_W -500 and BatteryCharging true. The driver stays read-only. battery_pac_w keeps the vendor sign. Signed-off-by: Jörgen Ohlsson <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
8869bdc to
7ca2326
Compare
|
Rebased onto current main (3 new commits; only CHANGELOG conflicted, and the generated |
miravoss26
left a comment
There was a problem hiding this comment.
Flips the sonnen battery.w sign (battery.w = -Pac_total_W), bumps the driver to 2.0.4 and adds a Lua harness test plus pytest wrapper.
- Logic looks right and the evidence is solid for one unit: three independent observations (TOU charge window, self-consumption, a 500 W setpoint readback) all agree on negative = charging.
- Note: the PR body says a local 2.0.3 copy already runs on that site with the same negation, so this is verified on 1 unit / firmware 1.40.5 only. The CHANGELOG already says so, good. Anyone on other firmware will see the sign flip with no way to tell which convention they have. Worth a line in release notes.
- Security screen: no secrets (test uses 192.0.2.10 and a dummy token), no new deps, no new network hosts, driver stays
read_only. - Minor:
index.yaml/ manifest sha256 andsize_byteschange; I did not recompute them, assume the repo's make target generated them. CI shows no check runs on this PR, so nothing has run the new test yet.
Safe to merge from my read once CI has actually run the harness test.
…2093) Moves the driver pin from srcfl/device-drivers 8aeecee3 to 20f9e8e5. Only sonnen.lua changes (srcfl/device-drivers#232). Signed-off-by: Fredrik Ahlgren <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Need
FTW shows a sonnenBatterie charging when it discharges and the reverse.
sonnen's local JSON API v2 reports
Pac_total_Wpositive whiledischarging; the driver passed it through unchanged, but the site
convention wants battery charge positive. The driver comment already said the
original sign came from untested community sample code.
Evidence
One unit: sonnenBatterie, software 1.40.5, JSON API v2 on port 80.
EM_OperatingMode10), from a 5-minute snapshot log of
/api/v2/latestdata, with the moderead from
/api/v2/configurations. Between 02:05 and 05:55 every sampleread negative
Pac_total_W(45 samples; one sample at 03:50 failed with"No route to host"). Most samples read -4.1 to -4.4 kW: 34 of 45, mean
-4.3 kW. The full range was -3.5 to -5.3 kW. Over the same window
USOCrose from 17 % to 99 %, and grid import was +4.9 to +7.5 kW.
At 06:00
Pac_total_Wread 5 W.EM_OperatingMode2), same log, 2026-11-14 14:00 to2026-11-16 10:55. 291 samples read
Pac_total_Wabove +100 W. They fallin hours when consumption exceeded production, for example 2026-11-14 16:05
with +3458 W, USOC falling 98 → 96 % and grid near 0. 26 samples read
below -100 W, all with production above consumption, for example
2026-11-15 08:20 with -1495 W, production 2330 W and consumption 969 W.
the owner's approval and logged in that session. In manual mode (
PUT /api/v2/configurations,EM_OperatingMode=1),POST /api/v2/setpoint/charge/500was followed by six reads at 5 s intervals./api/v2/latestdatashowedPac_total_W-495 to -504 W andSetPoint_W-500, and
/api/v2/statusshowedBatteryCharging: true. Afterwardssetpoint 0 and
EM_OperatingMode=2were restored and read back.The unit charges with negative
Pac_total_Wand discharges with positivePac_total_W.A local copy of 2.0.3 has run read-only on that site's FTW since 2026-11-13
with fresh telemetry. It differs from 2.0.3 in two ways: it negates
Pac_total_W, and it treats an{"error": ...}reply, such asUnauthorized, as a failed read instead of emittingw = 0. This PR carriesonly the negation; the error handling is listed under "Not in this PR".
Change
drivers/lua/sonnen.lua:battery.w = -Pac_total_W; sign comment corrected.battery_pac_wkeeps the vendor sign. Stillread_only = true; no otherbehaviour changes.
tools/bump_driver.py, manifests/index/devices/support status regenerated, CHANGELOG entry.
drivers/tests/test_sonnen_sign.py+ harnesslua_harness/test_sonnen_sign.lua: charging body (-500) must emit +500,discharging body (+1200) must emit -1200, SoC/capacity unchanged, driver
still read-only. The test fails on 2.0.3 (charging read as -500).
Checks
Every step of
make check, run with the same tools through a local venv(Python 3.13, pytest 9.2.0, cryptography 50.0.2) because
uvis notinstalled on the test host: boundary, manifest sync/validate, index, devices,
support status, history, FTW baseline, host API, sandbox, and
pytest drivers/tests tests— 5091 passed, 951 skipped.Not in this PR
w = 0when the unit answers{"error":"Unauthorized"}; that should become a failed read. Separate fix.host.http_putin FTWCore (sonnen answers PATCH/POST on
/api/v2/configurationswith 404) andwill be a separate PR.
drivers/BUNDLED_SOURCE.jsonto this commit once merged.🤖 Generated with Claude Code