Tasmota: enable more usages for SML (#19072)
This commit is contained in:
parent
8f9c43cc8a
commit
a964688704
5 changed files with 20 additions and 27 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ requirements:
|
|||
```
|
||||
params:
|
||||
- name: usage
|
||||
choice: ["grid"]
|
||||
choice: ["grid", "pv", "battery", "charge"]
|
||||
- name: host
|
||||
- name: user
|
||||
required: false
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue