Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Elli chargers #4207

Merged
merged 62 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
1dd518e
Template schema fixes
DerAndereAndi Aug 23, 2022
9cbc9bc
Workarounds for Elli chargers
DerAndereAndi Aug 23, 2022
a15f720
Template updates
DerAndereAndi Aug 23, 2022
723c83a
Update eebus repo reference
DerAndereAndi Aug 23, 2022
4963682
Set site voltage
DerAndereAndi Aug 23, 2022
7fffdab
Minor templates fix
DerAndereAndi Aug 23, 2022
1379b42
Add fixed IP requirement
DerAndereAndi Aug 23, 2022
9796631
Add decorator for proper meter handling
DerAndereAndi Aug 23, 2022
7a63d7c
Fix to lowercase
DerAndereAndi Aug 23, 2022
d328064
Fix crash
DerAndereAndi Aug 24, 2022
c71fc28
Fix charging state logic
DerAndereAndi Aug 24, 2022
2f6fdd6
Merge branch 'master' into feature/elli
DerAndereAndi Aug 24, 2022
d3f93d8
Only set phases if they are wrong
DerAndereAndi Aug 24, 2022
a1374fe
Update isCharging detection and added tests
DerAndereAndi Aug 24, 2022
a0e811b
Add some sanity checks
DerAndereAndi Aug 24, 2022
59e2013
Minor style change
DerAndereAndi Aug 24, 2022
04b7a65
Remove commented dead code
DerAndereAndi Aug 24, 2022
7b499c9
Minor code style fix
DerAndereAndi Aug 24, 2022
44b2c12
Remove set phases
DerAndereAndi Aug 25, 2022
4f3555d
Simplify templates
DerAndereAndi Aug 25, 2022
fc60892
Update eebus and zeroconf
DerAndereAndi Aug 25, 2022
7870923
Support external connected meters
DerAndereAndi Aug 25, 2022
626ccf6
Add meter hint to Connect template
DerAndereAndi Aug 25, 2022
6097f26
Fix for built in meters for isCharging check
DerAndereAndi Aug 26, 2022
c8c56bb
Merge branch 'master' into feature/elli
DerAndereAndi Aug 26, 2022
b1cd510
Fix a crash
DerAndereAndi Aug 26, 2022
d84bf05
Fix detection of charging status with ext meter
DerAndereAndi Aug 28, 2022
ac9ebc0
Update eebus lib
DerAndereAndi Sep 3, 2022
ad5ba0f
Merge branch 'master' into feature/elli
DerAndereAndi Sep 12, 2022
6d21fd4
Change some errors to warnings
DerAndereAndi Sep 12, 2022
0c1d633
Change some warnings to trace
DerAndereAndi Sep 12, 2022
addfc46
Fix comment
DerAndereAndi Sep 12, 2022
18bb799
Merge branch 'master' into feature/elli
DerAndereAndi Sep 12, 2022
01ac753
Add patching of asn1
DerAndereAndi Sep 15, 2022
3b03b2c
Use the dir option of patch
DerAndereAndi Sep 15, 2022
c4d9764
Fix for previous commit
DerAndereAndi Sep 15, 2022
6d00528
Minor template update
DerAndereAndi Sep 15, 2022
93a3c92
Merge branch 'master' into feature/elli
DerAndereAndi Sep 15, 2022
497d3fb
Fix self consumption support action
DerAndereAndi Sep 22, 2022
e2fc87e
Update eebus lib
DerAndereAndi Sep 22, 2022
1ba34ef
Merge branch 'master' into feature/elli
DerAndereAndi Sep 22, 2022
cc9417a
Only check external meters every 10 seconds
DerAndereAndi Sep 22, 2022
ea6e71e
Fix for isCharging check cache
DerAndereAndi Sep 22, 2022
6aaf46c
Fix 10 minutes timeout workaround
DerAndereAndi Sep 24, 2022
7430880
Update eebus lib
DerAndereAndi Sep 26, 2022
3b168b2
Merge branch 'master' into feature/elli
DerAndereAndi Sep 26, 2022
14243cc
Tidy mod
DerAndereAndi Sep 26, 2022
c08d9b4
Merge branch 'master' into feature/elli
DerAndereAndi Sep 28, 2022
2a22346
go mod tidy
DerAndereAndi Sep 28, 2022
cd592c7
Use evcc internal machineID when possible
DerAndereAndi Sep 28, 2022
88f0587
Merge branch 'master' into feature/elli
DerAndereAndi Sep 29, 2022
f979f09
Minor style fixes
DerAndereAndi Sep 29, 2022
e7a609b
Update patching go
DerAndereAndi Sep 29, 2022
79b7e42
Add docker patch
andig Sep 29, 2022
5774c54
Update eebus lib
DerAndereAndi Sep 29, 2022
5c749df
Remove old UniqueID usage
DerAndereAndi Sep 29, 2022
5b33215
Minor error handling improvement
DerAndereAndi Sep 29, 2022
24fc80b
Update eebus lib to master
DerAndereAndi Sep 29, 2022
fc76e9b
Update Elli templates marking them as beta
DerAndereAndi Sep 29, 2022
53066a7
Remove more additional log timestamps
DerAndereAndi Sep 29, 2022
b941e42
Update eebus library
DerAndereAndi Sep 29, 2022
9199dd8
Simplify patch and ignore already-applied error
andig Sep 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions charger/eebus.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,26 @@ func init() {
// NewEEBusFromConfig creates an EEBus charger from generic config
func NewEEBusFromConfig(other map[string]interface{}) (api.Charger, error) {
cc := struct {
Ski string
}{}
Ski string
Ip string
Meter bool
ChargedEnergy bool
}{
Meter: true,
DerAndereAndi marked this conversation as resolved.
Show resolved Hide resolved
ChargedEnergy: true,
}

if err := util.DecodeOther(other, &cc); err != nil {
return nil, err
}

return NewEEBus(cc.Ski)
return NewEEBus(cc.Ski, cc.Ip, cc.Meter, cc.ChargedEnergy)
}

