Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

## [Unreleased]

### sonnen 2.0.4

Battery power has the site sign. sonnen reports `Pac_total_W` positive while
discharging and negative while charging; the driver passed it through, so
FTW showed every charge as a discharge and the reverse. It now negates the
value: charging is positive. 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. `battery_pac_w` keeps the vendor's own sign. The driver stays
read-only.

### easee_cloud 1.4.1

The driver says its session energy is coarse, with `session_wh_coarse`. Easee
Expand Down
4 changes: 2 additions & 2 deletions SUPPORT_STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ Catalog source is not proof that a target can install or run a driver.
| solis | 2.1.1 | blixt-l1 | not_assessed | — | not_recorded | not_assessed |
| solis_string | 1.1.3 | ftw-core | not_assessed | — | not_recorded | not_assessed |
| solis_string | 1.1.3 | blixt-l1 | not_assessed | — | not_recorded | not_assessed |
| sonnen | 2.0.3 | ftw-core | not_assessed | — | not_recorded | not_assessed |
| sonnen | 2.0.3 | blixt-l1 | not_assessed | — | not_recorded | not_assessed |
| sonnen | 2.0.4 | ftw-core | not_assessed | — | not_recorded | not_assessed |
| sonnen | 2.0.4 | blixt-l1 | not_assessed | — | not_recorded | not_assessed |
| sungrow | 1.6.1 | ftw-core | not_assessed | — | not_recorded | not_assessed |
| sungrow | 1.6.1 | blixt-l1 | not_assessed | — | not_recorded | not_assessed |
| tesla_cloud | 0.2.0 | ftw-core | not_assessed | — | not_recorded | not_assessed |
Expand Down
2 changes: 1 addition & 1 deletion devices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2175,7 +2175,7 @@ manufacturers:
protocols:
- protocol: http
driver: "sonnen"
version: "2.0.3"
version: "2.0.4"
ders: [battery, meter]
control: false
firmware_versions: ""
Expand Down
13 changes: 7 additions & 6 deletions drivers/lua/sonnen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@
--
-- Sign convention (site: positive W flows INTO the site):
-- battery.w: positive = charging (sink), negative = discharging (source).
-- Sonnen Pac_total_W is reported positive=charging, so it passes through
-- unchanged. This is from community-contributed sample code; verify
-- on first install by checking that battery.w is positive while the
-- site is exporting and the Sonnen is taking the surplus.
-- sonnen reports Pac_total_W positive while DISCHARGING and negative while
-- charging, so the driver negates it. 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.

