Skip to content

Commit

Permalink
HardyBarth: add measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Mar 15, 2022
1 parent e6b3162 commit a610ce8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 24 deletions.
58 changes: 34 additions & 24 deletions charger/hardybarth.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/charger/echarge"
"github.com/evcc-io/evcc/charger/obis"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request"
)
Expand Down Expand Up @@ -89,11 +90,11 @@ func NewHardyBarth(uri string, chargecontrol, meter int) (api.Charger, error) {
func (wb *HardyBarth) getChargeControl() (echarge.ChargeControl, error) {
uri := fmt.Sprintf("%s/api/v1/chargecontrols/%d", wb.uri, wb.chargecontrol)

res := struct {
var res struct {
ChargeControl struct {
echarge.ChargeControl
}
}{}
}

err := wb.GetJSON(uri, &res)

Expand Down Expand Up @@ -162,46 +163,55 @@ func (wb *HardyBarth) MaxCurrent(current int64) error {
return err
}

var _ api.Meter = (*HardyBarth)(nil)

// CurrentPower implements the api.Meter interface
func (wb *HardyBarth) CurrentPower() (float64, error) {
func (wb *HardyBarth) getMeter() (echarge.Meter, error) {
uri := fmt.Sprintf("%s/api/v1/meters/%d", wb.uri, wb.meter)

res := struct {
var res struct {
Meter struct {
echarge.Meter
}
}{}
}

err := wb.GetJSON(uri, &res)

return res.Meter.Meter, err
}

var _ api.Meter = (*HardyBarth)(nil)

// CurrentPower implements the api.Meter interface
func (wb *HardyBarth) CurrentPower() (float64, error) {
res, err := wb.getMeter()
if err != nil {
return 0, err
}

return res.Meter.Meter.Data["1-0:1.4.0"], nil
return res.Data[obis.PowerConsumption], nil
}

// var _ api.ChargeRater = (*HardyBarth)(nil)
var _ api.MeterEnergy = (*HardyBarth)(nil)

// // ChargedEnergy implements the api.ChargeRater interface
// func (wb *HardyBarth) ChargedEnergy() (float64, error) {
// return 0, api.ErrNotAvailable
// }
// TotalEnergy implements the api.MeterEnergy interface
func (wb *HardyBarth) TotalEnergy() (float64, error) {
res, err := wb.getMeter()
if err != nil {
return 0, err
}

// var _ api.MeterCurrent = (*HardyBarth)(nil)
return res.Data[obis.EnergyConsumption], nil
}

// // Currents implements the api.MeterCurrent interface
// func (wb *HardyBarth) Currents() (float64, float64, float64, error) {
// return 0, 0, 0, api.ErrNotAvailable
// }
var _ api.MeterCurrent = (*HardyBarth)(nil)

// var _ api.MeterEnergy = (*HardyBarth)(nil)
// Currents implements the api.MeterCurrent interface
func (wb *HardyBarth) Currents() (float64, float64, float64, error) {
res, err := wb.getMeter()
if err != nil {
return 0, 0, 0, err
}

// // TotalEnergy implements the api.MeterEnergy interface - v2 only
// func (wb *HardyBarth) TotalEnergy() (float64, error) {
// return 0, api.ErrNotAvailable
// }
return res.Data[obis.CurrentL1], res.Data[obis.CurrentL2], res.Data[obis.CurrentL3], nil
}

// var _ api.Identifier = (*HardyBarth)(nil)

Expand Down
22 changes: 22 additions & 0 deletions charger/obis/obis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package obis

// https://www.kbr.de/de/obis-kennzeichen/elektrizitaet

const (
PowerConsumption = "1-0:1.4.0"
EnergyConsumption = "1-0:1.8.0"
PowerFeedIn = "1-0:2.4.0"
EnergyFeedIn = "1-0:2.8.0"

PowerConsumptionL1 = "1-0:21.4.0"
EnergyConsumptionL1 = "1-0:21.8.0"
CurrentL1 = "1-0:31.4.0"

PowerConsumptionL2 = "1-0:41.4.0"
EnergyConsumptionL2 = "1-0:41.8.0"
CurrentL2 = "1-0:51.4.0"

PowerConsumptionL3 = "1-0:61.4.0"
EnergyConsumptionL3 = "1-0:61.8.0"
CurrentL3 = "1-0:71.4.0"
)

0 comments on commit a610ce8

Please sign in to comment.