Repository navigation
fix(sonnen): report battery power with the site sign (2.0.4) - #232
Open
yogiohlsson-ai wants to merge 1 commit into
Open
yogiohlsson-ai wants to merge 1 commit into
yogiohlsson-ai wants to merge 1 commit into
Conversation
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. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Jörgen Ohlsson <yogiohlsson@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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