TasmotaSML: add returnEnergy (#30599)

This commit is contained in:
Lars Gellrich 2026-06-10 11:49:40 +02:00 • committed by GitHub
parent ca2f32876d
commit 23bab534e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 3 deletions

View file

@ -71,6 +71,10 @@ func NewTasmota(uri, user, password, usage string, channels []int, cache time.Du
implement.Has(c, implement.PhasePowers(c.powers)) implement.Has(c, implement.PhasePowers(c.powers))
} }
if _, err := c.conn.ReturnEnergy(); err == nil {
implement.Has(c, implement.MeterReturnEnergy(c.returnEnergy))
}
return c, nil return c, nil
} }
@ -96,6 +100,11 @@ func (c *Tasmota) TotalEnergy() (float64, error) {
return c.conn.TotalEnergy() 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 // powers implements the api.PhasePowers interface
func (c *Tasmota) powers() (float64, float64, float64, error) { func (c *Tasmota) powers() (float64, float64, float64, error) {
return c.conn.Powers() return c.conn.Powers()

View file

@ -7,6 +7,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request" "github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/transport" "github.com/evcc-io/evcc/util/transport"
@ -229,12 +230,27 @@ func (c *Connection) TotalEnergy() (float64, error) {
return 0, err return 0, err
} }
// SML total energy available // SML import energy available
if sml := res.StatusSNS.SML.TotalIn; sml != nil { 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 // Powers implements the api.PhasePowers interface

View file

@ -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"}}` 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)) require.NoError(t, json.Unmarshal([]byte(jsonstr), &res))
assert.Equal(t, float64(-894), *res.StatusSNS.SML.PowerCurr) 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 // 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}}}` 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)) require.NoError(t, json.Unmarshal([]byte(jsonstr), &res))
assert.Equal(t, float64(-36), *res.StatusSNS.SML.PowerCurr) 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(60), *res.StatusSNS.SML.PowerL1)
assert.Equal(t, float64(-111), *res.StatusSNS.SML.PowerL2) assert.Equal(t, float64(-111), *res.StatusSNS.SML.PowerL2)
assert.Equal(t, float64(14), *res.StatusSNS.SML.PowerL3) assert.Equal(t, float64(14), *res.StatusSNS.SML.PowerL3)