From 3ba0c8d171e1ca449a1ddf0d9460d37d3cd473a8 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 7 Jan 2024 10:10:33 +0100 Subject: [PATCH] SMA: add battery control (#11368) --- .../definition/meter/sma-datamanager.yaml | 3 +- .../definition/meter/sma-homemanager.yaml | 5 +- templates/definition/meter/sma-hybrid.yaml | 151 ++++++++++++++---- .../definition/meter/sma-inverter-modbus.yaml | 97 +++++++++++ ...erter.yaml => sma-inverter-speedwire.yaml} | 7 +- 5 files changed, 229 insertions(+), 34 deletions(-) create mode 100644 templates/definition/meter/sma-inverter-modbus.yaml rename templates/definition/meter/{sma-inverter.yaml => sma-inverter-speedwire.yaml} (79%) diff --git a/templates/definition/meter/sma-datamanager.yaml b/templates/definition/meter/sma-datamanager.yaml index c8fd7da3d..205a0fdca 100644 --- a/templates/definition/meter/sma-datamanager.yaml +++ b/templates/definition/meter/sma-datamanager.yaml @@ -1,6 +1,5 @@ template: sma-data-manager -covers: - - sma-data-manager-m-lite +covers: ["sma-data-manager-m-lite"] products: - brand: SMA description: diff --git a/templates/definition/meter/sma-homemanager.yaml b/templates/definition/meter/sma-homemanager.yaml index 5a3d168fa..1b8dc4ace 100644 --- a/templates/definition/meter/sma-homemanager.yaml +++ b/templates/definition/meter/sma-homemanager.yaml @@ -18,7 +18,10 @@ linked: - template: sma-hybrid usage: battery multiple: true - - template: sma-inverter + - template: sma-inverter-speedwire + usage: battery + multiple: true + - template: sma-inverter-modbus usage: battery multiple: true params: diff --git a/templates/definition/meter/sma-hybrid.yaml b/templates/definition/meter/sma-hybrid.yaml index c0f153cff..23a83021a 100644 --- a/templates/definition/meter/sma-hybrid.yaml +++ b/templates/definition/meter/sma-hybrid.yaml @@ -4,6 +4,7 @@ products: description: de: Smart Energy Hybrid-Wechselrichter en: Smart Energy Hybrid Inverter +capabilities: ["battery-control"] params: - name: usage choice: ["pv", "battery"] @@ -17,50 +18,144 @@ params: de: Der Modbus TCP-Server muss an diesem Smart Energy Wechselrichter aktiviert sein - name: capacity advanced: true + - name: watchdog + type: duration + default: 60s + advanced: true render: | type: custom - power: {{- if eq .usage "pv" }} + power: + source: modbus + {{- include "modbus" . | indent 2 }} + register: + address: 30773 # SMA Modbus Profile: DcMs.Watt + type: input + decode: int32nan + energy: + source: modbus + {{- include "modbus" . | indent 2 }} + register: + address: 30513 # SMA Modbus Profile: Metering.TotWhOut + type: holding + decode: uint64nan + scale: 0.001 + {{- end }} + {{- if eq .usage "battery" }} + power: source: calc add: - source: modbus {{- include "modbus" . | indent 6 }} - register: # manual non-sunspec register configuration - address: 30773 # SMA Modbus Profile: DC power input [1] - type: holding - decode: int32nan - - source: modbus - {{- include "modbus" . | indent 6 }} - register: # manual non-sunspec register configuration - address: 30961 # SMA Modbus Profile: DC power input [2] - type: holding - decode: int32nan - {{- end }} - {{- if eq .usage "battery" }} - source: calc - mul: - - source: modbus - {{- include "modbus" . | indent 6 }} - register: # manual non-sunspec register configuration - address: 30851 # SMA Modbus Profile: Battery voltage - type: holding + register: + address: 31395 # SMA Modbus Profile: BatDsch.CurBatDsch + type: input decode: uint32nan - scale: 0.01 - source: modbus {{- include "modbus" . | indent 6 }} - register: # manual non-sunspec register configuration - address: 30843 # SMA Modbus Profile: Battery current - type: holding - decode: int32nan - scale: 0.001 + register: + address: 31393 # SMA Modbus Profile: BatChrg.CurBatCha + type: input + decode: uint32nan + scale: -1 + energy: + source: modbus + {{- include "modbus" . | indent 2 }} + register: + address: 31401 # SMA Modbus Profile: CmpBMS.GetBatDschWh + type: holding + decode: uint64nan + scale: 0.001 soc: source: modbus {{- include "modbus" . | indent 2 }} - register: # manual non-sunspec register configuration - address: 30845 # SMA Modbus Profile: Battery state of charge + register: + address: 30845 # SMA Modbus Profile: Bat.ChaStt type: holding decode: uint32nan + batterymode: + source: watchdog + timeout: {{ .watchdog }} # re-write at timeout/2 + reset: 1 # reset watchdog on normal + set: + source: switch + switch: + - case: 1 # normal + set: + source: const + value: 10000 # Maximale Wirkleistung + set: + source: modbus + {{- include "modbus" . | indent 10 }} + timeout: {{ .timeout }} + register: + address: 44039 # SMA Modbus Profile: Inverter.WModCfg.WCtlComCfg.WSptMaxNom + type: writemultiple + decode: int32 + - case: 2 # hold + set: + source: const + value: 0 # Maximale Wirkleistung + set: + source: modbus + {{- include "modbus" . | indent 10 }} + timeout: {{ .timeout }} + register: + address: 44039 # SMA Modbus Profile: Inverter.WModCfg.WCtlComCfg.WSptMaxNom + type: writemultiple + decode: int32 + - case: 3 # charge + set: + source: const + value: -10000 # Maximale Wirkleistung + set: + source: modbus + {{- include "modbus" . | indent 10 }} + timeout: {{ .timeout }} + register: + address: 44039 # SMA Modbus Profile: Inverter.WModCfg.WCtlComCfg.WSptMaxNom + type: writemultiple + decode: int32 {{- if .capacity }} capacity: {{ .capacity }} # kWh {{- end }} {{- end }} + {{- if eq .usage "grid" }} + power: + source: modbus + {{- include "modbus" . | indent 2 }} + register: + address: 30865 # SMA Modbus Profile: Metering.GridMs.TotWIn + type: input + decode: int32nan + energy: + source: modbus + {{- include "modbus" . | indent 2 }} + register: + address: 30581 # SMA Modbus Profile: Metering.GridMs.TotWhIn + type: holding + decode: int32nan + scale: 0.001 + currents: + - source: modbus + {{- include "modbus" . | indent 4 }} + register: + address: 31435 # SMA Modbus Profile: Metering.GridMs.A.phsA + type: input + decode: int32nan + scale: 0.001 + - source: modbus + {{- include "modbus" . | indent 4 }} + register: + address: 31437 # SMA Modbus Profile: Metering.GridMs.A.phsB + type: input + decode: int32nan + scale: 0.001 + - source: modbus + {{- include "modbus" . | indent 4 }} + register: + address: 31439 # SMA Modbus Profile: Metering.GridMs.A.phsC + type: input + decode: int32nan + scale: 0.001 + {{- end }} diff --git a/templates/definition/meter/sma-inverter-modbus.yaml b/templates/definition/meter/sma-inverter-modbus.yaml new file mode 100644 index 000000000..410353d24 --- /dev/null +++ b/templates/definition/meter/sma-inverter-modbus.yaml @@ -0,0 +1,97 @@ +template: sma-inverter-modbus +products: + - brand: SMA + description: + generic: Sunny Island (Modbus) + - brand: SMA + description: + generic: Sunny Boy Storage (Modbus) +capabilities: ["battery-control"] +params: + - name: usage + choice: ["battery"] + - name: modbus + choice: ["tcpip"] + port: 502 + id: 3 + help: + en: The Modbus TCP-Server needs to be enabled on this inverter + de: Der Modbus TCP-Server muss an diesem Wechselrichter aktiviert sein + - name: capacity + advanced: true + - name: watchdog + type: duration + default: 60s + advanced: true +render: | + type: custom + power: + source: modbus + {{- include "modbus" . | indent 2 }} + register: + address: 30775 # SMA Modbus Profile: GridMs.TotW + type: input + decode: int32nan + energy: + source: modbus + {{- include "modbus" . | indent 2 }} + register: + address: 30513 # SMA Modbus Profile: Metering.TotWhOut + type: holding + decode: uint64nan + scale: 0.001 + {{- if eq .usage "battery" }} + soc: + source: modbus + {{- include "modbus" . | indent 2 }} + register: + address: 30845 # SMA Modbus Profile: Bat.ChaStt + type: holding + decode: uint32nan + batterymode: + source: watchdog + timeout: {{ .watchdog }} # re-write at timeout/2 + reset: 1 # reset watchdog on normal + set: + source: switch + switch: + - case: 1 # normal + set: + source: const + value: 10000 # Maximale Wirkleistung + set: + source: modbus + {{- include "modbus" . | indent 10 }} + timeout: {{ .timeout }} + register: + address: 44039 # SMA Modbus Profile: Inverter.WModCfg.WCtlComCfg.WSptMaxNom + type: writemultiple + decode: int32 + - case: 2 # hold + set: + source: const + value: 0 # Maximale Wirkleistung + set: + source: modbus + {{- include "modbus" . | indent 10 }} + timeout: {{ .timeout }} + register: + address: 44039 # SMA Modbus Profile: Inverter.WModCfg.WCtlComCfg.WSptMaxNom + type: writemultiple + decode: int32 + - case: 3 # charge + set: + source: const + value: -10000 # Maximale Wirkleistung + set: + source: modbus + {{- include "modbus" . | indent 10 }} + timeout: {{ .timeout }} + register: + address: 44039 # SMA Modbus Profile: Inverter.WModCfg.WCtlComCfg.WSptMaxNom + type: writemultiple + decode: int32 + {{- if .capacity }} + capacity: {{ .capacity }} # kWh + {{- end }} + {{- end }} diff --git a/templates/definition/meter/sma-inverter.yaml b/templates/definition/meter/sma-inverter-speedwire.yaml similarity index 79% rename from templates/definition/meter/sma-inverter.yaml rename to templates/definition/meter/sma-inverter-speedwire.yaml index 958d78d6d..5c153a3ee 100644 --- a/templates/definition/meter/sma-inverter.yaml +++ b/templates/definition/meter/sma-inverter-speedwire.yaml @@ -1,9 +1,10 @@ -template: sma-inverter +template: sma-inverter-speedwire +covers: ["sma-inverter"] products: - brand: SMA description: - de: Wechselrichter - en: Inverter + de: Wechselrichter (Speedwire) + en: Inverter (Speedwire) params: - name: usage choice: ["pv", "battery"]