Skip to content

Commit

Permalink
myPV AC Thor: fix power and mode (#18175)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Jan 11, 2025
1 parent 9dcb1fa commit 4cce98c
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions charger/mypv.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,34 @@ import (

// MyPv charger implementation
type MyPv struct {
log *util.Logger
conn *modbus.Connection
power uint32
regPower uint16
log *util.Logger
conn *modbus.Connection
power uint32
statusC uint16
}

const (
elwaRegSetPower = 1000
elwaRegTemp = 1001
elwaRegTempLimit = 1002
elwaRegStatus = 1003
elwaRegPower = 1074
thorRegPower = 1060
elwaRegPower = 1000 // https://github.com/evcc-io/evcc/issues/18020#issuecomment-2585300804
)

func init() {
// https://github.com/evcc-io/evcc/discussions/12761
registry.AddCtx("ac-elwa-2", func(ctx context.Context, other map[string]interface{}) (api.Charger, error) {
return newMyPvFromConfig(ctx, "ac-elwa-2", other, elwaRegPower)
return newMyPvFromConfig(ctx, "ac-elwa-2", other, 2)
})

// https: // github.com/evcc-io/evcc/issues/18020
registry.AddCtx("ac-thor", func(ctx context.Context, other map[string]interface{}) (api.Charger, error) {
return newMyPvFromConfig(ctx, "ac-thor", other, thorRegPower)
return newMyPvFromConfig(ctx, "ac-thor", other, 9)
})
}

// newMyPvFromConfig creates a MyPv charger from generic config
func newMyPvFromConfig(ctx context.Context, name string, other map[string]interface{}, regPower uint16) (api.Charger, error) {
func newMyPvFromConfig(ctx context.Context, name string, other map[string]interface{}, statusC uint16) (api.Charger, error) {
cc := modbus.TcpSettings{
ID: 1,
}
Expand All @@ -68,11 +67,11 @@ func newMyPvFromConfig(ctx context.Context, name string, other map[string]interf
return nil, err
}

return NewMyPv(ctx, name, cc.URI, cc.ID, regPower)
return NewMyPv(ctx, name, cc.URI, cc.ID, statusC)
}

// NewMyPv creates myPV AC Elwa 2 or Thor charger
func NewMyPv(ctx context.Context, name, uri string, slaveID uint8, regPower uint16) (api.Charger, error) {
func NewMyPv(ctx context.Context, name, uri string, slaveID uint8, statusC uint16) (api.Charger, error) {
conn, err := modbus.NewConnection(uri, "", "", 0, modbus.Tcp, slaveID)
if err != nil {
return nil, err
Expand All @@ -86,9 +85,9 @@ func NewMyPv(ctx context.Context, name, uri string, slaveID uint8, regPower uint
conn.Logger(log.TRACE)

wb := &MyPv{
log: log,
conn: conn,
regPower: regPower,
log: log,
conn: conn,
statusC: statusC,
}

go wb.heartbeat(ctx, 30*time.Second)
Expand Down Expand Up @@ -138,7 +137,7 @@ func (wb *MyPv) Status() (api.ChargeStatus, error) {
}

res := api.StatusB
if binary.BigEndian.Uint16(b) == 2 {
if binary.BigEndian.Uint16(b) == wb.statusC {
res = api.StatusC
}

Expand Down Expand Up @@ -196,7 +195,7 @@ var _ api.Meter = (*MyPv)(nil)

// CurrentPower implements the api.Meter interface
func (wb *MyPv) CurrentPower() (float64, error) {
b, err := wb.conn.ReadHoldingRegisters(wb.regPower, 1)
b, err := wb.conn.ReadHoldingRegisters(elwaRegPower, 1)
if err != nil {
return 0, err
}
Expand Down

0 comments on commit 4cce98c

Please sign in to comment.