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

EEBUS: Monitor measurements after limit change #15778

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 23 additions & 8 deletions charger/eebus.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
eebusapi "github.com/enbility/eebus-go/api"
ucapi "github.com/enbility/eebus-go/usecases/api"
"github.com/enbility/eebus-go/usecases/cem/evcc"
"github.com/enbility/eebus-go/usecases/cem/evcem"
spineapi "github.com/enbility/spine-go/api"
"github.com/enbility/spine-go/model"
"github.com/evcc-io/evcc/api"
Expand Down Expand Up @@ -38,6 +39,9 @@ type EEBus struct {
lp loadpoint.API
minMaxG func() (minMax, error)

limitUpdated time.Time // time of last limit change
currentsUpdated time.Time // time of last measurement

vasVW bool // wether the EVSE supports VW VAS with ISO15118-2
enabled bool
reconnect bool
Expand Down Expand Up @@ -121,6 +125,10 @@ func (c *EEBus) UseCaseEvent(device spineapi.DeviceRemoteInterface, entity spine

case evcc.EvDisconnected:
c.ev = nil

case evcem.DataUpdateCurrentPerPhase:
// do not use the timestamp of the measurement itself, as some devices don't provide it
c.currentsUpdated = time.Now()
}
}

Expand Down Expand Up @@ -330,6 +338,7 @@ func (c *EEBus) writeCurrentLimitData(evEntity spineapi.EntityRemoteInterface, c
// if VAS VW is available, limits are completely covered by it
// this way evcc can fully control the charging behaviour
if c.writeLoadControlLimitsVASVW(evEntity, limits) {
c.limitUpdated = time.Now()
return nil
}

Expand All @@ -340,6 +349,9 @@ func (c *EEBus) writeCurrentLimitData(evEntity spineapi.EntityRemoteInterface, c

// set overload protection limits
_, err = c.uc.OpEV.WriteLoadControlLimits(evEntity, limits, nil)
if err == nil {
c.limitUpdated = time.Now()
}

return err
}
Expand Down Expand Up @@ -551,12 +563,18 @@ func (c *EEBus) currents() (float64, float64, float64, error) {
return 0, 0, 0, api.ErrNotAvailable
}

c.mux.Lock()
ts := c.currentsUpdated
c.mux.Unlock()

// if there is no measurement data available within 15 seconds after the last limit change, return an error
if d := ts.Sub(c.limitUpdated); d < 0 || d > 15*time.Second {
return 0, 0, 0, api.ErrNotAvailable
}

res, err := c.uc.EvCem.CurrentPerPhase(evEntity)
if err != nil {
if err == eebusapi.ErrDataNotAvailable {
err = api.ErrNotAvailable
}
return 0, 0, 0, err
return 0, 0, 0, eebus.WrapError(err)
}

// fill phases
Expand Down Expand Up @@ -618,10 +636,7 @@ func (c *EEBus) minMax() (minMax, error) {

minLimits, maxLimits, _, err := c.uc.OpEV.CurrentLimits(evEntity)
if err != nil {
if err == eebusapi.ErrDataNotAvailable {
err = api.ErrNotAvailable
}
return zero, err
return zero, eebus.WrapError(err)
}

if len(minLimits) == 0 || len(maxLimits) == 0 {
Expand Down
15 changes: 15 additions & 0 deletions server/eebus/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package eebus

import (
"errors"

eebusapi "github.com/enbility/eebus-go/api"
"github.com/evcc-io/evcc/api"
)

func WrapError(err error) error {
if errors.Is(err, eebusapi.ErrDataNotAvailable) {
return api.ErrNotAvailable
}
return err
}
2 changes: 2 additions & 0 deletions templates/definition/charger/elli-charger-pro.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ params:
- name: ip
render: |
{{ include "eebus" . }}
meter: true
chargedEnergy: false
Loading