From 84b5037c64f9983ea41b09d8bfd18b48355cd57d Mon Sep 17 00:00:00 2001 From: premultiply <4681172+premultiply@users.noreply.github.com> Date: Mon, 10 Feb 2025 11:15:21 +0100 Subject: [PATCH] Sungrow Hybrid: fix charge sign (again) (#18473) --- .../definition/meter/sungrow-hybrid.yaml | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/templates/definition/meter/sungrow-hybrid.yaml b/templates/definition/meter/sungrow-hybrid.yaml index af21190df..5056400d3 100644 --- a/templates/definition/meter/sungrow-hybrid.yaml +++ b/templates/definition/meter/sungrow-hybrid.yaml @@ -110,34 +110,41 @@ render: | {{- end }} {{- if eq .usage "battery" }} power: - source: calc - mul: - - source: calc - abs: + source: go # handling old and new firmware + script: | + res := float64(bp) + if (brs&0x2 > 0 || bc < 0) && bp >= 0 { + res = float64(-bp) + } + res + in: + - name: brs + type: int + config: + source: modbus + {{- include "modbus" . | indent 6 }} + register: + type: input + address: 13000 # Battery running state + decode: uint16 + - name: bc + type: int + config: + source: modbus + {{- include "modbus" . | indent 6 }} + register: + type: input + address: 13020 # Battery current + decode: int16 + - name: bp + type: int + config: source: modbus {{- include "modbus" . | indent 6 }} - timeout: {{ .timeout }} register: type: input address: 13021 # Battery power decode: int16 - - source: calc - add: - - source: modbus - {{- include "modbus" . | indent 6 }} - register: - type: input - address: 13000 # Battery running state - decode: bool16 - bitmask: 2 # Charging - scale: -1 - - source: modbus - {{- include "modbus" . | indent 6 }} - register: - type: input - address: 13000 # Battery running state - decode: bool16 - bitmask: 4 # Discharging energy: source: modbus {{- include "modbus" . | indent 2 }}