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 18 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
104 changes: 88 additions & 16 deletions charger/em2go.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/core/loadpoint"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/modbus"
"github.com/volkszaehler/mbmd/meters/rs485"
Expand All @@ -32,8 +33,11 @@ import (

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

const (
Expand Down Expand Up @@ -63,7 +67,7 @@ func init() {
return NewEm2GoFromConfig(other, true)
})
registry.Add("em2go-home", func(other map[string]any) (api.Charger, error) {
return NewEm2GoFromConfig(other, false)
return NewEm2GoFromConfig(other, true)
})
}

Expand Down Expand Up @@ -98,25 +102,39 @@ 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 (
maxCurrent func(float64) error
phases1p3p func(int) error
phasesG func() (int, error)
maxCurrent func(float64) error
phases1p3p func(int) error
phasesG func() (int, error)
chargerCurrent float64
)

if milli {
maxCurrent = wb.maxCurrentMillis
}

if _, err := wb.conn.ReadHoldingRegisters(em2GoRegPhases, 1); err == nil {
phases1p3p = wb.phases1p3p
phasesG = wb.getPhases
}

// Test if workaround is needed (Home fw <1.3)
if wb.maxCurrentMillis(6.1) != nil {
return nil, err
}
chargerCurrent, err = wb.GetMaxCurrent()

if chargerCurrent == 6 {
wb.workaround = true
} else {
wb.workaround = false
if milli {
andig marked this conversation as resolved.
Show resolved Hide resolved
maxCurrent = wb.maxCurrentMillis
}
}

return decorateEm2Go(wb, maxCurrent, phases1p3p, phasesG), err
}

Expand Down Expand Up @@ -158,8 +176,32 @@ 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
}

// Workaround
if wb.workaround {
andig marked this conversation as resolved.
Show resolved Hide resolved
//Get wanted phases set in lp and send to charger
var phases int
if wb.lp != nil {
andig marked this conversation as resolved.
Show resolved Hide resolved
phases = wb.lp.GetPhases()
}
if phases == 0 {
phases = 3
}
c := make([]byte, 2)
binary.BigEndian.PutUint16(c, uint16(phases))
if _, err := wb.conn.WriteMultipleRegisters(em2GoRegPhases, 1, c); err != nil {
return err
}

//Send default current to charger
var current int64
current = wb.current
wb.MaxCurrent(current)
andig marked this conversation as resolved.
Show resolved Hide resolved
}
return nil
}

// MaxCurrent implements the api.Charger interface
Expand Down Expand Up @@ -271,8 +313,31 @@ func (wb *Em2Go) phases1p3p(phases int) error {
b := make([]byte, 2)
binary.BigEndian.PutUint16(b, uint16(phases))

_, err := wb.conn.WriteMultipleRegisters(em2GoRegPhases, 1, b)
return err
//Workaround
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
}
}
}

if _, err := wb.conn.WriteMultipleRegisters(em2GoRegPhases, 1, b); err != nil {
andig marked this conversation as resolved.
Show resolved Hide resolved
return err
}

return nil
}

// getPhases implements the api.PhaseGetter interface
Expand Down Expand Up @@ -332,3 +397,10 @@ func (wb *Em2Go) Diagnose() {
fmt.Printf("\tCharge Command:\t%d\n", binary.BigEndian.Uint16(b))
}
}

var _ loadpoint.Controller = (*Em2Go)(nil)

// LoadpointControl implements loadpoint.Controller
func (wb *Em2Go) LoadpointControl(lp loadpoint.API) {
wb.lp = lp
}
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