diff --git a/meter/tasmota.go b/meter/tasmota.go index 58aa21aae..bd7d9f5b3 100644 --- a/meter/tasmota.go +++ b/meter/tasmota.go @@ -71,6 +71,10 @@ func NewTasmota(uri, user, password, usage string, channels []int, cache time.Du implement.Has(c, implement.PhasePowers(c.powers)) } + if _, err := c.conn.ReturnEnergy(); err == nil { + implement.Has(c, implement.MeterReturnEnergy(c.returnEnergy)) + } + return c, nil } @@ -96,6 +100,11 @@ func (c *Tasmota) TotalEnergy() (float64, error) { return c.conn.TotalEnergy() } +// returnEnergy implements the api.MeterReturnEnergy interface +func (c *Tasmota) returnEnergy() (float64, error) { + return c.conn.ReturnEnergy() +} + // powers implements the api.PhasePowers interface func (c *Tasmota) powers() (float64, float64, float64, error) { return c.conn.Powers() diff --git a/meter/tasmota/connection.go b/meter/tasmota/connection.go index 2339a0157..3442d3932 100644 --- a/meter/tasmota/connection.go +++ b/meter/tasmota/connection.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/transport" @@ -229,12 +230,27 @@ func (c *Connection) TotalEnergy() (float64, error) { return 0, err } - // SML total energy available + // SML import energy available if sml := res.StatusSNS.SML.TotalIn; sml != nil { - return *sml, err + return *sml, nil } - return res.StatusSNS.Energy.Total, err + return res.StatusSNS.Energy.Total, nil +} + +// ReturnEnergy implements the api.MeterReturnEnergy interface +func (c *Connection) ReturnEnergy() (float64, error) { + res, err := c.statusSnsG.Get() + if err != nil { + return 0, err + } + + // SML export energy available + if sml := res.StatusSNS.SML.TotalOut; sml != nil { + return *sml, nil + } + + return 0, api.ErrNotAvailable } // Powers implements the api.PhasePowers interface diff --git a/meter/tasmota/types_test.go b/meter/tasmota/types_test.go index a8126f89d..f69bd28ca 100644 --- a/meter/tasmota/types_test.go +++ b/meter/tasmota/types_test.go @@ -30,11 +30,15 @@ func TestUnmarshalStatusSNSResponse(t *testing.T) { jsonstr = `{"StatusSNS":{"Time":"2022-07-07T13:01:11","HTU21":{"Temperature":25.2,"Humidity":45.5},"SML":{"Total_in":34507.4761,"Total_out":14737.1422,"Power_curr":-894,"Meter_number":"0901454d48000000000"},"Gas":{"Count":1.84},"TempUnit":"C"}}` require.NoError(t, json.Unmarshal([]byte(jsonstr), &res)) assert.Equal(t, float64(-894), *res.StatusSNS.SML.PowerCurr) + assert.Equal(t, float64(34507.4761), *res.StatusSNS.SML.TotalIn) + assert.Equal(t, float64(14737.1422), *res.StatusSNS.SML.TotalOut) // Test case for #26857 jsonstr = `{"StatusSNS":{"Time":"2026-01-21T11:07:31","SML":{"Total_in":2687.3687,"Total_out":582.4569,"Power_curr":-36,"Meter_Id":"0a01454652240487bd2a","power_l1":60,"power_l2":-111,"power_l3":14,"voltage_l1":235.3,"voltage_l2":235.7,"voltage_l3":235.7,"current_l1":0.98,"current_l2":1.47,"current_l3":1.18,"phase_angle_L2_L1":238,"phase_angle_L3_L1":118,"phase_angle_L1":23.0,"phase_angle_L2":108.0,"phase_angle_L3":350.0,"Frequenz":49.9}}}` require.NoError(t, json.Unmarshal([]byte(jsonstr), &res)) assert.Equal(t, float64(-36), *res.StatusSNS.SML.PowerCurr) + assert.Equal(t, float64(2687.3687), *res.StatusSNS.SML.TotalIn) + assert.Equal(t, float64(582.4569), *res.StatusSNS.SML.TotalOut) assert.Equal(t, float64(60), *res.StatusSNS.SML.PowerL1) assert.Equal(t, float64(-111), *res.StatusSNS.SML.PowerL2) assert.Equal(t, float64(14), *res.StatusSNS.SML.PowerL3)