diff --git a/charger/easee.go b/charger/easee.go index 38da681de..468838baa 100644 --- a/charger/easee.go +++ b/charger/easee.go @@ -30,6 +30,7 @@ import ( "github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/charger/easee" + "github.com/evcc-io/evcc/core/loadpoint" "github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/sponsor" @@ -50,11 +51,13 @@ type Easee struct { dynamicChargerCurrent float64 current float64 chargerEnabled bool + smartCharging bool enabledStatus bool phaseMode int currentPower, sessionEnergy, currentL1, currentL2, currentL3 float64 rfid string + lp loadpoint.API } func init() { @@ -269,6 +272,8 @@ func (c *Easee) observe(typ string, i json.RawMessage) { c.rfid = res.Value case easee.IS_ENABLED: c.chargerEnabled = value.(bool) + case easee.SMART_CHARGING: + c.smartCharging = value.(bool) case easee.TOTAL_POWER: c.currentPower = 1e3 * value.(float64) case easee.SESSION_ENERGY: @@ -336,6 +341,8 @@ func (c *Easee) chargers() ([]easee.Charger, error) { // Status implements the api.Charger interface func (c *Easee) Status() (api.ChargeStatus, error) { + c.updateSmartCharging() + c.mux.L.Lock() defer c.mux.L.Unlock() @@ -500,3 +507,40 @@ func (c *Easee) Identify() (string, error) { return c.rfid, nil } + +// Set smart charging status to update the chargers led (smart=blue, fast=white) +func (c *Easee) updateSmartCharging() { + if c.lp == nil { + return + } + + mode := c.lp.GetMode() + isSmartCharging := mode == api.ModePV || mode == api.ModeMinPV + + c.mux.L.Lock() + updateNeeded := isSmartCharging != c.smartCharging + c.mux.L.Unlock() + + if updateNeeded { + data := easee.ChargerSettings{ + SmartCharging: &isSmartCharging, + } + uri := fmt.Sprintf("%s/chargers/%s/settings", easee.API, c.charger) + resp, err := c.Post(uri, request.JSONContent, request.MarshalJSON(data)) + if err != nil { + c.log.WARN.Println("smart charging update failed:", err) + } else if resp.StatusCode != http.StatusAccepted { + resp.Body.Close() + c.log.WARN.Println("smart charging update failed:", resp.StatusCode, resp.Status) + } + + c.mux.L.Lock() + c.smartCharging = isSmartCharging + c.mux.L.Unlock() + } +} + +// LoadpointControl implements loadpoint.Controller +func (c *Easee) LoadpointControl(lp loadpoint.API) { + c.lp = lp +}