DRIVER = {
host_api_min = 1,
host_api_max = 1,
id = "sonnen",
name = "sonnenBatterie (local API)",
manufacturer = "sonnen",
version = "2.0.3",
version = "2.0.4",
protocols = { "http" },
capabilities = { "battery" },
read_only = true,
Expand Down Expand Up @@ -182,7 +183,7 @@ function driver_poll()

local soc_pct = usoc or rsoc or 0
local battery = {
w = pac_w,
w = -pac_w, -- sonnen: + = discharge; site: + = charge
soc = soc_pct / 100.0,
}
if cap_wh then
Expand Down
58 changes: 58 additions & 0 deletions drivers/tests/lua_harness/test_sonnen_sign.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
-- sonnen: battery.w sign. sonnen reports Pac_total_W positive while
-- discharging and negative while charging; FTW's battery.w is positive while
-- charging. Bodies follow /api/v2/latestdata from a sonnenBatterie running
-- software 1.40.5.

dofile("drivers/tests/lua_harness/host_mock.lua")

local URL = "http://192.0.2.10:80/api/v2/latestdata"

local function latest(pac_w, setpoint_w)
return '{"Consumption_W":2259,"FullChargeCapacity":18700,' ..
'"GridFeedIn_W":-2240,"Pac_total_W":' .. tostring(pac_w) ..
',"Production_W":16,"RSOC":45,"SetPoint_W":' .. tostring(setpoint_w) ..
',"Timestamp":"2026-11-13 20:03:26","USOC":40,"UTC_Offset":1}'
end

local function poll_battery_w(body)
host.reset()
dofile("drivers/lua/sonnen.lua")
driver_init({ host = "192.0.2.10", port = 80, api_token = "token" })
host._http_responses[URL] = body
local ok, err = pcall(driver_poll)
if not ok then error("driver_poll failed: " .. tostring(err)) end
local list = host._emitted.battery
if not list or #list == 0 then error("no battery emit") end
return list[#list]
end

-- Charging: shaped like the readback of a 500 W charge setpoint
-- (measured -495 to -504 W; -500 here).
local charging = poll_battery_w(latest(-500, -500))
if charging.w ~= 500 then
error("charging must be +500 W in site convention, got " .. tostring(charging.w))
end
if math.abs(charging.soc - 0.40) > 1e-9 then
error("soc must come from USOC as a fraction, got " .. tostring(charging.soc))
end
if charging.capacity_wh ~= 18700 then
error("capacity_wh lost: " .. tostring(charging.capacity_wh))
end

-- Discharging.
local discharging = poll_battery_w(latest(1200, 0))
if discharging.w ~= -1200 then
error("discharging must be -1200 W in site convention, got " .. tostring(discharging.w))
end

-- The raw vendor value stays available, unconverted, as a metric.
if not host._metrics.battery_pac_w or host._metrics.battery_pac_w.value ~= 1200 then
error("battery_pac_w must keep the vendor sign")
end

-- Still read-only.
if DRIVER.read_only ~= true or driver_command("battery", 1000, {}) ~= false then
error("sonnen must stay read-only")
end

print("OK")
27 changes: 27 additions & 0 deletions drivers/tests/test_sonnen_sign.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""sonnen: battery.w follows the site convention.

sonnen reports Pac_total_W positive while discharging; FTW's battery.w is
positive while charging. The harness script polls the driver against
/api/v2/latestdata bodies in the shape a live unit returns.
"""

from __future__ import annotations

import subprocess
from pathlib import Path

import pytest

ROOT = Path(__file__).resolve().parents[2]
LUA = ROOT / "lua55"

pytestmark = pytest.mark.skipif(
not LUA.exists(), reason="run make check to build ./lua55")


def test_sonnen_battery_sign_follows_site_convention():
result = subprocess.run(
[str(LUA), "drivers/tests/lua_harness/test_sonnen_sign.lua"],
capture_output=True, text=True, cwd=ROOT)
assert result.returncode == 0, result.stdout + result.stderr
assert "OK" in result.stdout
6 changes: 3 additions & 3 deletions index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -709,15 +709,15 @@ drivers:
size_bytes: 5807
sha256: "5669996a562d10fc94ed89748664542ce14e5d965ff0df85d1e7610ff4dda568"
- name: "sonnen"
version: "2.0.3"
version: "2.0.4"
tier: community
protocol: http
connectivity: local
setup: [device_ui]
ders: [battery, meter]
control: false
size_bytes: 6631
sha256: "94ae5e0065f5793051acb89b7ef04a679b2898908dfac6f4ffd6e8deb77fa2c0"
size_bytes: 6734
sha256: "aee7b5ecf3b7666561084d434664f2df1019425f085ce36c4c4488baebfd1f76"
- name: "sungrow"
version: "1.6.1"
tier: core
Expand Down
6 changes: 3 additions & 3 deletions manifests/sonnen.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "sonnen"
version: "2.0.3"
version: "2.0.4"
tier: community
author: "Sourceful Labs AB"
protocol: http
Expand All @@ -16,9 +16,9 @@ tested_devices:
notes: "Community driver, untested"
min_driver_version: "1.0.0"
min_host_version: "2.1.0"
size_bytes: 6631
size_bytes: 6734
dkb_id: ""
sha256: "94ae5e0065f5793051acb89b7ef04a679b2898908dfac6f4ffd6e8deb77fa2c0"
sha256: "aee7b5ecf3b7666561084d434664f2df1019425f085ce36c4c4488baebfd1f76"
signature: ""

bytecode_sha256: ""
Expand Down
2 changes: 1 addition & 1 deletion support-status.json
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,7 @@
},
{
"catalog_source": true,
"catalog_version": "2.0.3",
"catalog_version": "2.0.4",
"driver_id": "sonnen",
"targets": {
"blixt-l1": {
Expand Down