Sungrow-hybrid - Add curtailing - #33210
Conversation
…row hybrid template
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="templates/definition/meter/sungrow-hybrid.yaml" line_range="136-162" />
<code_context>
+ ena := 170 // 0xAA - enable limitation
</code_context>
<issue_to_address>
**issue (bug_risk):** If the second Modbus write to `watts` fails after the first write succeeds, the inverter remains in the newly enabled state while retaining its previous feed-in limit, so the requested curtailment is not applied and the device can export above the requested cap.
**Triggers:** When changing or enabling curtailment and the feed-in limitation value write fails.
**Suggested fix:** On failure of the value write, retry the operation or explicitly restore the previous switch state instead of leaving the limiter enabled with a stale value.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and the change writes a feed-in power limit to the inverter, so an incorrect calculation or register interpretation could leave the device curtailed and cause generation to be lost until someone corrects the setting. Reverting the software would not undo the register write or recover production that was missed.
Blocking findings: templates/definition/meter/sungrow-hybrid.yaml:162
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| ena := 170 // 0xAA - enable limitation | ||
| if curtail == 100 { | ||
| ena = 85 // 0x55 - disable limitation | ||
| } | ||
| ena | ||
| out: | ||
| - name: ena | ||
| type: int | ||
| config: | ||
| source: modbus | ||
| {{- include "modbus" . | indent 12 }} | ||
| register: | ||
| address: 13086 # Feed-in Limitation switch (doc 13087), 0xAA enable / 0x55 disable | ||
| type: writesingle | ||
| decode: uint16 | ||
| - source: go | ||
| script: | | ||
| watts := curtail * {{ .maxacpower }} / 100 | ||
| watts | ||
| out: | ||
| - name: watts | ||
| type: int | ||
| config: | ||
| source: modbus | ||
| {{- include "modbus" . | indent 12 }} | ||
| register: | ||
| address: 13073 # Feed-in Limitation Value (doc 13074), 1W resolution |
There was a problem hiding this comment.
issue (bug_risk): If the second Modbus write to watts fails after the first write succeeds, the inverter remains in the newly enabled state while retaining its previous feed-in limit, so the requested curtailment is not applied and the device can export above the requested cap.
Triggers: When changing or enabling curtailment and the feed-in limitation value write fails.
Suggested fix: On failure of the value write, retry the operation or explicitly restore the previous switch state instead of leaving the limiter enabled with a stale value.
|
/cc @CiNcH83 |
Sungrow: add EEG §9 curtailment support
What
Adds feed-in curtailment (capabilities: ["curtail"]) to the sungrow-hybrid PV meter template, so Sungrow SH-series hybrid inverters can be used as a curtailable device with evcc's External Limit (§14a/§9) feature — same mechanism already used by sunspec-inverter.yaml.
Implementation notes
Uses Feed-in Limitation (register 13087) to enable/disable the limiter, and Feed-in Limitation Value (register 13074, absolute Watts) rather than Feed-in Limitation Ratio (register 13088, 0.1% units) to express the target level. The percentage-based ratio register was only added to Sungrow's Modbus protocol in V1.1.7 (May 2025) and isn't reliably available across firmware versions; the Watt-based register has been present much longer and proved more broadly compatible in testing. The Watt target is derived from the existing maxacpower param (maxacpower * curtail / 100).
maxacpower is now a required param, since curtail/curtailed depend on it directly for the percentage↔Watt conversion.
Follows the same enable/disable convention Sungrow uses elsewhere in this template (0xAA/170 = enable, 0x55/85 = disable), and the same 100%-is-uncurtailed convention evcc's other curtailable templates use.
Testing
Verified against a Sungrow SH4.0RS (WiNet-S) — write and read round-trip correctly with the Watt-based approach.
Not yet tested against SH-RT/SH-T/MG-series units; feedback from owners of those models welcome before merge.