Skip to content

Commit

Permalink
add multiplication function
Browse files Browse the repository at this point in the history
deye_2mppt.yaml: add sensor to get power by string
  • Loading branch information
Sebastian Fiedler committed Sep 27, 2024
1 parent d4296b1 commit e3dd49e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
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 |

0 comments on commit e3dd49e

Please sign in to comment.