Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HEMS: use configurable circuit for SteuVE #15241

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ type Circuit interface {
SetTitle(string)
GetParent() Circuit
RegisterChild(child Circuit)
Wrap(parent Circuit) error
HasMeter() bool
GetMaxPower() float64
GetMaxCurrent() float64
Expand Down
19 changes: 19 additions & 0 deletions cmd/demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
andig marked this conversation as resolved.
Show resolved Hide resolved
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:
Expand Down
8 changes: 0 additions & 8 deletions core/circuit/circuit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
27 changes: 8 additions & 19 deletions hems/eebus/eebus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
24 changes: 6 additions & 18 deletions hems/relay/relay.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -23,38 +23,26 @@ type Relay struct {
func New(other map[string]interface{}, site site.API) (*Relay, error) {
var cc struct {
MaxPower float64
Circuit string
Limit provider.Config
}

if err := util.DecodeOther(other, &cc); err != nil {
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)
if err != nil {
return nil, err
}

return NewRelay(lpc, limitG, cc.MaxPower)
return NewRelay(circuit.Instance(), limitG, cc.MaxPower)
}

// NewRelay creates Relay HEMS
Expand Down
Loading