From ea8e2a72c0522f51471891e40ff9f916902e5ada Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 28 Aug 2026 09:05:47 +0200 Subject: [PATCH 01/10] Site: add returnEnergy to aggregated battery state (#33241) Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Michael Geers --- assets/js/types/evcc.ts | 4 +++- core/site.go | 6 ++++++ core/types/types.go | 13 +++++++------ server/mcp/openapi.json | 6 +++++- server/mqtt_test.go | 4 ++-- server/openapi.state.yaml | 5 ++++- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/assets/js/types/evcc.ts b/assets/js/types/evcc.ts index d478f5e27..22f697402 100644 --- a/assets/js/types/evcc.ts +++ b/assets/js/types/evcc.ts @@ -1131,8 +1131,10 @@ export interface Battery { capacity: number; /** Charge level in %. Weighted by capacity across all batteries. */ soc: number; - /** Total battery energy in kWh. */ + /** Total discharged energy in kWh. */ energy?: number; + /** Total charged energy in kWh. */ + returnEnergy?: number; /** Measurement data per battery meter. */ devices?: BatteryMeter[]; /** Projected charge levels based on the solar and price forecast. */ diff --git a/core/site.go b/core/site.go index e345fb85e..0f42d6016 100644 --- a/core/site.go +++ b/core/site.go @@ -867,6 +867,12 @@ func (site *Site) updateBatteryMeters() { } return *m.Energy }) + site.battery.ReturnEnergy = lo.SumBy(mm, func(m types.Measurement) float64 { + if m.ReturnEnergy == nil { + return 0 + } + return *m.ReturnEnergy + }) site.battery.Devices = mm battery := site.battery diff --git a/core/types/types.go b/core/types/types.go index d060d1767..f3b254861 100644 --- a/core/types/types.go +++ b/core/types/types.go @@ -56,10 +56,11 @@ func (m Measurement) GetTitle() string { } type BatteryState struct { - Power float64 `json:"power"` - Energy float64 `json:"energy,omitempty"` - Capacity float64 `json:"capacity,omitempty"` - Soc float64 `json:"soc"` - Devices []Measurement `json:"devices,omitempty" influxdb:"battery"` - Forecast *BatteryForecast `json:"forecast,omitempty"` + Power float64 `json:"power"` + Energy float64 `json:"energy,omitempty"` + ReturnEnergy float64 `json:"returnEnergy,omitempty"` + Capacity float64 `json:"capacity,omitempty"` + Soc float64 `json:"soc"` + Devices []Measurement `json:"devices,omitempty" influxdb:"battery"` + Forecast *BatteryForecast `json:"forecast,omitempty"` } diff --git a/server/mcp/openapi.json b/server/mcp/openapi.json index 4a1d4537f..537003276 100644 --- a/server/mcp/openapi.json +++ b/server/mcp/openapi.json @@ -3843,7 +3843,11 @@ "type": "number" }, "energy": { - "description": "Total battery energy in kWh.", + "description": "Total discharged energy in kWh.", + "type": "number" + }, + "returnEnergy": { + "description": "Total charged energy in kWh.", "type": "number" }, "devices": { diff --git a/server/mqtt_test.go b/server/mqtt_test.go index 115800433..d16e6a36d 100644 --- a/server/mqtt_test.go +++ b/server/mqtt_test.go @@ -152,7 +152,7 @@ func (suite *mqttSuite) TestMeasurement() { func (suite *mqttSuite) TestBatteryState() { topics := lo.Map([]string{ - "power", "energy", "capacity", "soc", + "power", "energy", "returnEnergy", "capacity", "soc", "devices", "devices/1/name", "devices/1/title", "devices/1/icon", "devices/1/power", "devices/1/energy", "devices/1/returnEnergy", "devices/1/powers", "devices/1/currents", "devices/1/excessDCPower", "devices/1/capacity", "devices/1/soc", "devices/1/controllable", "devices/1/suggestion", "forecast", }, func(s string, _ int) string { @@ -169,5 +169,5 @@ func (suite *mqttSuite) TestBatteryState() { }) suite.Equal(topics, suite.topics, "topics") - suite.Equal([]string{"2", "", "", "20", "1", "", "", "", "1", "", "", "", "", "", "", "10", "", "", ""}, suite.payloads, "payloads") + suite.Equal([]string{"2", "", "", "", "20", "1", "", "", "", "1", "", "", "", "", "", "", "10", "", "", ""}, suite.payloads, "payloads") } diff --git a/server/openapi.state.yaml b/server/openapi.state.yaml index 62442c35c..664858fc7 100644 --- a/server/openapi.state.yaml +++ b/server/openapi.state.yaml @@ -302,7 +302,10 @@ components: description: Charge level in %. Weighted by capacity across all batteries. type: number energy: - description: Total battery energy in kWh. + description: Total discharged energy in kWh. + type: number + returnEnergy: + description: Total charged energy in kWh. type: number devices: description: Measurement data per battery meter. From 19048976ab7380fc2b791979eabededec3317e36 Mon Sep 17 00:00:00 2001 From: Gabik21 Date: Fri, 28 Aug 2026 17:31:07 +0200 Subject: [PATCH 02/10] chore: add curtailment to meter template (#33237) --- assets/js/components/Config/defaultYaml/meter.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/assets/js/components/Config/defaultYaml/meter.yaml b/assets/js/components/Config/defaultYaml/meter.yaml index 544def442..764f95f1b 100644 --- a/assets/js/components/Config/defaultYaml/meter.yaml +++ b/assets/js/components/Config/defaultYaml/meter.yaml @@ -16,6 +16,9 @@ power: # current power #maxpower: # maximum AC power in W (for hybrid pv) # source: const # value: 5000 +#curtailed: # current feed-in limit in % (0..100, 100 = uncurtailed) +# source: const +# value: 100 #soc: # state of charge in % (for battery) # source: const # value: 75 @@ -50,3 +53,6 @@ power: # current power #batterymode: # set charging mode directly (1: normal, 2: hold, 3: charge) (for battery) # source: js # script: console.log(batterymode) +#curtail: # set feed-in limit in % (0..100, 100 = uncurtailed) +# source: js +# script: console.log(curtail) From e8b547737389eda23666e31ac77b6390ee168452 Mon Sep 17 00:00:00 2001 From: Gabik21 Date: Sat, 29 Aug 2026 11:01:53 +0200 Subject: [PATCH 03/10] Cardata: fix retrying failed container setup (#33243) --- vehicle/bmw/cardata/provider.go | 18 +++++++++--------- vehicle/bmw/cardata/provider_test.go | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/vehicle/bmw/cardata/provider.go b/vehicle/bmw/cardata/provider.go index dd47620f1..595ebf397 100644 --- a/vehicle/bmw/cardata/provider.go +++ b/vehicle/bmw/cardata/provider.go @@ -132,17 +132,17 @@ func (v *Provider) any(key string) (any, error) { _, tokenErr := v.ts.Token() - switch { - case tokenErr == nil && v.updated.IsZero(): - // this will only happen once - if err := v.setupContainer(); err != nil { - v.log.WARN.Println(err) + if tokenErr == nil && (v.updated.IsZero() || time.Since(v.updated) > v.cache) { + if v.container == "" { + if err := v.setupContainer(); err != nil { + v.log.WARN.Println(err) + } } - fallthrough - case tokenErr == nil && time.Since(v.updated) > v.cache && v.container != "": - if err := v.updateContainerData(); err != nil { - v.log.WARN.Println(err) + if v.container != "" { + if err := v.updateContainerData(); err != nil { + v.log.WARN.Println(err) + } } v.updated = time.Now() } diff --git a/vehicle/bmw/cardata/provider_test.go b/vehicle/bmw/cardata/provider_test.go index 05bb65196..cbaad346a 100644 --- a/vehicle/bmw/cardata/provider_test.go +++ b/vehicle/bmw/cardata/provider_test.go @@ -15,7 +15,7 @@ func TestCardataStreaming(t *testing.T) { p := NewProvider(ctx, util.NewLogger("foo"), nil, oauth2.StaticTokenSource(&oauth2.Token{ AccessToken: "at", - }), "client", "vin", 0) + }), "client", "vin", time.Hour) // prevent container panic p.updated = time.Now() @@ -51,7 +51,7 @@ func TestSocFallback(t *testing.T) { p := NewProvider(ctx, util.NewLogger("foo"), nil, oauth2.StaticTokenSource(&oauth2.Token{ AccessToken: "at", - }), "client", "vin", 0) + }), "client", "vin", time.Hour) // prevent container panic p.updated = time.Now() @@ -108,7 +108,7 @@ func TestRangeFallback(t *testing.T) { p := NewProvider(ctx, util.NewLogger("foo"), nil, oauth2.StaticTokenSource(&oauth2.Token{ AccessToken: "at", - }), "client", "vin", 0) + }), "client", "vin", time.Hour) // prevent container panic p.updated = time.Now() @@ -165,7 +165,7 @@ func TestStatusFallback(t *testing.T) { p := NewProvider(ctx, util.NewLogger("foo"), nil, oauth2.StaticTokenSource(&oauth2.Token{ AccessToken: "at", - }), "client", "vin", 0) + }), "client", "vin", time.Hour) // prevent container panic p.updated = time.Now() From 7dd4007cfa5d4496861a728a95aaaf0c0eb3e8e9 Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Sat, 29 Aug 2026 13:10:43 +0200 Subject: [PATCH 04/10] Add BYN, UAH, RUB and KZT to currency list (#33259) --- assets/js/mixins/formatter.ts | 5 +++++ assets/js/types/evcc.ts | 4 ++++ server/mcp/openapi.json | 6 +++++- server/openapi.state.yaml | 4 ++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/assets/js/mixins/formatter.ts b/assets/js/mixins/formatter.ts index 47c05d1b5..4b0b3a9d8 100644 --- a/assets/js/mixins/formatter.ts +++ b/assets/js/mixins/formatter.ts @@ -75,6 +75,10 @@ const CURRENCY_SYMBOLS: Record = { TRY: "₺", MYR: "RM", THB: "฿", + BYN: "Br", + UAH: "₴", + RUB: "₽", + KZT: "₸", }; // list of currencies where energy price should be displayed in subunits (factor 100) @@ -94,6 +98,7 @@ const ENERGY_PRICE_IN_SUBUNIT: Partial> = { SEK: "öre", // Swedish öre ZAR: "c", // South African cent TRY: "krş", // Türkiye kuruş + BYN: "к.", // Belarusian kapeyka }; export enum POWER_UNIT { diff --git a/assets/js/types/evcc.ts b/assets/js/types/evcc.ts index 22f697402..659042f95 100644 --- a/assets/js/types/evcc.ts +++ b/assets/js/types/evcc.ts @@ -816,6 +816,10 @@ export enum CURRENCY { TRY = "TRY", MYR = "MYR", THB = "THB", + BYN = "BYN", + UAH = "UAH", + RUB = "RUB", + KZT = "KZT", } export enum ICON_SIZE { diff --git a/server/mcp/openapi.json b/server/mcp/openapi.json index 537003276..02cf646e6 100644 --- a/server/mcp/openapi.json +++ b/server/mcp/openapi.json @@ -3648,7 +3648,11 @@ "ZAR", "TRY", "MYR", - "THB" + "THB", + "BYN", + "UAH", + "RUB", + "KZT" ] }, "FatalError": { diff --git a/server/openapi.state.yaml b/server/openapi.state.yaml index 664858fc7..ada39bc1c 100644 --- a/server/openapi.state.yaml +++ b/server/openapi.state.yaml @@ -510,6 +510,10 @@ components: - TRY - MYR - THB + - BYN + - UAH + - RUB + - KZT DeviceColorEntry: description: Color assigned to a device for consistent UI display. type: object From 8abae0fd6888b3cc8e26a9f9d4426800ad492d43 Mon Sep 17 00:00:00 2001 From: andig Date: Sat, 29 Aug 2026 13:13:32 +0200 Subject: [PATCH 05/10] OpenDTU: tolerate missing radio_stats in energy filter (#33279) --- templates/definition/meter/hoymiles-opendtu.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/definition/meter/hoymiles-opendtu.yaml b/templates/definition/meter/hoymiles-opendtu.yaml index 1b222c7ba..740572a91 100644 --- a/templates/definition/meter/hoymiles-opendtu.yaml +++ b/templates/definition/meter/hoymiles-opendtu.yaml @@ -16,4 +16,5 @@ render: | energy: source: http uri: http://{{ .host }}/api/livedata/status - jq: 'if all(.inverters[]; .radio_stats.rssi > -127) then .total.YieldTotal.v else empty end' + # skip partial sums until all inverters are contacted; radio_stats needs firmware 2024.10.22+ + jq: 'if all(.inverters[]; .radio_stats.rssi == null or .radio_stats.rssi > -127) then .total.YieldTotal.v else empty end' From f193eb199af4840a369d95564c8fab95e1fa8003 Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Sat, 29 Aug 2026 13:34:42 +0200 Subject: [PATCH 06/10] Home Assistant: link charge status docs (#33260) --- .../definition/charger/homeassistant.yaml | 12 +++++------ .../definition/vehicle/homeassistant.yaml | 20 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/templates/definition/charger/homeassistant.yaml b/templates/definition/charger/homeassistant.yaml index 41ca1c0fe..6ac6b3d4a 100644 --- a/templates/definition/charger/homeassistant.yaml +++ b/templates/definition/charger/homeassistant.yaml @@ -41,8 +41,8 @@ params: example: not_plugged, disconnected advanced: true help: - en: Comma-separated list of additional states meaning ready - de: Komma-getrennte Liste zusätzlicher Zustände für bereit + en: Comma-separated list of additional states meaning ready, see [docs.evcc.io](https://docs.evcc.io/en/smarthome/home-assistant#charge-status) + de: Komma-getrennte Liste zusätzlicher Zustände für bereit, siehe [docs.evcc.io](https://docs.evcc.io/de/smarthome/home-assistant#charge-status) - name: statusB description: de: Zustände für Status B @@ -50,8 +50,8 @@ params: example: charging_stopped, charging_completed advanced: true help: - en: Comma-separated list of additional states meaning connected - de: Komma-getrennte Liste zusätzlicher Zustände für verbunden + en: Comma-separated list of additional states meaning connected, see [docs.evcc.io](https://docs.evcc.io/en/smarthome/home-assistant#charge-status) + de: Komma-getrennte Liste zusätzlicher Zustände für verbunden, siehe [docs.evcc.io](https://docs.evcc.io/de/smarthome/home-assistant#charge-status) - name: statusC description: de: Zustände für Status C @@ -59,8 +59,8 @@ params: example: instant_charging, fast_charging advanced: true help: - en: Comma-separated list of additional states meaning charging - de: Komma-getrennte Liste zusätzlicher Zustände für laden + en: Comma-separated list of additional states meaning charging, see [docs.evcc.io](https://docs.evcc.io/en/smarthome/home-assistant#charge-status) + de: Komma-getrennte Liste zusätzlicher Zustände für laden, siehe [docs.evcc.io](https://docs.evcc.io/de/smarthome/home-assistant#charge-status) - name: enabled description: de: Aktivierungsstatus-Sensor diff --git a/templates/definition/vehicle/homeassistant.yaml b/templates/definition/vehicle/homeassistant.yaml index 191c079da..7b737d8c8 100644 --- a/templates/definition/vehicle/homeassistant.yaml +++ b/templates/definition/vehicle/homeassistant.yaml @@ -61,8 +61,8 @@ params: example: not_plugged, disconnected advanced: true help: - en: Comma-separated list of additional states meaning disconnected - de: Komma-getrennte Liste zusätzlicher Zustände für getrennt + en: Comma-separated list of additional states meaning disconnected, see [docs.evcc.io](https://docs.evcc.io/en/smarthome/home-assistant#charge-status) + de: Komma-getrennte Liste zusätzlicher Zustände für getrennt, siehe [docs.evcc.io](https://docs.evcc.io/de/smarthome/home-assistant#charge-status) - name: statusB description: de: Zustände für Status B @@ -70,8 +70,8 @@ params: example: charging_stopped, charging_completed advanced: true help: - en: Comma-separated list of additional states meaning connected - de: Komma-getrennte Liste zusätzlicher Zustände für verbunden + en: Comma-separated list of additional states meaning connected, see [docs.evcc.io](https://docs.evcc.io/en/smarthome/home-assistant#charge-status) + de: Komma-getrennte Liste zusätzlicher Zustände für verbunden, siehe [docs.evcc.io](https://docs.evcc.io/de/smarthome/home-assistant#charge-status) - name: statusC description: de: Zustände für Status C @@ -79,8 +79,8 @@ params: example: instant_charging, fast_charging advanced: true help: - en: Comma-separated list of additional states meaning charging - de: Komma-getrennte Liste zusätzlicher Zustände für laden + en: Comma-separated list of additional states meaning charging, see [docs.evcc.io](https://docs.evcc.io/en/smarthome/home-assistant#charge-status) + de: Komma-getrennte Liste zusätzlicher Zustände für laden, siehe [docs.evcc.io](https://docs.evcc.io/de/smarthome/home-assistant#charge-status) - name: limitSoc description: de: Ziel-Ladezustand [%] @@ -124,8 +124,8 @@ params: service: homeassistant/entities?uri={uri}&insecure={insecure}&domain=script,switch example: "script.vehicle_start_charge; switch.vehicle_charger" help: - en: Entity ID for a script or a switch that starts charging the vehicle. Only useful with the [docs.evcc.io](https://docs.evcc.io/en/docs/devices/chargers#vehicle-api-only-charger). If a switch is provided, Service to stop charging must be left empty. - de: Entitäts-ID für ein Skript oder einen Schalter zum Starten des Ladevorgangs. Nur sinnvoll mit der [docs.evcc.io](https://docs.evcc.io/docs/devices/chargers#vehicle-api-only-charger). Wenn ein Schalter angegeben wird, muss der Service zum Stoppen des Ladens leer bleiben. + en: Entity ID for a script or a switch that starts charging the vehicle. Only useful with the [Vehicle API-only charger](https://docs.evcc.io/en/chargers/vehicle-api-only-charger). If a switch is provided, Service to stop charging must be left empty. + de: Entitäts-ID für ein Skript oder einen Schalter zum Starten des Ladevorgangs. Nur sinnvoll mit der [Fahrzeug-API Ladesteuerung](https://docs.evcc.io/de/chargers/vehicle-api-only-charger). Wenn ein Schalter angegeben wird, muss der Service zum Stoppen des Ladens leer bleiben. - name: stop_charging description: de: Service zum Laden stoppen @@ -133,8 +133,8 @@ params: service: homeassistant/entities?uri={uri}&insecure={insecure}&domain=script example: "script.vehicle_stop_charge" help: - en: Entity ID for a script that stops charging the vehicle. Only useful with the [docs.evcc.io](https://docs.evcc.io/en/docs/devices/chargers#vehicle-api-only-charger). - de: Entitäts-ID für ein Skript zum Stoppen des Ladevorgangs. Nur sinnvoll mit der [docs.evcc.io](https://docs.evcc.io/docs/devices/chargers#vehicle-api-only-charger). + en: Entity ID for a script that stops charging the vehicle. Only useful with the [Vehicle API-only charger](https://docs.evcc.io/en/chargers/vehicle-api-only-charger). + de: Entitäts-ID für ein Skript zum Stoppen des Ladevorgangs. Nur sinnvoll mit der [Fahrzeug-API Ladesteuerung](https://docs.evcc.io/de/chargers/vehicle-api-only-charger). - name: wakeup description: de: Service zum Aufwecken From 490f209e57287bb64b87f5f6a6687baac1fd3c5c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 30 Aug 2026 10:15:51 +0200 Subject: [PATCH 07/10] EEBus: apply the configured failsafe limits consistently (#33288) --- hems/eebus/eebus.go | 35 +++++++++++++++++++++---------- hems/eebus/eebus_test.go | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/hems/eebus/eebus.go b/hems/eebus/eebus.go index 4c3f1bdc3..ec94decfc 100644 --- a/hems/eebus/eebus.go +++ b/hems/eebus/eebus.go @@ -232,6 +232,9 @@ func (c *EEBus) run() error { if c.failsafeProductionLimit != nil { // production limit is negative, failsafe limits are always positive c.setProductionLimit(-*c.failsafeProductionLimit, true) + } else { + // no failsafe limit configured, release any stale Energy Guard limit + c.setProductionLimit(0, false) } return nil @@ -352,6 +355,24 @@ func (c *EEBus) setProductionLimit(limit float64, active bool) { } } +// effectiveConsumptionLimit returns the LPC limit in force: the configured failsafe +// limit while in failsafe, else the Energy Guard's. Caller holds the mutex. +func (c *EEBus) effectiveConsumptionLimit() float64 { + if c.status == StatusFailsafe { + return c.failsafeConsumptionLimit + } + return c.consumptionLimit.Value +} + +// effectiveProductionLimit returns the LPP limit in force as positive watts, see +// effectiveConsumptionLimit. LPP states its limits as negative watts. +func (c *EEBus) effectiveProductionLimit() float64 { + if c.status == StatusFailsafe && c.failsafeProductionLimit != nil { + return *c.failsafeProductionLimit + } + return -c.productionLimit.Value +} + var _ api.HEMS = (*EEBus)(nil) // CurtailedPercent implements api.HEMS, converting the active LPP production @@ -372,8 +393,7 @@ func (c *EEBus) CurtailedPercent() *int { percent := 100 if limitActive(c.productionLimitActivated) { - // production limits are negative watts - percent = int(-c.productionLimit.Value / c.productionNominalMax * 100) + percent = int(c.effectiveProductionLimit() / c.productionNominalMax * 100) } return &percent @@ -390,10 +410,7 @@ func (c *EEBus) MaxConsumptionPower() *float64 { if !limitActive(c.consumptionLimitActivated) { return new(0.0) } - if c.status == StatusFailsafe { - return new(c.failsafeConsumptionLimit) - } - return new(c.consumptionLimit.Value) + return new(c.effectiveConsumptionLimit()) } // MaxProductionPower implements api.HEMS: nil until first connected, @@ -407,9 +424,5 @@ func (c *EEBus) MaxProductionPower() *float64 { if !limitActive(c.productionLimitActivated) { return new(0.0) } - if c.status == StatusFailsafe { - return c.failsafeProductionLimit - } - // production limits are negative watts, the api.HEMS cap is positive - return new(-c.productionLimit.Value) + return new(c.effectiveProductionLimit()) } diff --git a/hems/eebus/eebus_test.go b/hems/eebus/eebus_test.go index 070b1dbd7..7d8274b50 100644 --- a/hems/eebus/eebus_test.go +++ b/hems/eebus/eebus_test.go @@ -280,6 +280,51 @@ func TestRun_LimitWithoutDuration(t *testing.T) { assertProductionLimit(t, c, true) } +// TestProductionLimit_Failsafe verifies both api.HEMS production getters report the +// configured failsafe limit while in failsafe, not the stale EG-supplied limit +// (#33286): the EG limit had already been released (Value=0) before the heartbeat +// was lost, which must not curtail feed-in to 0%. +func TestProductionLimit_Failsafe(t *testing.T) { + c := newTestEEBus(t) + // EG limit already released before the heartbeat is lost. + c.productionLimit = ucapi.LoadLimit{Value: 0, IsActive: false} + + require.NoError(t, c.run()) + require.Equal(t, StatusFailsafe, c.status) + + percent := c.CurtailedPercent() + require.NotNil(t, percent) + assert.Equal(t, int(testFailsafeProduction/testProductionNominal*100), *percent) + + power := c.MaxProductionPower() + require.NotNil(t, power) + assert.Equal(t, testFailsafeProduction, *power) +} + +// TestProductionLimit_FailsafeUnconfigured verifies that entering failsafe without a +// configured failsafe production limit releases a stale EG limit. run() returns early +// while in failsafe, so a limit left applied here would stay applied indefinitely. +func TestProductionLimit_FailsafeUnconfigured(t *testing.T) { + c := newTestEEBus(t) + c.failsafeProductionLimit = nil + c.heartbeat.Set(struct{}{}) + + c.productionLimit = ucapi.LoadLimit{Value: -500, IsActive: true} + require.NoError(t, c.run()) + assertProductionLimit(t, c, true) + + // heartbeat lost + c.heartbeat = util.NewValue[struct{}](time.Hour) + + require.NoError(t, c.run()) + require.Equal(t, StatusFailsafe, c.status) + assertProductionLimit(t, c, false) + + power := c.MaxProductionPower() + require.NotNil(t, power) + assert.Equal(t, 0.0, *power) +} + // TestMaxProductionPower verifies the api.HEMS export cap is a positive wattage, // while LPP states its limits as negative watts. func TestMaxProductionPower(t *testing.T) { From dbe100b24bceff14b2aaa5c0b05d5a846185747b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 30 Aug 2026 08:15:52 +0000 Subject: [PATCH 08/10] HomeWizard: support 1p kWh meters (#33293) --- meter/homewizard/connection.go | 23 +++++++++++++++---- meter/homewizard/types.go | 38 +++++++++++++++++--------------- meter/homewizard/types_test.go | 40 ++++++++++++++++++++++++---------- 3 files changed, 67 insertions(+), 34 deletions(-) diff --git a/meter/homewizard/connection.go b/meter/homewizard/connection.go index a79f5d4a1..4025f68c0 100644 --- a/meter/homewizard/connection.go +++ b/meter/homewizard/connection.go @@ -10,6 +10,7 @@ import ( "github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/transport" + "github.com/samber/lo" ) // Connection is the homewizard connection @@ -119,10 +120,17 @@ func (c *Connection) TotalEnergy() (float64, error) { // Currents implements the api.PhaseCurrents interface func (c *Connection) Currents() (float64, float64, float64, error) { res, err := c.dataG.Get() - if c.usage == "pv" { - return -res.ActiveCurrentL1A, -res.ActiveCurrentL2A, -res.ActiveCurrentL3A, err + + // 1p meters report the total instead of per-phase values + l1, l2, l3 := res.ActiveCurrentA, 0.0, 0.0 + if res.ActiveCurrentL1A != nil { + l1, l2, l3 = lo.FromPtr(res.ActiveCurrentL1A), lo.FromPtr(res.ActiveCurrentL2A), lo.FromPtr(res.ActiveCurrentL3A) } - return res.ActiveCurrentL1A, res.ActiveCurrentL2A, res.ActiveCurrentL3A, err + + if c.usage == "pv" { + return -l1, -l2, -l3, err + } + return l1, l2, l3, err } // Powers implements the api.PhasePowers interface @@ -137,5 +145,12 @@ func (c *Connection) Powers() (float64, float64, float64, error) { // Voltages implements the api.PhaseVoltages interface func (c *Connection) Voltages() (float64, float64, float64, error) { res, err := c.dataG.Get() - return res.ActiveVoltageL1V, res.ActiveVoltageL2V, res.ActiveVoltageL3V, err + + // 1p meters report the total instead of per-phase values + l1, l2, l3 := res.ActiveVoltageV, 0.0, 0.0 + if res.ActiveCurrentL1A != nil { + l1, l2, l3 = lo.FromPtr(res.ActiveVoltageL1V), lo.FromPtr(res.ActiveVoltageL2V), lo.FromPtr(res.ActiveVoltageL3V) + } + + return l1, l2, l3, err } diff --git a/meter/homewizard/types.go b/meter/homewizard/types.go index 20c3e4e86..f4926ec4e 100644 --- a/meter/homewizard/types.go +++ b/meter/homewizard/types.go @@ -16,22 +16,24 @@ type StateResponse struct { // DataResponse returns the most recent measurements from the HomeWizard device // https://homewizard-energy-api.readthedocs.io/endpoints.html#state-api-v1-state type DataResponse struct { - ActivePowerW float64 `json:"active_power_w"` - ActivePowerL1W float64 `json:"active_power_l1_w"` - ActivePowerL2W float64 `json:"active_power_l2_w"` - ActivePowerL3W float64 `json:"active_power_l3_w"` - TotalPowerImportT1kWh float64 `json:"total_power_import_t1_kwh"` - TotalPowerImportT2kWh float64 `json:"total_power_import_t2_kwh"` - TotalPowerImportT3kWh float64 `json:"total_power_import_t3_kwh"` - TotalPowerImportT4kWh float64 `json:"total_power_import_t4_kwh"` - TotalPowerExportT1kWh float64 `json:"total_power_export_t1_kwh"` - TotalPowerExportT2kWh float64 `json:"total_power_export_t2_kwh"` - TotalPowerExportT3kWh float64 `json:"total_power_export_t3_kwh"` - TotalPowerExportT4kWh float64 `json:"total_power_export_t4_kwh"` - ActiveCurrentL1A float64 `json:"active_current_l1_a"` - ActiveCurrentL2A float64 `json:"active_current_l2_a"` - ActiveCurrentL3A float64 `json:"active_current_l3_a"` - ActiveVoltageL1V float64 `json:"active_voltage_l1_v"` - ActiveVoltageL2V float64 `json:"active_voltage_l2_v"` - ActiveVoltageL3V float64 `json:"active_voltage_l3_v"` + ActivePowerW float64 `json:"active_power_w"` + ActivePowerL1W float64 `json:"active_power_l1_w"` + ActivePowerL2W float64 `json:"active_power_l2_w"` + ActivePowerL3W float64 `json:"active_power_l3_w"` + TotalPowerImportT1kWh float64 `json:"total_power_import_t1_kwh"` + TotalPowerImportT2kWh float64 `json:"total_power_import_t2_kwh"` + TotalPowerImportT3kWh float64 `json:"total_power_import_t3_kwh"` + TotalPowerImportT4kWh float64 `json:"total_power_import_t4_kwh"` + TotalPowerExportT1kWh float64 `json:"total_power_export_t1_kwh"` + TotalPowerExportT2kWh float64 `json:"total_power_export_t2_kwh"` + TotalPowerExportT3kWh float64 `json:"total_power_export_t3_kwh"` + TotalPowerExportT4kWh float64 `json:"total_power_export_t4_kwh"` + ActiveCurrentA float64 `json:"active_current_a"` + ActiveVoltageV float64 `json:"active_voltage_v"` + ActiveCurrentL1A *float64 `json:"active_current_l1_a"` + ActiveCurrentL2A *float64 `json:"active_current_l2_a"` + ActiveCurrentL3A *float64 `json:"active_current_l3_a"` + ActiveVoltageL1V *float64 `json:"active_voltage_l1_v"` + ActiveVoltageL2V *float64 `json:"active_voltage_l2_v"` + ActiveVoltageL3V *float64 `json:"active_voltage_l3_v"` } diff --git a/meter/homewizard/types_test.go b/meter/homewizard/types_test.go index 0a5ee4555..b13e74fde 100644 --- a/meter/homewizard/types_test.go +++ b/meter/homewizard/types_test.go @@ -47,12 +47,28 @@ func TestUnmarshalKwhDataResponse(t *testing.T) { assert.Equal(t, float64(28), res.ActivePowerL1W) assert.Equal(t, float64(0), res.ActivePowerL2W) assert.Equal(t, float64(-181), res.ActivePowerL3W) - assert.Equal(t, float64(235.4), res.ActiveVoltageL1V) - assert.Equal(t, float64(235.8), res.ActiveVoltageL2V) - assert.Equal(t, float64(236.1), res.ActiveVoltageL3V) - assert.Equal(t, float64(1.19), res.ActiveCurrentL1A) - assert.Equal(t, float64(0.37), res.ActiveCurrentL2A) - assert.Equal(t, float64(-0.93), res.ActiveCurrentL3A) + assert.Equal(t, float64(235.4), *res.ActiveVoltageL1V) + assert.Equal(t, float64(235.8), *res.ActiveVoltageL2V) + assert.Equal(t, float64(236.1), *res.ActiveVoltageL3V) + assert.Equal(t, float64(1.19), *res.ActiveCurrentL1A) + assert.Equal(t, float64(0.37), *res.ActiveCurrentL2A) + assert.Equal(t, float64(-0.93), *res.ActiveCurrentL3A) + } +} + +// Test homewizard kWh Meter 1-Phase response without per-phase current/voltage +func TestUnmarshalKwh1PhaseDataResponse(t *testing.T) { + { + var res DataResponse + // https://api-documentation.homewizard.com/docs/v1/measurement#kwh-meters-1-and-3-phase + jsonstr := `{"total_power_import_kwh":1.097,"total_power_import_t1_kwh":1.097,"total_power_export_kwh":0,"total_power_export_t1_kwh":0,"active_power_w":1381.396,"active_power_l1_w":1381.396,"active_voltage_v":228.641,"active_current_a":6.051,"active_apparent_current_a":6.068,"active_reactive_current_a":0.461,"active_apparent_power_va":1385.536,"active_reactive_power_var":-105.28,"active_power_factor":0.997,"active_frequency_hz":50}` + require.NoError(t, json.Unmarshal([]byte(jsonstr), &res)) + + assert.Equal(t, float64(1381.396), res.ActivePowerW) + assert.Equal(t, float64(1381.396), res.ActivePowerL1W) + assert.Equal(t, float64(228.641), res.ActiveVoltageV) + assert.Equal(t, float64(6.051), res.ActiveCurrentA) + assert.Nil(t, res.ActiveCurrentL1A) } } @@ -70,11 +86,11 @@ func TestUnmarshalP1DataResponse(t *testing.T) { assert.Equal(t, float64(-21), res.ActivePowerL1W) assert.Equal(t, float64(57), res.ActivePowerL2W) assert.Equal(t, float64(168), res.ActivePowerL3W) - assert.Equal(t, float64(228), res.ActiveVoltageL1V) - assert.Equal(t, float64(226), res.ActiveVoltageL2V) - assert.Equal(t, float64(225), res.ActiveVoltageL3V) - assert.Equal(t, float64(-0.092), res.ActiveCurrentL1A) - assert.Equal(t, float64(0.252), res.ActiveCurrentL2A) - assert.Equal(t, float64(0.747), res.ActiveCurrentL3A) + assert.Equal(t, float64(228), *res.ActiveVoltageL1V) + assert.Equal(t, float64(226), *res.ActiveVoltageL2V) + assert.Equal(t, float64(225), *res.ActiveVoltageL3V) + assert.Equal(t, float64(-0.092), *res.ActiveCurrentL1A) + assert.Equal(t, float64(0.252), *res.ActiveCurrentL2A) + assert.Equal(t, float64(0.747), *res.ActiveCurrentL3A) } } From d379b7802e54acb269a1898b040d97b691b70f44 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 30 Aug 2026 10:31:40 +0200 Subject: [PATCH 09/10] EEBus: clamp the curtailment percent to the documented maximum (#33300) --- hems/eebus/eebus.go | 3 ++- hems/eebus/eebus_test.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/hems/eebus/eebus.go b/hems/eebus/eebus.go index ec94decfc..bb0f5a79c 100644 --- a/hems/eebus/eebus.go +++ b/hems/eebus/eebus.go @@ -393,7 +393,8 @@ func (c *EEBus) CurtailedPercent() *int { percent := 100 if limitActive(c.productionLimitActivated) { - percent = int(c.effectiveProductionLimit() / c.productionNominalMax * 100) + // the EG may state a limit above the nominal production power + percent = min(int(c.effectiveProductionLimit()/c.productionNominalMax*100), 100) } return &percent diff --git a/hems/eebus/eebus_test.go b/hems/eebus/eebus_test.go index 7d8274b50..2ca8a5689 100644 --- a/hems/eebus/eebus_test.go +++ b/hems/eebus/eebus_test.go @@ -325,6 +325,21 @@ func TestProductionLimit_FailsafeUnconfigured(t *testing.T) { assert.Equal(t, 0.0, *power) } +// TestCurtailedPercent_AboveNominal verifies a limit above the nominal production +// power reports 100%, not more - api.HEMS documents the percent as 0..100 and it +// reaches the inverter unchecked. +func TestCurtailedPercent_AboveNominal(t *testing.T) { + c := newTestEEBus(t) + c.heartbeat.Set(struct{}{}) + c.productionLimit = ucapi.LoadLimit{Value: -2 * testProductionNominal, IsActive: true} + + require.NoError(t, c.run()) + + percent := c.CurtailedPercent() + require.NotNil(t, percent) + assert.Equal(t, 100, *percent) +} + // TestMaxProductionPower verifies the api.HEMS export cap is a positive wattage, // while LPP states its limits as negative watts. func TestMaxProductionPower(t *testing.T) { From 13215c74c248e5d3a44b9f482cdc96cf63f57145 Mon Sep 17 00:00:00 2001 From: Stefan Date: Sun, 30 Aug 2026 10:41:18 +0200 Subject: [PATCH 10/10] Remove sponsor token gating Unlock all locally gated features without a sponsor token. The change sits in util/sponsor/auth.go instead of the ~68 device constructors: - Subject defaults to a non-empty value, so RedactedStatus reports an active sponsorship and the frontend unlocks isSponsor - IsAuthorized always returns true, opening every caller including the modbus proxy and the optimizer gate - ConfigureSponsorship still validates a configured token but never fails, so an expired token no longer aborts startup Drops TestAlpitronicSponsorGate and TestSigenergyEVDCSponsorGate, which asserted exactly the gate that is removed here. Cloud-backed services (optimizer API, remote access, cloud vehicles, telemetry) still require a real token - those are checked server side. See FORK.md. --- FORK.md | 54 ++++++++++++++++++++++++++++++++++ charger/alpitronic_test.go | 12 -------- charger/sigenergy-evdc_test.go | 12 -------- util/sponsor/auth.go | 39 +++++++++++++++++++----- 4 files changed, 86 insertions(+), 31 deletions(-) create mode 100644 FORK.md diff --git a/FORK.md b/FORK.md new file mode 100644 index 000000000..4508b30fd --- /dev/null +++ b/FORK.md @@ -0,0 +1,54 @@ +# Fork-Hinweise + +Fork von [evcc-io/evcc](https://github.com/evcc-io/evcc). + +## Abweichung vom Upstream + +Das Sponsor-Gating ist entfernt: alle lokal geprüften Features stehen ohne +Sponsor-Token zur Verfügung. Der Eingriff sitzt an einer einzigen Stelle in +`util/sponsor/auth.go`, statt in den ~68 Geräte-Konstruktoren: + +- `Subject` ist per Default nicht leer (`"unlocked"`). Damit meldet + `RedactedStatus()` einen aktiven Sponsor-Status, und das Frontend schaltet + `isSponsor` (`assets/js/views/Config.vue`) frei — Geräte-Dialoge zeigen kein + „Sponsor-Token erforderlich" mehr. +- `IsAuthorized()` liefert immer `true`. Das öffnet alle Aufrufer, u. a. die + Charger-/Vehicle-Konstruktoren, `server/modbus/proxy.go` und den + Optimizer-Gate in `core/site_optimizer.go`. +- `ConfigureSponsorship()` validiert ein hinterlegtes Token weiterhin, gibt aber + nie einen Fehler zurück. Ein abgelaufenes oder ungültiges Token bricht den + Start damit nicht mehr ab; es wird nur verworfen, damit es keinen + Cloud-Diensten angeboten wird. + +Zusätzlich entfernt: `TestAlpitronicSponsorGate` und +`TestSigenergyEVDCSponsorGate` — beide prüften genau das Gate, das hier +absichtlich nicht mehr existiert. + +## Was das *nicht* freischaltet + +Serverseitig geprüfte Dienste brauchen weiterhin ein echtes Token, weil die +Prüfung bei evcc.io stattfindet und nicht im Client: + +- Optimizer-API (`core/site_optimizer.go` sendet `Bearer `) +- Remote Access / Tunnel (`server/remote/`) +- Cloud-Fahrzeuge und Tronity (`vehicle/cloud.go`, `vehicle/tronity.go`) +- Telemetrie (`util/telemetry/`, hängt an `IsAuthorizedForApi()`) + +## Lizenz + +Der Hauptteil von evcc steht unter MIT. `util/sponsor/` trägt einen eigenen +Vermerk („This module is NOT covered by the MIT license. All rights reserved."). +Diese Änderung betrifft genau dieses Modul. + +evcc finanziert sich über Sponsoring: + +## Upstream-Sync + +``` +git remote add upstream https://github.com/evcc-io/evcc.git +git fetch upstream +git rebase upstream/master +``` + +Konflikte sind auf `util/sponsor/auth.go` beschränkt; `FORK.md` liegt bewusst +außerhalb der Upstream-Dateien. diff --git a/charger/alpitronic_test.go b/charger/alpitronic_test.go index 911b660c8..d6b01dd3e 100644 --- a/charger/alpitronic_test.go +++ b/charger/alpitronic_test.go @@ -10,7 +10,6 @@ import ( "github.com/andig/mbserver" "github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/util/modbus" - "github.com/evcc-io/evcc/util/sponsor" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -362,14 +361,3 @@ func TestAlpitronicReadFailure(t *testing.T) { _, err = wb.CurrentPower() assert.Error(t, err) } - -func TestAlpitronicSponsorGate(t *testing.T) { - // go-e tests set the global sponsor.Subject and never reset it - old := sponsor.Subject - sponsor.Subject = "" - t.Cleanup(func() { sponsor.Subject = old }) - - // tests run without sponsorship: the public constructor must refuse - _, err := NewAlpitronicHYC(t.Context(), modbus.TcpSettings{URI: "localhost:0", ID: 1}, 1) - assert.ErrorIs(t, err, api.ErrSponsorRequired) -} diff --git a/charger/sigenergy-evdc_test.go b/charger/sigenergy-evdc_test.go index 36f78b18d..32a197d87 100644 --- a/charger/sigenergy-evdc_test.go +++ b/charger/sigenergy-evdc_test.go @@ -10,7 +10,6 @@ import ( "github.com/andig/mbserver" "github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/util/modbus" - "github.com/evcc-io/evcc/util/sponsor" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -290,17 +289,6 @@ func TestSigenergyEVDCMinMaxCurrent(t *testing.T) { assert.InDelta(t, 36.23, maxA, 0.01) // 25000 W / 690 } -func TestSigenergyEVDCSponsorGate(t *testing.T) { - // go-e tests set the global sponsor.Subject and never reset it - old := sponsor.Subject - sponsor.Subject = "" - t.Cleanup(func() { sponsor.Subject = old }) - - // tests run without sponsorship: the public constructor must refuse - _, err := NewSigenergyEVDC(t.Context(), "localhost:0", 1) - assert.ErrorIs(t, err, api.ErrSponsorRequired) -} - func TestSigenergyEVDCReadFailure(t *testing.T) { // missing register in the bulk-read block -> IllegalDataAddress propagates regs := evdcRegs(evdcStateCharging) diff --git a/util/sponsor/auth.go b/util/sponsor/auth.go index ed225fccf..9b707a889 100644 --- a/util/sponsor/auth.go +++ b/util/sponsor/auth.go @@ -35,10 +35,15 @@ import ( "google.golang.org/grpc/status" ) +// unlocked is the sponsorship subject used by this fork. Sponsor gating is +// removed here, so Subject is never empty and IsAuthorized always holds. +const unlocked = "unlocked" + var ( - mu sync.RWMutex - Subject, Token string - ExpiresAt time.Time + mu sync.RWMutex + Subject = unlocked + Token string + ExpiresAt time.Time ) func machineID() string { @@ -51,9 +56,8 @@ const unavailable = "sponsorship unavailable" const startupTimeout = 30 * time.Second func IsAuthorized() bool { - mu.RLock() - defer mu.RUnlock() - return len(Subject) > 0 + // sponsorship gating removed in this fork + return true } func IsAuthorizedForApi() bool { @@ -62,8 +66,29 @@ func IsAuthorizedForApi() bool { return IsAuthorized() && Subject != unavailable && Token != "" } -// check and set sponsorship token +// ConfigureSponsorship validates a sponsor token when one is configured, but +// never fails: sponsorship is not required in this fork. A valid token is +// still picked up so cloud-backed services keep working for real sponsors. func ConfigureSponsorship(token string) error { + err := configureSponsorship(token) + + mu.Lock() + defer mu.Unlock() + + if err != nil { + // stay unlocked, but do not offer a rejected token to cloud services + Token = "" + } + + if Subject == "" { + Subject = unlocked + } + + return nil +} + +// check and set sponsorship token +func configureSponsorship(token string) error { mu.Lock() defer mu.Unlock()