From 4a8e6ad9eab6130d50046fa3b3a473b155e1a2c6 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 4 Aug 2024 18:23:27 +0200 Subject: [PATCH 1/3] HEMS: use configurable circuit for SteuVE --- cmd/demo.yaml | 19 +++++++++++++++++++ hems/eebus/eebus.go | 27 ++++++++------------------- hems/relay/relay.go | 24 ++++++------------------ 3 files changed, 33 insertions(+), 37 deletions(-) diff --git a/cmd/demo.yaml b/cmd/demo.yaml index dc1a327ffc..3ae5998d70 100644 --- a/cmd/demo.yaml +++ b/cmd/demo.yaml @@ -242,16 +242,35 @@ site: loadpoints: - title: Carport + circuit: lpc charger: charger_1 mode: pv meter: meter_charger_1 vehicle: vehicle_1 - title: Garage + circuit: root charger: charger_2 mode: "off" meter: meter_charger_2 vehicle: vehicle_2 +circuits: + - name: root + title: Grid + meter: grid + - name: lpc + Title: Limitation of Grid Consumption + parent: root + +hems: + type: relay + circuit: lpc + maxPower: 4200 # single SteuVE + limit: + source: go + script: | + true + tariffs: currency: EUR # three letter ISO-4217 currency code (default EUR) grid: diff --git a/hems/eebus/eebus.go b/hems/eebus/eebus.go index 3a7a7947be..e1803574d1 100644 --- a/hems/eebus/eebus.go +++ b/hems/eebus/eebus.go @@ -2,16 +2,17 @@ package eebus import ( "errors" + "fmt" "sync" "time" ucapi "github.com/enbility/eebus-go/usecases/api" "github.com/evcc-io/evcc/api" - "github.com/evcc-io/evcc/core/circuit" "github.com/evcc-io/evcc/core/site" "github.com/evcc-io/evcc/provider" "github.com/evcc-io/evcc/server/eebus" "github.com/evcc-io/evcc/util" + "github.com/evcc-io/evcc/util/config" ) type EEBus struct { @@ -43,8 +44,9 @@ type Limits struct { // New creates an EEBus HEMS from generic config func New(other map[string]interface{}, site site.API) (*EEBus, error) { cc := struct { - Ski string - Limits `mapstructure:",squash"` + Ski string + Circuit string + Limits `mapstructure:",squash"` }{ Limits: Limits{ ContractualConsumptionNominalMax: 24800, @@ -58,25 +60,12 @@ func New(other map[string]interface{}, site site.API) (*EEBus, error) { return nil, err } - // get root circuit - root := circuit.Root() - if root == nil { - return nil, errors.New("hems requires load management- please configure root circuit") - } - - // create new root circuit for LPC - lpc, err := circuit.New(util.NewLogger("lpc"), "eebus", 0, 0, nil, time.Minute) + circuit, err := config.Circuits().ByName(cc.Circuit) if err != nil { - return nil, err - } - - // wrap old root with new pc parent - if err := root.Wrap(lpc); err != nil { - return nil, err + return nil, fmt.Errorf("circuit: %w", err) } - site.SetCircuit(lpc) - return NewEEBus(cc.Ski, cc.Limits, lpc) + return NewEEBus(cc.Ski, cc.Limits, circuit.Instance()) } // NewEEBus creates EEBus charger diff --git a/hems/relay/relay.go b/hems/relay/relay.go index 741b3bc77c..674b5cb72e 100644 --- a/hems/relay/relay.go +++ b/hems/relay/relay.go @@ -1,14 +1,14 @@ package relay import ( - "errors" + "fmt" "time" "github.com/evcc-io/evcc/api" - "github.com/evcc-io/evcc/core/circuit" "github.com/evcc-io/evcc/core/site" "github.com/evcc-io/evcc/provider" "github.com/evcc-io/evcc/util" + "github.com/evcc-io/evcc/util/config" ) type Relay struct { @@ -23,6 +23,7 @@ type Relay struct { func New(other map[string]interface{}, site site.API) (*Relay, error) { var cc struct { MaxPower float64 + Circuit string Limit provider.Config } @@ -30,23 +31,10 @@ func New(other map[string]interface{}, site site.API) (*Relay, error) { return nil, err } - // get root circuit - root := circuit.Root() - if root == nil { - return nil, errors.New("hems requires load management- please configure root circuit") - } - - // create new root circuit for LPC - lpc, err := circuit.New(util.NewLogger("lpc"), "relay", 0, 0, nil, time.Minute) + circuit, err := config.Circuits().ByName(cc.Circuit) if err != nil { - return nil, err - } - - // wrap old root with new pc parent - if err := root.Wrap(lpc); err != nil { - return nil, err + return nil, fmt.Errorf("circuit: %w", err) } - site.SetCircuit(lpc) // limit getter limitG, err := provider.NewBoolGetterFromConfig(cc.Limit) @@ -54,7 +42,7 @@ func New(other map[string]interface{}, site site.API) (*Relay, error) { return nil, err } - return NewRelay(lpc, limitG, cc.MaxPower) + return NewRelay(circuit.Instance(), limitG, cc.MaxPower) } // NewRelay creates Relay HEMS From b73a612195947b52f094990bc67a58379f9cc8cf Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 4 Aug 2024 18:25:45 +0200 Subject: [PATCH 2/3] wip --- api/api.go | 1 - core/circuit/circuit.go | 8 -------- 2 files changed, 9 deletions(-) diff --git a/api/api.go b/api/api.go index c7dcafb399..df264285b0 100644 --- a/api/api.go +++ b/api/api.go @@ -222,7 +222,6 @@ type Circuit interface { SetTitle(string) GetParent() Circuit RegisterChild(child Circuit) - Wrap(parent Circuit) error HasMeter() bool GetMaxPower() float64 GetMaxCurrent() float64 diff --git a/core/circuit/circuit.go b/core/circuit/circuit.go index ad31ee7e8f..749a70c3e5 100644 --- a/core/circuit/circuit.go +++ b/core/circuit/circuit.go @@ -133,14 +133,6 @@ func (c *Circuit) setParent(parent api.Circuit) error { return nil } -// Wrap wraps circuit with parent, keeping the original meter -func (c *Circuit) Wrap(parent api.Circuit) error { - if c.meter != nil { - parent.(*Circuit).meter = c.meter - } - return c.setParent(parent) -} - // HasMeter returns the max power setting func (c *Circuit) HasMeter() bool { c.mu.RLock() From 11cdba2cd923aafe6b80bd466f9b5205f432f239 Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 5 Aug 2024 17:48:30 +0200 Subject: [PATCH 3/3] Update cmd/demo.yaml --- cmd/demo.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/demo.yaml b/cmd/demo.yaml index 3ae5998d70..d7b07669e8 100644 --- a/cmd/demo.yaml +++ b/cmd/demo.yaml @@ -259,7 +259,7 @@ circuits: title: Grid meter: grid - name: lpc - Title: Limitation of Grid Consumption + title: Limitation of Power Consumption parent: root hems: