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

EM2GO Home: Workaround for old fw current and phase setting #16201

Merged
merged 26 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
730293d
fix EM2GO Home charger phase and current setting
Jul 29, 2024
6c33a75
fix lint checks
Jul 29, 2024
253be34
Merge branch 'evcc-io:master' into master
dniakamal Jul 29, 2024
733248b
Merge branch 'master' into master
dniakamal Jul 30, 2024
42e31de
Merge branch 'master' into master
dniakamal Jul 31, 2024
3480581
Merge branch 'evcc-io:master' into master
dniakamal Sep 17, 2024
ee2bd70
add check for workaround
Sep 17, 2024
71a4233
Merge branch 'evcc-io:master' into master
dniakamal Sep 17, 2024
2307e96
fix link checks
Sep 17, 2024
6da5766
Merge branch 'master' of github.com:dniakamal/evcc
Sep 17, 2024
a0862e7
Merge branch 'evcc-io:master' into master
dniakamal Sep 18, 2024
e6101a7
Merge branch 'master' into master
dniakamal Sep 18, 2024
036ebd6
Merge branch 'master' into master
dniakamal Sep 19, 2024
2d51e96
Merge branch 'master' into master
dniakamal Sep 20, 2024
d74b0be
Merge branch 'master' into master
dniakamal Sep 23, 2024
e7b8990
Enable mA support when not using workaround
Sep 23, 2024
f15c54a
Revert mA capability for em2go-home template, add description for fw …
Sep 23, 2024
0acbbb6
Fix for Porcelain.
Sep 23, 2024
fe401f1
Merge branch 'master' into master
dniakamal Sep 24, 2024
be7604f
Merge branch 'master' into master
dniakamal Sep 25, 2024
687908d
Merge branch 'master' into master
dniakamal Sep 28, 2024
c257538
Merge branch 'evcc-io:master' into master
dniakamal Sep 30, 2024
1fb1b78
Remove milli parameter
andig Oct 7, 2024
72daf49
Store phases in loadpoint
andig Oct 7, 2024
0aa3d90
Fix lint
andig Oct 7, 2024
04d3961
Reuse buffer
andig Oct 7, 2024
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
84 changes: 68 additions & 16 deletions charger/em2go.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ import (

// Em2Go charger implementation
type Em2Go struct {
log *util.Logger
conn *modbus.Connection
log *util.Logger
conn *modbus.Connection
current int64
workaround bool
phases int
}

const (
Expand All @@ -59,18 +62,14 @@ const (
)

func init() {
registry.Add("em2go", func(other map[string]any) (api.Charger, error) {
return NewEm2GoFromConfig(other, true)
})
registry.Add("em2go-home", func(other map[string]any) (api.Charger, error) {
return NewEm2GoFromConfig(other, false)
})
registry.Add("em2go", NewEm2GoFromConfig)
registry.Add("em2go-home", NewEm2GoFromConfig)
}

//go:generate go run ../cmd/tools/decorate.go -f decorateEm2Go -b *Em2Go -r api.Charger -t "api.ChargerEx,MaxCurrentMillis,func(float64) error" -t "api.PhaseSwitcher,Phases1p3p,func(int) error" -t "api.PhaseGetter,GetPhases,func() (int, error)"

// NewEm2GoFromConfig creates a Em2Go charger from generic config
func NewEm2GoFromConfig(other map[string]interface{}, milli bool) (api.Charger, error) {
func NewEm2GoFromConfig(other map[string]interface{}) (api.Charger, error) {
cc := modbus.TcpSettings{
ID: 255,
}
Expand All @@ -79,11 +78,11 @@ func NewEm2GoFromConfig(other map[string]interface{}, milli bool) (api.Charger,
return nil, err
}

return NewEm2Go(cc.URI, cc.ID, milli)
return NewEm2Go(cc.URI, cc.ID)
}

// NewEm2Go creates Em2Go charger
func NewEm2Go(uri string, slaveID uint8, milli bool) (api.Charger, error) {
func NewEm2Go(uri string, slaveID uint8) (api.Charger, error) {
uri = util.DefaultPort(uri, 502)

conn, err := modbus.NewConnection(uri, "", "", 0, modbus.Tcp, slaveID)
Expand All @@ -98,8 +97,10 @@ func NewEm2Go(uri string, slaveID uint8, milli bool) (api.Charger, error) {
conn.Logger(log.TRACE)

wb := &Em2Go{
log: log,
conn: conn,
log: log,
conn: conn,
current: 6,
workaround: false,
}

var (
Expand All @@ -108,7 +109,20 @@ func NewEm2Go(uri string, slaveID uint8, milli bool) (api.Charger, error) {
phasesG func() (int, error)
)

if milli {
// test if workaround is needed (Home fw <1.3)
if err := wb.maxCurrentMillis(6.1); err != nil {
return nil, err
}

chargerCurrent, err := wb.GetMaxCurrent()
if err != nil {
return nil, err
}

// did rounding occur?
if chargerCurrent == 6 {
wb.workaround = true
} else {
maxCurrent = wb.maxCurrentMillis
}

Expand Down Expand Up @@ -158,8 +172,22 @@ func (wb *Em2Go) Enable(enable bool) error {
b := make([]byte, 2)
binary.BigEndian.PutUint16(b, map[bool]uint16{true: 1, false: 2}[enable])

_, err := wb.conn.WriteMultipleRegisters(em2GoRegChargeCommand, 1, b)
return err
if _, err := wb.conn.WriteMultipleRegisters(em2GoRegChargeCommand, 1, b); err != nil {
return err
}

// re-set 1p if required
if wb.workaround && wb.phases == 1 && enable {
binary.BigEndian.PutUint16(b, uint16(wb.phases))
if _, err := wb.conn.WriteMultipleRegisters(em2GoRegPhases, 1, b); err != nil {
return err
}

// send default current
return wb.MaxCurrent(wb.current)
}

return nil
}

// MaxCurrent implements the api.Charger interface
Expand Down Expand Up @@ -268,10 +296,34 @@ func (wb *Em2Go) ChargeDuration() (time.Duration, error) {

// phases1p3p implements the api.PhaseSwitcher interface
func (wb *Em2Go) phases1p3p(phases int) error {
if wb.workaround {
// when enabled, disable, wait 10 seconds, enable and set phases
enabled, err := wb.Enabled()
if err != nil {
return err
}

if enabled {
if err := wb.Enable(false); err != nil {
return err
}

time.Sleep(10 * time.Second)

if err := wb.Enable(true); err != nil {
return err
}
}
}

b := make([]byte, 2)
binary.BigEndian.PutUint16(b, uint16(phases))

_, err := wb.conn.WriteMultipleRegisters(em2GoRegPhases, 1, b)
if err == nil {
wb.phases = phases
}

return err
}

Expand Down
6 changes: 3 additions & 3 deletions templates/definition/charger/em2go-home.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ products:
- brand: EM2GO
description:
generic: Home
capabilities: ["1p3p"]
capabilities: ["1p3p", "mA"]
requirements:
description:
de: "Benötigt Firmware version E3C_V1.1 oder neuer."
en: "Requires Firmware version E3C_V1.1 or newer."
de: "Benötigt FW version >= E3C_V1.1. mA Regelung benötigt FW version >= E3C_V1.3."
en: "Requires FW Version >= E3C_V1.1. mA regulation requires FW version >= E3C_V1.3."
params:
- name: host
render: |
Expand Down