Repository navigation
feat(sonnen): set battery power via the local API (2.1.0) - #237
Draft
yogiohlsson-ai wants to merge 8 commits into
Draft
yogiohlsson-ai wants to merge 8 commits into
yogiohlsson-ai wants to merge 8 commits 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. Signed-off-by: Jörgen Ohlsson <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
sonnen applies setpoints only in manual mode, which it enters through
PUT /api/v2/configurations; PATCH and POST there return 404. With FTW's
host.http_put and capabilities.http.allow_write, a battery command enters
manual mode and posts /setpoint/charge|discharge/<W>, limited to
IC_InverterMaxPower_w and an optional owner max_power_w.
A manual setpoint holds until replaced, so the driver owns the way back:
a 60 s lease in poll, default mode and deinit clear the setpoint and
restore the automatic mode the unit ran before (2 or 10), with readback;
init clears a manual mode a stopped FTW left behind; three failed
handovers stop the unprompted writes. {"error": ...} replies are failed
reads instead of w = 0. Without http_put the driver refuses commands and
keeps reporting telemetry.
Adds http_put to the host API profile and the harness mock.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Jörgen Ohlsson <[email protected]>
host.http_post is not gated by capabilities.http.allow_write. When the unit already reported manual mode, a battery command skipped the PUT and posted the setpoint directly, so a driver without write permission could still move the battery. Every control session now starts with a confirmed PUT; a refused PUT ends the command before any POST. Also report 0 instead of -0 W when the battery is idle. Found in a dry run of the hardware test protocol against a local fake unit. The new harness case fails on the previous code. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jörgen Ohlsson <[email protected]>
Default mode counted every failed hand-back toward the three-attempt limit, including calls made while the unit was unreachable, such as FTW's watchdog during a network loss. After three of those it reported the default as held and the lease stopped trying, so the unit kept its manual setpoint after the network returned. Only refusals, where the unit answered the read, now count. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jörgen Ohlsson <[email protected]>
…left Init and default mode returned the unit to its automatic mode whenever it reported manual mode. That overrode an owner who keeps the unit in manual mode with setpoint 0 (idle), and without allow_write it still posted setpoint 0, because http_post is not gated by allow_write. Now the driver undoes its own session as before (setpoint 0, then the automatic mode). A manual setpoint other than 0 that it did not set is cleared with a PUT only. A manual mode with setpoint 0 that it did not set is left alone. Without write access nothing is written. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jörgen Ohlsson <[email protected]>
In the automatic modes a sonnenBatterie reports its own load-following target in SetPoint_W (1255 W was seen in self-consumption). The driver reported it as setpoint_w in every mode, so FTW would read it as a command it never gave. setpoint_w is now emitted only after a fresh /configurations read confirms manual mode. A /configurations reply without EM_OperatingMode kept the mode from an earlier read, and default mode could then report the unit as automatic while another controller held a manual setpoint. Such a reply is now a failed read. The harness fake now follows the house load in mode 2, as the unit does. Both new cases fail on the previous driver. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jörgen Ohlsson <[email protected]>
When the unit was already in manual mode at start, the first poll reported its SetPoint_W as FTW's setpoint, although this driver had not posted one (-1622 and -942 W were seen in the harness log). setpoint_w is now emitted only after this session's own setpoint POST was answered "true" and a fresh read confirms manual mode. A refused POST, a hand-back to automatic mode, or the unit leaving manual mode withdraws it. Mode 2 still never reports SetPoint_W. The max_power_w config example now reads 5000. The new harness case fails on the previous driver with -1622. Signed-off-by: Jörgen Ohlsson <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jörgen Ohlsson <[email protected]>
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.
Summary
Adds battery control to the sonnen driver (
drivers/lua/sonnen.lua, 2.1.0) through the local API v2. This is a separately reviewed control change on top of the read-only driver.Draft, stacked on two open PRs. The first commit of this branch is the same change as #232 (Pac_total_W sign convention). It also needs srcfl/ftw#2028 (
host.http_put, used to switch the operating mode). I will rebase once those are merged, so that only the commits of this PR remain.How control works:
EM_OperatingMode= 1) plusPOST /api/v2/setpoint/charge/{W}or/discharge/{W}. A setpoint of 0 clears it.PUTof mode 1.host.http_postis not gated byallow_write, so thisPUTis what keeps a read-only driver from posting a setpoint.IC_InverterMaxPower_w, 9900 W on the test unit). An optionalmax_power_wcan lower it. If the unit reports no limit, setpoints are refused.2, self-consumption;10viadefault_operating_mode). Default mode and deinit do the same. Only refusals count against the hand-back attempts.setpoint_wis reported only after this session's own setpointPOSTwas confirmed and a fresh read shows manual mode. In the automatic modes the unit'sSetPoint_Wfollows the house load and is never reported. Before this fix the first poll after start could report a setpoint this driver had not written (-1622 W and -942 W were seen).Driver evidence
/api/v2/latestdata,/api/v2/configurations,/api/v2/setpoint/charge|discharge/{W}), measured on one unitSafety
Control evidence
setpoint_wnullmax_power_w1000, request 3000 Wkill -9while chargingkill -9SIGSTOP,SIGCONT,SIGTERMsetpoint_wfixPOST,nullagain after hand-backChecks
Signed-off-by.make test-driver ID=sonnen: 44 passed, 10 skipped, 0 failedmake check: 5093 passed, 951 skipped, 0 failed (origin/main: 5091 passed).🤖 Generated with Claude Code
https://claude.ai/code/session_017rc5E7dBomboUb3BCbVuNF