diff --git a/charger/tasmota.go b/charger/tasmota.go index 47262ee75..37a05fd47 100644 --- a/charger/tasmota.go +++ b/charger/tasmota.go @@ -32,6 +32,7 @@ func NewTasmotaFromConfig(other map[string]interface{}) (api.Charger, error) { URI string User string Password string + Usage string StandbyPower float64 Channel []int Cache time.Duration @@ -44,11 +45,11 @@ func NewTasmotaFromConfig(other map[string]interface{}) (api.Charger, error) { return nil, err } - return NewTasmota(cc.embed, cc.URI, cc.User, cc.Password, cc.Channel, cc.StandbyPower, cc.Cache) + return NewTasmota(cc.embed, cc.URI, cc.User, cc.Password, cc.Usage, cc.Channel, cc.StandbyPower, cc.Cache) } // NewTasmota creates Tasmota charger -func NewTasmota(embed embed, uri, user, password string, channels []int, standbypower float64, cache time.Duration) (api.Charger, error) { +func NewTasmota(embed embed, uri, user, password, usage string, channels []int, standbypower float64, cache time.Duration) (api.Charger, error) { conn, err := tasmota.NewConnection(uri, user, password, channels, cache) if err != nil { return nil, err diff --git a/meter/tasmota.go b/meter/tasmota.go index acb1578cc..04a69807b 100644 --- a/meter/tasmota.go +++ b/meter/tasmota.go @@ -1,6 +1,7 @@ package meter import ( + "math" "strings" "time" @@ -23,7 +24,7 @@ func init() { //go:generate go tool decorate -f decorateTasmota -b *Tasmota -r api.Meter -t "api.PhaseVoltages,Voltages,func() (float64, float64, float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" // NewTasmotaFromConfig creates a Tasmota meter from generic config -func NewTasmotaFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewTasmotaFromConfig(other map[string]any) (api.Meter, error) { cc := struct { URI string User string @@ -68,19 +69,21 @@ var _ api.Meter = (*Tasmota)(nil) // CurrentPower implements the api.Meter interface func (c *Tasmota) CurrentPower() (float64, error) { - if c.usage == "grid" { - return c.conn.SmlPower() + power, err := c.conn.CurrentPower() + if err != nil { + return 0, err } - return c.conn.CurrentPower() + // positive power for pv usage + if c.usage == "pv" { + return math.Abs(power), nil + } + return power, nil } var _ api.MeterEnergy = (*Tasmota)(nil) // TotalEnergy implements the api.MeterEnergy interface func (c *Tasmota) TotalEnergy() (float64, error) { - if c.usage == "grid" { - return c.conn.SmlTotalEnergy() - } return c.conn.TotalEnergy() } diff --git a/meter/tasmota/connection.go b/meter/tasmota/connection.go index 4986a4dee..078aaecdd 100644 --- a/meter/tasmota/connection.go +++ b/meter/tasmota/connection.go @@ -208,13 +208,13 @@ func (c *Connection) CurrentPower() (float64, error) { } res += power } - return res, nil + return res + float64(s.StatusSNS.SML.PowerCurr), nil } // TotalEnergy implements the api.MeterEnergy interface func (c *Connection) TotalEnergy() (float64, error) { res, err := c.statusSnsG.Get() - return res.StatusSNS.Energy.Total, err + return res.StatusSNS.Energy.Total + res.StatusSNS.SML.TotalOut, err } // Currents implements the api.PhaseCurrents interface @@ -250,15 +250,3 @@ func (c *Connection) getPhaseValues(fun func(StatusSNSResponse) Channels) (float return res[0], res[1], res[2], nil } - -// SmlPower provides the sml sensor power -func (c *Connection) SmlPower() (float64, error) { - res, err := c.statusSnsG.Get() - return float64(res.StatusSNS.SML.PowerCurr), err -} - -// SmlTotalEnergy provides the sml sensor total import energy -func (c *Connection) SmlTotalEnergy() (float64, error) { - res, err := c.statusSnsG.Get() - return res.StatusSNS.SML.TotalIn, err -} diff --git a/templates/definition/meter/tasmota-sml.yaml b/templates/definition/meter/tasmota-sml.yaml index 1ff9a4bb9..73a09abfa 100644 --- a/templates/definition/meter/tasmota-sml.yaml +++ b/templates/definition/meter/tasmota-sml.yaml @@ -56,7 +56,7 @@ requirements: ``` params: - name: usage - choice: ["grid"] + choice: ["grid", "pv", "battery", "charge"] - name: host - name: user required: false diff --git a/templates/definition/meter/tasmota.yaml b/templates/definition/meter/tasmota.yaml index fd71e6ee9..792c79168 100644 --- a/templates/definition/meter/tasmota.yaml +++ b/templates/definition/meter/tasmota.yaml @@ -1,11 +1,12 @@ template: tasmota products: - - description: - generic: Tasmota (1 Phase Meter) + - brand: Tasmota + description: + generic: Tasmota (1 Phase + SML Meter) group: switchsockets params: - name: usage - choice: ["pv", "battery", "charge"] + choice: ["grid", "pv", "battery", "charge"] - name: host - name: user required: false