//go:generate go run ../cmd/tools/decorate.go -f decorateEEBus -b *EEBus -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterCurrent,Currents,func() (float64, float64, float64, error)" -t "api.ChargeRater,ChargedEnergy,func() (float64, error)"

// NewEEBus creates EEBus charger
func NewEEBus(ski string) (*EEBus, error) {
func NewEEBus(ski, ip string, hasMeter, hasChargedEnergy bool) (api.Charger, error) {
log := util.NewLogger("eebus")

if server.EEBusInstance == nil {
Expand All @@ -65,7 +73,15 @@ func NewEEBus(ski string) (*EEBus, error) {
communicationStandard: communication.EVCommunicationStandardEnumTypeUnknown,
}

server.EEBusInstance.Register(ski, c.onConnect, c.onDisconnect)
server.EEBusInstance.Register(ski, ip, c.onConnect, c.onDisconnect)

if hasMeter {
if hasChargedEnergy {
return decorateEEBus(c, c.currentPower, c.currents, c.chargedEnergy), nil
} else {
return decorateEEBus(c, c.currentPower, c.currents, nil), nil
}
}

return c, nil
}
Expand All @@ -76,6 +92,7 @@ func (c *EEBus) onConnect(ski string, conn ship.Conn) error {
eebusDevice := app.HEMS(server.EEBusInstance.DeviceInfo())
c.cc = communication.NewConnectionController(c.log.TRACE, conn, eebusDevice)
c.cc.SetDataUpdateHandler(c.dataUpdateHandler)
c.cc.Voltage = 230.0 // TODO value should be provided from site

c.setDefaultValues()
c.setConnected(true)
Expand Down Expand Up @@ -499,10 +516,8 @@ func (c *EEBus) MaxCurrentMillis(current float64) error {
return c.writeCurrentLimitData(currents)
}

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

// CurrentPower implements the api.Meter interface
func (c *EEBus) CurrentPower() (float64, error) {
func (c *EEBus) currentPower() (float64, error) {
data, err := c.cc.GetData()
if err != nil {
return 0, err
Expand All @@ -523,10 +538,8 @@ func (c *EEBus) CurrentPower() (float64, error) {
return power, nil
}

var _ api.ChargeRater = (*EEBus)(nil)

// ChargedEnergy implements the api.ChargeRater interface
func (c *EEBus) ChargedEnergy() (float64, error) {
func (c *EEBus) chargedEnergy() (float64, error) {
data, err := c.cc.GetData()
if err != nil {
return 0, err
Expand Down Expand Up @@ -554,10 +567,8 @@ func (c *EEBus) ChargedEnergy() (float64, error) {
// return 0, nil
// }

var _ api.MeterCurrent = (*EEBus)(nil)

// Currents implements the api.MeterCurrent interface
func (c *EEBus) Currents() (float64, float64, float64, error) {
func (c *EEBus) currents() (float64, float64, float64, error) {
data, err := c.cc.GetData()
if err != nil {
return 0, 0, 0, err
Expand Down
137 changes: 137 additions & 0 deletions charger/eebus_decorators.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/koron/go-ssdp v0.0.3
github.com/korylprince/ipnetgen v1.0.1
github.com/libp2p/zeroconf/v2 v2.0.0-20220623102032-af1f1d3ada85
github.com/libp2p/zeroconf/v2 v2.0.0-20220807195455-586e7c571d10
github.com/lorenzodonini/ocpp-go v0.16.0
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40
github.com/manifoldco/promptui v0.9.0
Expand Down Expand Up @@ -173,3 +173,5 @@ require (
)

replace github.com/foogod/go-powerwall => github.com/andig/go-powerwall v0.2.1-0.20220205120646-e5220ad9a9a0

replace github.com/evcc-io/eebus => github.com/DerAndereAndi/eebus v0.0.0-20220823162657-a23f338f1a3c
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DerAndereAndi/eebus v0.0.0-20220823162657-a23f338f1a3c h1:pBveG/j/cZPGswRfC0P5W3pulIZ+Ca8mEH6+9tnNgbQ=
github.com/DerAndereAndi/eebus v0.0.0-20220823162657-a23f338f1a3c/go.mod h1:1MLJwXaBxVzxtuv/tvrULhBz29g61k1JpXy3zmUPris=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
Expand Down Expand Up @@ -228,8 +230,6 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.m
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/evcc-io/eebus v0.0.0-20220815121332-bbb3cd4260e0 h1:Hy0S1srOZXi/kd9gx5tdu5bFmCuz3GED9KkLvnOlYXU=
github.com/evcc-io/eebus v0.0.0-20220815121332-bbb3cd4260e0/go.mod h1:7TpZYb1fTnptzT5zpq46bU6K2LI3bH+YckOmDtcHXyY=
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
Expand Down Expand Up @@ -591,8 +591,8 @@ github.com/lestrrat-go/iter v1.0.1/go.mod h1:zIdgO1mRKhn8l9vrZJZz9TUMMFbQbLeTsbq
github.com/lestrrat-go/iter v1.0.2/go.mod h1:Momfcq3AnRlRjI5b5O8/G5/BvpzrhoFTZcn06fEOPt4=
github.com/lestrrat-go/jwx v1.2.24/go.mod h1:zoNuZymNl5lgdcu6P7K6ie2QRll5HVfF4xwxBBK1NxY=
github.com/lestrrat-go/option v1.0.0/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
github.com/libp2p/zeroconf/v2 v2.0.0-20220623102032-af1f1d3ada85 h1:jIPip1x91RFdohBowS6pg0lDWoFL8ZqL6ix3NjoCuF4=
github.com/libp2p/zeroconf/v2 v2.0.0-20220623102032-af1f1d3ada85/go.mod h1:fuJqLnUwZTshS3U/bMRJ3+ow/v9oid1n0DmyYyNO1Xs=
github.com/libp2p/zeroconf/v2 v2.0.0-20220807195455-586e7c571d10 h1:mR77t0DBvg8R9PIE9b6by0YaLY/RrX9xDOeua72YAA4=
github.com/libp2p/zeroconf/v2 v2.0.0-20220807195455-586e7c571d10/go.mod h1:fuJqLnUwZTshS3U/bMRJ3+ow/v9oid1n0DmyYyNO1Xs=
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
github.com/lorenzodonini/ocpp-go v0.16.0 h1:+MsMvmZfUi0ac5jXS/Bevn7afM8UNUUiGjMbtwv4SgI=
Expand Down
22 changes: 21 additions & 1 deletion server/eebus.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/x509"
"errors"
"fmt"
"net"
"strings"
"sync"

Expand Down Expand Up @@ -38,6 +39,7 @@ type EEBus struct {
id string
zc *zeroconf.Server
clients map[string]EEBusClientCBs
ipaddress map[string]string
connectedClients map[string]ship.Conn
discoveredClients map[string]*zeroconf.ServiceEntry
clientInConnection map[string]bool
Expand Down Expand Up @@ -108,6 +110,7 @@ func NewEEBus(other map[string]interface{}) (*EEBus, error) {
srv: srv,
id: cc.ShipID,
clients: make(map[string]EEBusClientCBs),
ipaddress: make(map[string]string),
connectedClients: make(map[string]ship.Conn),
discoveredClients: make(map[string]*zeroconf.ServiceEntry),
clientInConnection: make(map[string]bool),
Expand All @@ -120,14 +123,17 @@ func (c *EEBus) DeviceInfo() communication.ManufacturerDetails {
return EEBUSDetails
}

func (c *EEBus) Register(ski string, shipConnectHandler func(string, ship.Conn) error, shipDisconnectHandler func(string)) {
func (c *EEBus) Register(ski, ip string, shipConnectHandler func(string, ship.Conn) error, shipDisconnectHandler func(string)) {
ski = strings.ReplaceAll(ski, "-", "")
ski = strings.ReplaceAll(ski, " ", "")
ski = strings.ToLower(ski)
c.log.TRACE.Printf("registering ski: %s", ski)

c.mux.Lock()
c.clients[ski] = EEBusClientCBs{onConnect: shipConnectHandler, onDisconnect: shipDisconnectHandler}
if ip != "" {
c.ipaddress[ski] = ip
}
c.mux.Unlock()

// maybe the SKI is already discovered
Expand Down Expand Up @@ -200,6 +206,8 @@ func (c *EEBus) addDisoveredEntry(entry *zeroconf.ServiceEntry) {
return
}

c.patchMdnsEntryWithProvidedIP(svc.SKI, entry)

if entry.AddrIPv4 == nil && entry.AddrIPv6 == nil {
c.log.TRACE.Printf("Ignoring discovered mDNS entry as it has no IPv4 and IPv6 address: %s", entry.HostName)
return
Expand Down Expand Up @@ -245,7 +253,19 @@ func (c *EEBus) handleDiscoveredSKI(ski string) error {
return nil
}

// add the IP address from the charger configuration to the mDNS entry if it is missing
func (c *EEBus) patchMdnsEntryWithProvidedIP(ski string, entry *zeroconf.ServiceEntry) {
address, exists := c.ipaddress[ski]
if entry.AddrIPv4 == nil && exists && address != "" {
if ip := net.ParseIP(address); ip != nil {
entry.AddrIPv4 = []net.IP{ip}
}
}
}

func (c *EEBus) connectDiscoveredEntry(ski string, entry *zeroconf.ServiceEntry) error {
c.patchMdnsEntryWithProvidedIP(ski, entry)

svc, err := mdns.NewFromDNSEntry(entry)

var conn ship.Conn
Expand Down
11 changes: 3 additions & 8 deletions templates/definition/charger/eebus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@ products:
de: EEBUS kompatible Wallbox
en: EEBUS compatible Wallbox
group: generic
capabilities: ["iso151182", "mA"]
capabilities: ["mA"]
requirements:
evcc: ["eebus"]
params:
- name: ski
required: true
help:
en: The SKI of the wallbox, can usually be found on the web interface of the wallbox
de: Die SKI der Wallbox, ist üblicherweise im Web Interface der Wallbox zu finden
- preset: eebusmeter
render: |
type: eebus
ski: {{ .ski }}
{{ include "eebus-meter" . }}
18 changes: 18 additions & 0 deletions templates/definition/charger/elli-charger-connect.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
template: elliconnect
products:
- brand: Elli
description:
de: Charger Connect (ohne Meter)
en: Charger Connect (without Meter)
capabilities: ["mA"]
requirements:
evcc: ["eebus"]
description:
de: Dem Gerät muss eine feste IP Adresse zugewiesen sein (Manuell oder per DHCP)
en: The device has to have a fix IP address (manuall or via DHCP)
params:
- preset: eebusnometer
- name: ip
required: true
render: |
{{ include "eebus-no-meter" . }}
Loading