Meter (Home Assistant): support return energy entity (#31857)
This commit is contained in:
parent
3a3d7ad36b
commit
ba279718d2
2 changed files with 49 additions and 31 deletions
|
|
@ -21,6 +21,7 @@ func NewHomeAssistantFromConfig(other map[string]any) (api.Meter, error) {
|
||||||
homeassistant.Config `mapstructure:",squash"`
|
homeassistant.Config `mapstructure:",squash"`
|
||||||
Power string
|
Power string
|
||||||
Energy string
|
Energy string
|
||||||
|
ReturnEnergy string
|
||||||
Currents []string
|
Currents []string
|
||||||
Voltages []string
|
Voltages []string
|
||||||
Powers []string
|
Powers []string
|
||||||
|
|
@ -64,37 +65,19 @@ func NewHomeAssistantFromConfig(other map[string]any) (api.Meter, error) {
|
||||||
return conn.GetFloatState(cc.Power)
|
return conn.GetFloatState(cc.Power)
|
||||||
})
|
})
|
||||||
|
|
||||||
// decorators for optional interfaces
|
// energy
|
||||||
var energyG func() (float64, error)
|
|
||||||
var currentsG, voltagesG, powersG func() (float64, float64, float64, error)
|
|
||||||
|
|
||||||
if cc.Energy != "" {
|
if cc.Energy != "" {
|
||||||
energyG = func() (float64, error) { return conn.GetFloatState(cc.Energy) }
|
implement.Has(m, implement.MeterEnergy(func() (float64, error) {
|
||||||
|
return conn.GetFloatState(cc.Energy)
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// phase currents (optional)
|
if cc.ReturnEnergy != "" {
|
||||||
if phases, err := homeassistant.ValidatePhaseEntities(cc.Currents); err != nil {
|
implement.Has(m, implement.MeterReturnEnergy(func() (float64, error) {
|
||||||
return nil, fmt.Errorf("currents: %w", err)
|
return conn.GetFloatState(cc.ReturnEnergy)
|
||||||
} else if len(phases) > 0 {
|
}))
|
||||||
currentsG = func() (float64, float64, float64, error) { return conn.GetPhaseFloatStates(phases) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// phase voltages (optional)
|
|
||||||
if phases, err := homeassistant.ValidatePhaseEntities(cc.Voltages); err != nil {
|
|
||||||
return nil, fmt.Errorf("voltages: %w", err)
|
|
||||||
} else if len(phases) > 0 {
|
|
||||||
voltagesG = func() (float64, float64, float64, error) { return conn.GetPhaseFloatStates(phases) }
|
|
||||||
}
|
|
||||||
|
|
||||||
// phase powers (optional)
|
|
||||||
if phases, err := homeassistant.ValidatePhaseEntities(cc.Powers); err != nil {
|
|
||||||
return nil, fmt.Errorf("powers: %w", err)
|
|
||||||
} else if len(phases) > 0 {
|
|
||||||
powersG = func() (float64, float64, float64, error) { return conn.GetPhaseFloatStates(phases) }
|
|
||||||
}
|
|
||||||
|
|
||||||
implement.May(m, implement.MeterEnergy(energyG))
|
|
||||||
|
|
||||||
if cc.Soc != "" {
|
if cc.Soc != "" {
|
||||||
socG := func() (float64, error) { return conn.GetFloatState(cc.Soc) }
|
socG := func() (float64, error) { return conn.GetFloatState(cc.Soc) }
|
||||||
|
|
||||||
|
|
@ -125,9 +108,33 @@ func NewHomeAssistantFromConfig(other map[string]any) (api.Meter, error) {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
implement.May(m, implement.PhaseCurrents(currentsG))
|
// phase currents (optional)
|
||||||
implement.May(m, implement.PhaseVoltages(voltagesG))
|
if phases, err := homeassistant.ValidatePhaseEntities(cc.Currents); err != nil {
|
||||||
implement.May(m, implement.PhasePowers(powersG))
|
return nil, fmt.Errorf("currents: %w", err)
|
||||||
|
} else if len(phases) > 0 {
|
||||||
|
implement.Has(m, implement.PhaseCurrents(func() (float64, float64, float64, error) {
|
||||||
|
return conn.GetPhaseFloatStates(phases)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// phase voltages (optional)
|
||||||
|
if phases, err := homeassistant.ValidatePhaseEntities(cc.Voltages); err != nil {
|
||||||
|
return nil, fmt.Errorf("voltages: %w", err)
|
||||||
|
} else if len(phases) > 0 {
|
||||||
|
implement.Has(m, implement.PhaseVoltages(func() (float64, float64, float64, error) {
|
||||||
|
return conn.GetPhaseFloatStates(phases)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// phase powers (optional)
|
||||||
|
if phases, err := homeassistant.ValidatePhaseEntities(cc.Powers); err != nil {
|
||||||
|
return nil, fmt.Errorf("powers: %w", err)
|
||||||
|
} else if len(phases) > 0 {
|
||||||
|
implement.Has(m, implement.PhasePowers(func() (float64, float64, float64, error) {
|
||||||
|
return conn.GetPhaseFloatStates(phases)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
implement.May(m, implement.MaxACPowerGetter(cc.pvMaxACPower.Decorator()))
|
implement.May(m, implement.MaxACPowerGetter(cc.pvMaxACPower.Decorator()))
|
||||||
|
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,18 @@ params:
|
||||||
example: "sensor.house_energy"
|
example: "sensor.house_energy"
|
||||||
advanced: true
|
advanced: true
|
||||||
help:
|
help:
|
||||||
en: Entity ID for cumulative energy measurement in kWh. Should provide total energy consumed/produced, not daily or interval values.
|
en: Entity ID for total energy in kWh (e.g. grid import or battery charging). No daily or interval values.
|
||||||
de: Entitäts-ID für kumulative Energiemessung in kWh. Sollte die gesamte verbrauchte/produzierte Energie liefern, nicht tägliche oder Intervallwerte.
|
de: Entitäts-ID für Gesamtenergie in kWh (z.B. Netzbezug oder Batterieladung). Keine täglichen oder Intervallwerte.
|
||||||
|
- name: returnEnergy
|
||||||
|
description:
|
||||||
|
de: Energieentität (Gegenrichtung)
|
||||||
|
en: Return Energy Entity
|
||||||
|
service: homeassistant/entities?uri={uri}&insecure={insecure}&domain=sensor
|
||||||
|
example: "sensor.house_return_energy"
|
||||||
|
advanced: true
|
||||||
|
help:
|
||||||
|
en: Entity ID for total energy in reverse direction in kWh (e.g. grid export or battery discharging). No daily or interval values.
|
||||||
|
de: Entitäts-ID für Gesamtenergie in Gegenrichtung in kWh (z.B. Netzeinspeisung oder Batterieentladung). Keine täglichen oder Intervallwerte.
|
||||||
- name: currentL1
|
- name: currentL1
|
||||||
description:
|
description:
|
||||||
de: L1 Stromentität
|
de: L1 Stromentität
|
||||||
|
|
@ -160,6 +170,7 @@ render: |
|
||||||
insecure: {{ .insecure }}
|
insecure: {{ .insecure }}
|
||||||
power: {{ .power }}
|
power: {{ .power }}
|
||||||
energy: {{ .energy }}
|
energy: {{ .energy }}
|
||||||
|
returnenergy: {{ .returnEnergy }}
|
||||||
currents:
|
currents:
|
||||||
- {{ .currentL1 }}
|
- {{ .currentL1 }}
|
||||||
- {{ .currentL2 }}
|
- {{ .currentL2 }}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue