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 V1.1 current and phase setting #15131

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
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
69 changes: 61 additions & 8 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,10 @@ import (

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

const (
Expand Down Expand Up @@ -98,8 +101,9 @@ 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, // assume min current
}

var (
Expand Down Expand Up @@ -158,8 +162,30 @@ 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 get phases set in evcc and send to charger
var phases int
if wb.lp != nil {
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
}

//Workaround send default current to charger
var current int64
current = wb.current
wb.MaxCurrent(current)

return nil
}

// MaxCurrent implements the api.Charger interface
Expand Down Expand Up @@ -271,8 +297,28 @@ 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 when enabled, stop charging 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 {
return err
}
}

return nil
}

// getPhases implements the api.PhaseGetter interface
Expand Down Expand Up @@ -332,3 +378,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
}