From 58b6e70e647dd6e2b24f288da91cac4b14c7a8b6 Mon Sep 17 00:00:00 2001 From: Markus Thierolf <77847348+thierolm@users.noreply.github.com> Date: Fri, 4 Feb 2022 08:08:52 +0100 Subject: [PATCH] TPLink/Tasmota: fix total energy (#2484) --- charger/tasmota.go | 5 +++-- charger/tplink.go | 14 ++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/charger/tasmota.go b/charger/tasmota.go index a8002d324a..17d6c84152 100644 --- a/charger/tasmota.go +++ b/charger/tasmota.go @@ -53,11 +53,12 @@ func NewTasmota(uri, user, password string, standbypower float64) (*Tasmota, err log := util.NewLogger("tasmota") c := &Tasmota{ Helper: request.NewHelper(log), - uri: strings.TrimRight(uri, "/"), + uri: util.DefaultScheme(strings.TrimRight(uri, "/"), "http"), user: user, password: password, standbypower: standbypower, } + c.Client.Transport = request.NewTripper(log, transport.Insecure()) return c, nil @@ -132,7 +133,7 @@ func (c *Tasmota) TotalEnergy() (float64, error) { var resp tasmota.StatusSNSResponse err := c.GetJSON(c.cmdUri("Status 8"), &resp) - return resp.StatusSNS.Energy.Today, err + return resp.StatusSNS.Energy.Total, err } // cmdUri creates the Tasmota command web request diff --git a/charger/tplink.go b/charger/tplink.go index 5f4c9e1590..69c1b04f51 100644 --- a/charger/tplink.go +++ b/charger/tplink.go @@ -138,20 +138,18 @@ var _ api.MeterEnergy = (*TPLink)(nil) // TotalEnergy implements the api.MeterEnergy interface func (c *TPLink) TotalEnergy() (float64, error) { - var resp tplink.DayStatResponse - year, month, day := time.Now().Date() - cmd := fmt.Sprintf(`{"emeter":{"get_daystat":{"day":%v,"month":%v,"year":%v}}}`, day, int(month), year) - if err := c.execCmd(cmd, &resp); err != nil { + var resp tplink.EmeterResponse + if err := c.execCmd(`{"emeter":{"get_realtime":null}}`, &resp); err != nil { return 0, err } - if err := resp.Emeter.GetDaystat.ErrCode; err != 0 { - return 0, fmt.Errorf("get_daystat error %d", err) + if err := resp.Emeter.GetRealtime.ErrCode; err != 0 { + return 0, fmt.Errorf("get_realtime error %d", err) } - energy := resp.Emeter.GetDaystat.DayList[len(resp.Emeter.GetDaystat.DayList)-1].EnergyWh / 1000 + energy := resp.Emeter.GetRealtime.TotalWh / 1000 if energy == 0 { - energy = resp.Emeter.GetDaystat.DayList[len(resp.Emeter.GetDaystat.DayList)-1].Energy + energy = resp.Emeter.GetRealtime.Total } return energy, nil