Skip to content

fix(sonnen): report battery power with the site sign (2.0.4) - #232

Open
yogiohlsson-ai wants to merge 1 commit into
srcfl:mainfrom
yogiohlsson-ai:fix/sonnen-pac-sign
Open

yogiohlsson-ai wants to merge 1 commit into
srcfl:mainfrom
yogiohlsson-ai:fix/sonnen-pac-sign

Conversation

@yogiohlsson-ai

Copy link
Copy Markdown

Need

FTW shows a sonnenBatterie charging when it discharges and the reverse.
sonnen's local JSON API v2 reports Pac_total_W positive while
discharging; 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.

  1. Time-of-use charge window, 2026-11-16 02:00–06:00 (EM_OperatingMode
    10), from a 5-minute snapshot log of /api/v2/latestdata, with the mode
    read from /api/v2/configurations. Between 02:05 and 05:55 every sample
    read 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 USOC
    rose from 17 % to 99 %, and grid import was +4.9 to +7.5 kW.
    At 06:00 Pac_total_W read 5 W.
  2. Self-consumption (EM_OperatingMode 2), same log, 2026-11-14 14:00 to
    2026-11-16 10:55. 291 samples read Pac_total_W above +100 W. They fall
    in 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.
  3. API setpoint, 2026-11-13 20:03 CET, run by the PR author's agent with
    the owner's approval and logged in that session. In manual mode (PUT /api/v2/configurations, EM_OperatingMode=1), POST /api/v2/setpoint/charge/500 was followed by six reads at 5 s intervals.
    /api/v2/latestdata showed Pac_total_W -495 to -504 W and SetPoint_W
    -500, and /api/v2/status showed BatteryCharging: true. Afterwards
    setpoint 0 and EM_OperatingMode=2 were restored and read back.

The unit charges with negative Pac_total_W and discharges with positive
Pac_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 as
Unauthorized, as a failed read instead of emitting w = 0. This PR carries
only 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_w keeps the vendor sign. Still read_only = true; no other
    behaviour changes.
  • Version 2.0.3 → 2.0.4 via tools/bump_driver.py, manifests/index/devices/
    support status regenerated, CHANGELOG entry.
  • New drivers/tests/test_sonnen_sign.py + harness
    lua_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 uv is not
installed 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

  • The driver still emits w = 0 when the unit answers
    {"error":"Unauthorized"}; that should become a failed read. Separate fix.
  • Control (manual setpoints, safe default mode) needs host.http_put in FTW
    Core (sonnen answers PATCH/POST on /api/v2/configurations with 404) and
    will be a separate PR.
  • FTW follow-up: move drivers/BUNDLED_SOURCE.json to this commit once merged.

🤖 Generated with Claude Code

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

No deployments
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