diff --git a/hems/eebus/eebus.go b/hems/eebus/eebus.go index 42cf790ff..ef7f3dfc6 100644 --- a/hems/eebus/eebus.go +++ b/hems/eebus/eebus.go @@ -11,6 +11,7 @@ import ( "github.com/evcc-io/evcc/core/circuit" "github.com/evcc-io/evcc/core/site" "github.com/evcc-io/evcc/hems/shared" + "github.com/evcc-io/evcc/plugin" "github.com/evcc-io/evcc/server/eebus" "github.com/evcc-io/evcc/util" ) @@ -24,7 +25,8 @@ type EEBus struct { ma *eebus.MonitoringAppliance eg *eebus.EnergyGuard - root api.Circuit + root api.Circuit + passthrough func(bool) error status status statusUpdated time.Time @@ -47,9 +49,10 @@ type Limits struct { // NewFromConfig creates an EEBus HEMS from generic config func NewFromConfig(ctx context.Context, other map[string]any, site site.API) (*EEBus, error) { cc := struct { - Ski string - Limits `mapstructure:",squash"` - Interval time.Duration + Ski string + Limits `mapstructure:",squash"` + Passthrough *plugin.Config + Interval time.Duration }{ Limits: Limits{ ContractualConsumptionNominalMax: 24800, @@ -64,6 +67,11 @@ func NewFromConfig(ctx context.Context, other map[string]any, site site.API) (*E return nil, err } + passthroughS, err := cc.Passthrough.BoolSetter(ctx, "dim") + if err != nil { + return nil, err + } + // get root circuit root := circuit.Root() if root == nil { @@ -82,24 +90,25 @@ func NewFromConfig(ctx context.Context, other map[string]any, site site.API) (*E } site.SetCircuit(lpc) - return NewEEBus(ctx, cc.Ski, cc.Limits, lpc, cc.Interval) + return NewEEBus(ctx, cc.Ski, cc.Limits, passthroughS, lpc, cc.Interval) } // NewEEBus creates EEBus charger -func NewEEBus(ctx context.Context, ski string, limits Limits, root api.Circuit, interval time.Duration) (*EEBus, error) { +func NewEEBus(ctx context.Context, ski string, limits Limits, passthrough func(bool) error, root api.Circuit, interval time.Duration) (*EEBus, error) { if eebus.Instance == nil { return nil, errors.New("eebus not configured") } c := &EEBus{ - log: util.NewLogger("eebus"), - root: root, - cs: eebus.Instance.ControllableSystem(), - ma: eebus.Instance.MonitoringAppliance(), - eg: eebus.Instance.EnergyGuard(), - Connector: eebus.NewConnector(), - heartbeat: util.NewValue[struct{}](2 * time.Minute), // LPC-031 - interval: interval, + log: util.NewLogger("eebus"), + root: root, + passthrough: passthrough, + cs: eebus.Instance.ControllableSystem(), + ma: eebus.Instance.MonitoringAppliance(), + eg: eebus.Instance.EnergyGuard(), + Connector: eebus.NewConnector(), + heartbeat: util.NewValue[struct{}](2 * time.Minute), // LPC-031 + interval: interval, consumptionLimit: &ucapi.LoadLimit{ Value: limits.ConsumptionLimit, @@ -238,4 +247,10 @@ func (c *EEBus) setStatusAndLimit(status status, limit float64) { func (c *EEBus) setLimit(limit float64) { c.root.Dim(limit > 0) c.root.SetMaxPower(limit) + + if c.passthrough != nil { + if err := c.passthrough(limit > 0); err != nil { + c.log.ERROR.Printf("passthrough failed: %v", err) + } + } } diff --git a/hems/relay/relay.go b/hems/relay/relay.go index 55dc51767..17cd78bdb 100644 --- a/hems/relay/relay.go +++ b/hems/relay/relay.go @@ -3,6 +3,7 @@ package relay import ( "context" "errors" + "fmt" "time" "github.com/evcc-io/evcc/api" @@ -16,18 +17,20 @@ import ( type Relay struct { log *util.Logger - root api.Circuit - limit func() (bool, error) - maxPower float64 - interval time.Duration + root api.Circuit + passthrough func(bool) error + limit func() (bool, error) + maxPower float64 + interval time.Duration } // NewFromConfig creates an Relay HEMS from generic config func NewFromConfig(ctx context.Context, other map[string]any, site site.API) (*Relay, error) { cc := struct { - MaxPower float64 - Limit plugin.Config - Interval time.Duration + MaxPower float64 + Limit plugin.Config + Passthrough *plugin.Config + Interval time.Duration }{ Interval: 10 * time.Second, } @@ -60,17 +63,23 @@ func NewFromConfig(ctx context.Context, other map[string]any, site site.API) (*R return nil, err } - return NewRelay(lpc, limitG, cc.MaxPower, cc.Interval) + passthroughS, err := cc.Passthrough.BoolSetter(ctx, "dim") + if err != nil { + return nil, err + } + + return NewRelay(lpc, limitG, passthroughS, cc.MaxPower, cc.Interval) } // NewRelay creates Relay HEMS -func NewRelay(root api.Circuit, limit func() (bool, error), maxPower float64, interval time.Duration) (*Relay, error) { +func NewRelay(root api.Circuit, limit func() (bool, error), passthrough func(bool) error, maxPower float64, interval time.Duration) (*Relay, error) { c := &Relay{ - log: util.NewLogger("relay"), - root: root, - maxPower: maxPower, - limit: limit, - interval: interval, + log: util.NewLogger("relay"), + root: root, + passthrough: passthrough, + maxPower: maxPower, + limit: limit, + interval: interval, } return c, nil @@ -98,5 +107,11 @@ func (c *Relay) run() error { c.root.Dim(limit) c.root.SetMaxPower(power) + if c.passthrough != nil { + if err := c.passthrough(limit); err != nil { + return fmt.Errorf("passthrough failed: %w", err) + } + } + return nil }