Skip to content

Commit

Permalink
SofarSolar: add battery control (#10847)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Nov 21, 2023
1 parent bf36704 commit 5f7f4ea
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion provider/transformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func configureInputs(inConfig []transformationConfig) ([]inputTransformation, er
f = func() (any, error) { return ff() }

default:
return nil, fmt.Errorf("%s: Could not find converter for %s", cc.Name, cc.Type)
return nil, fmt.Errorf("%s: invalid type %s", cc.Name, cc.Type)
}

in = append(in, inputTransformation{
Expand Down
41 changes: 32 additions & 9 deletions templates/definition/meter/sofarsolar-g3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ params:
default: 1s
- name: capacity
advanced: true
# battery control
- name: minsoc
type: number
advanced: true
- name: maxsoc
type: number
advanced: true
render: |
type: custom
{{- if eq .usage "grid" }}
Expand Down Expand Up @@ -127,24 +134,40 @@ render: |
type: holding
decode: int16
scale: -10
soc:
energy:
source: modbus
{{- include "modbus" . | indent 2 }}
delay: {{ .delay }}
register:
address: 0x0608 # SOC_Bat1
address: 0x069A # Bat_Discharge_Total
type: holding
decode: uint16
energy:
decode: uint32
scale: 0.1
soc:
source: modbus
{{- include "modbus" . | indent 2 }}
delay: {{ .delay }}
register:
address: 0x069A # Bat_Discharge_Total
address: 0x0608 # SOC_Bat1
type: holding
decode: uint32
scale: 0.1
{{- if .capacity }}
decode: uint16
limitsoc:
source: go
script:
return int(100-limitSoc)
out:
- name: dod
type: int
config:
source: modbus
{{- include "modbus" . | indent 6 }}
delay: {{ .delay }}
register:
address: 0x104C # BatConfig_Current_Discharge_Limit
type: writemultiple
decode: uint16
scale: 100
capacity: {{ .capacity }} # kWh
{{- end }}
minsoc: {{ .minsoc }} # %
maxsoc: {{ .maxsoc }} # %
{{- end }}
2 changes: 1 addition & 1 deletion util/modbus/modbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func RegisterOperation(r Register) (rs485.Operation, error) {
r.Decode = "bool8"
case "writesingle", "writeholding":
op.FuncCode = modbus.FuncCodeWriteSingleRegister
case "writemultiple":
case "writemultiple", "writeholdings":
op.FuncCode = modbus.FuncCodeWriteMultipleRegisters
case "writecoil":
op.FuncCode = modbus.FuncCodeWriteSingleCoil
Expand Down

0 comments on commit 5f7f4ea

Please sign in to comment.