From ad0f5477cb5cb0b4c367ab6237dc114fb4123047 Mon Sep 17 00:00:00 2001 From: Andreas Linde <42185+DerAndereAndi@users.noreply.github.com> Date: Sun, 1 Sep 2024 10:50:41 +0200 Subject: [PATCH] EEbus: Monitor measurements after limit change (#15778) If a limit has been set, a measurement is expected to provided within 15s. If this is not the case, then show a warning and return an error. Also add support for the Elli Connect Pro internal meter again. This should now lead to those EEBUS wallboxes not providing measurements, to fall back to the actual limit being assumed as being the current measurement. And the user is informed about non function metering in the wallbox. --- charger/eebus.go | 31 ++++++++++++++----- server/eebus/helper.go | 15 +++++++++ .../definition/charger/elli-charger-pro.yaml | 2 ++ 3 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 server/eebus/helper.go diff --git a/charger/eebus.go b/charger/eebus.go index 7a8ce4e44..d570d827f 100644 --- a/charger/eebus.go +++ b/charger/eebus.go @@ -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" @@ -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 @@ -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() } } @@ -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 } @@ -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 } @@ -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 @@ -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 { diff --git a/server/eebus/helper.go b/server/eebus/helper.go new file mode 100644 index 000000000..8aa7f61fc --- /dev/null +++ b/server/eebus/helper.go @@ -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 +} diff --git a/templates/definition/charger/elli-charger-pro.yaml b/templates/definition/charger/elli-charger-pro.yaml index 29fa36c43..194f22e40 100644 --- a/templates/definition/charger/elli-charger-pro.yaml +++ b/templates/definition/charger/elli-charger-pro.yaml @@ -36,3 +36,5 @@ params: - name: ip render: | {{ include "eebus" . }} + meter: true + chargedEnergy: false