Skip to content

Commit

Permalink
Amperified Solar: add 1p3p (#12051)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Feb 4, 2024
1 parent bdeac02 commit 113ba95
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 16 deletions.
54 changes: 38 additions & 16 deletions charger/amperfied.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,46 @@ type Amperfied struct {
}

const (
ampRegChargingState = 5 // Input
ampRegCurrents = 6 // Input 6,7,8
ampRegTemperature = 9 // Input
ampRegVoltages = 10 // Input 10,11,12
ampRegPower = 14 // Input
ampRegEnergy = 17 // Input
ampRegTimeoutConfig = 257 // Holding
ampRegRemoteLock = 259 // Holding
ampRegAmpsConfig = 261 // Holding
ampRegFailSafeConfig = 262 // Holding
ampRegRfidUID = 2002 // Input
ampRegChargingState = 5 // Input
ampRegCurrents = 6 // Input 6,7,8
ampRegTemperature = 9 // Input
ampRegVoltages = 10 // Input 10,11,12
ampRegPower = 14 // Input
ampRegEnergy = 17 // Input
ampRegTimeoutConfig = 257 // Holding
ampRegRemoteLock = 259 // Holding
ampRegAmpsConfig = 261 // Holding
ampRegFailSafeConfig = 262 // Holding
ampRegPhaseSwitchControl = 501 // Holding
ampRegRfidUID = 2002 // Input
)

func init() {
registry.Add("amperfied", NewAmperfiedFromConfig)
}

//go:generate go run ../cmd/tools/decorate.go -f decorateAmperfied -b *Amperfied -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error"

// NewAmperfiedFromConfig creates a Amperfied charger from generic config
func NewAmperfiedFromConfig(other map[string]interface{}) (api.Charger, error) {
cc := modbus.TcpSettings{
ID: 255,
cc := struct {
modbus.TcpSettings
Phases1p3p bool
}{
TcpSettings: modbus.TcpSettings{
ID: 255,
},
}

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

return NewAmperfied(cc.URI, cc.ID)
return NewAmperfied(cc.URI, cc.ID, cc.Phases1p3p)
}

// NewAmperfied creates Amperfied charger
func NewAmperfied(uri string, slaveID uint8) (api.Charger, error) {
func NewAmperfied(uri string, slaveID uint8, phases bool) (api.Charger, error) {
conn, err := modbus.NewConnection(uri, "", "", 0, modbus.Tcp, slaveID)
if err != nil {
return nil, err
Expand Down Expand Up @@ -97,7 +105,12 @@ func NewAmperfied(uri string, slaveID uint8) (api.Charger, error) {
go wb.heartbeat(time.Duration(u) * time.Millisecond / 2)
}

return wb, nil
var phases1p3p func(int) error
if phases {
phases1p3p = wb.phases1p3p
}

return decorateAmperfied(wb, phases1p3p), nil
}

func (wb *Amperfied) heartbeat(timeout time.Duration) {
Expand Down Expand Up @@ -321,3 +334,12 @@ func (wb *Amperfied) WakeUp() error {
// return to normal operation by unlocking after ~10 sec
return wb.set(ampRegRemoteLock, 1)
}

// phases1p3p implements the api.PhaseSwitcher interface
func (wb *Amperfied) phases1p3p(phases int) error {
b := make([]byte, 2)
binary.BigEndian.PutUint16(b, uint16(phases))

_, err := wb.conn.WriteMultipleRegisters(ampRegPhaseSwitchControl, 1, b)
return err
}
35 changes: 35 additions & 0 deletions charger/amperfied_decorators.go

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

16 changes: 16 additions & 0 deletions templates/definition/charger/amperfied-solar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
template: amperfied-solar
products:
- brand: Amperfied
description:
generic: Wallbox connect.solar
capabilities: ["mA", "rfid", "1p3p"]
requirements:
evcc: ["sponsorship"]
params:
- name: modbus
choice: ["tcpip"]
id: 255
render: |
type: amperfied
{{- include "modbus" . }}
phases1p3p: true

3 comments on commit 113ba95

@maatinh
Copy link
Contributor

@maatinh maatinh commented on 113ba95 Feb 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hallo @andig

evcc startet für mich jetzt nicht mehr. Weder mit template: amperfied noch mit template: amperfied-solar.

[main  ] INFO 2024/02/05 08:49:14 evcc 0.124.0 (113ba953)
[main  ] INFO 2024/02/05 08:49:14 using config file: /etc/evcc.yaml
[main  ] INFO 2024/02/05 08:49:14 starting ui and api at :7070
[proxy-5200] DEBUG 2024/02/05 08:49:14 modbus proxy for 192.168.XX.XX:502 listening at :5200
[main  ] FATAL 2024/02/05 08:49:14 cannot create charger 'connect.solar': cannot create charger type 'template': cannot create charger type 'amperfied': 1 error(s) decoding:

* '' has invalid keys: id, rtu, uri
[...]
# charger definitions
# name can be freely chosen and is used as reference when assigning charger to vehicle
# for documentation see https://docs.evcc.io/docs/devices/chargers
chargers:
  - name: NRGKick
    type: template
    template: nrgkick-connect
    host: 192.168.XX.XX
    mac: XXXXXXX
    password: 'XXXX'
  - name: connect.solar
    type: template
    template: amperfied
    modbus: tcpip
    id: 255
    host: 192.168.XX.XX
    port: 502

# vehicle definitions
# name can be freely chosen and is used as reference when assigning vehicle to loadpoint
# for documentation see https://docs.evcc.io/docs/devices/vehicles
vehicles:
  - name: Zoe
    title: Zoe-PV-Laden
    type: template
    phases: 1
    template: renault
    capacity: 25 # kWh
    user: XXX
    password: XXX
    # vin: XXX
    mode: pv # enable PV-charging when vehicle is identified
    minCurrent: 8
    #targetSoc: 85 # limit charge to 90%

[...]

@andig
Copy link
Member Author

@andig andig commented on 113ba95 Feb 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Danke für den Hinweis, ist im master behoben

@maatinh
Copy link
Contributor

@maatinh maatinh commented on 113ba95 Feb 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kannst du den nightly dafür manuell anstoßen damit ich das direkt testen kann?

Please sign in to comment.