Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add multiplication function #666

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions custom_components/solarman/inverter_definitions/deye_2mppt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,21 @@ parameters:
- key: 1
value: "Enabled"
icon: 'mdi:factory'

- name: "PV1 Power"
class: "power"
state_class: "measurement"
uom: "W"
scale: 10
rule: 11
registers: [0x006D, 0x006E]
icon: 'mdi:solar-power'

- name: "PV2 Power"
class: "power"
state_class: "measurement"
uom: "W"
scale: 10
rule: 11
registers: [0x006F, 0x0070]
icon: 'mdi:solar-power'
18 changes: 18 additions & 0 deletions custom_components/solarman/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def try_parse_field (self, rawData, definition, start, length):
self.try_parse_time(rawData,definition, start, length)
elif rule == 10:
self.try_parse_raw(rawData,definition, start, length)
elif rule == 11:
self.try_parse_multipl(rawData,definition, start, length)
return

def do_validate(self, title, value, rule):
Expand Down Expand Up @@ -190,6 +192,22 @@ def try_parse_raw (self, rawData, definition, start, length):
if found:
self.result[title] = value
return

def try_parse_multipl (self, rawData, definition, start, length):
title = definition['name']
value = definition['scale'] if 'scale' in definition else 1
found = True
for r in definition['registers']:
index = r - start # get the decimal value of the register'
if (index >= 0) and (index < length):
temp = rawData[index]
value = value * temp
else:
found = False

if found:
self.result[title] = value
return

def try_parse_version (self, rawData, definition, start, length):
title = definition['name']
Expand Down
2 changes: 1 addition & 1 deletion customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ The `rule` field specifies how to interpret the binary data contained in the reg
| 8 | Date Time | |
| 9 | Time | Time value as string<ul><li>Example 1: Register Value 2200 => Time Value: 22:00</li><li>Example 2: Register value: 400 => 04:00</li></ul>|
| 10 | Raw | Similar to Bit field without hex conversion. Useful where you need to read multiple registers atomically |

| 11 | Multiplication | Multiplicate all elements |