Skip to content

Commit

Permalink
Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
webstoney committed Aug 20, 2024
1 parent d1daa63 commit c320806
Showing 1 changed file with 46 additions and 22 deletions.
68 changes: 46 additions & 22 deletions plugins/sun2000/sun2000_ → plugins/solar/sun2000_
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/env python3

# Wildcard-plugin to monitor a Huawei SUN 2000 inverter with SDongle through Modbus TCP
# Wildcard-plugin to monitor a Huawei SUN 2000 inverter with SDongle
# through Modbus TCP
#
# To monitor an inverter, link sun2000_<ip-or-hostname> to this file.
# E.g.
# ln -s /usr/share/munin/plugins/sun2000_ /etc/munin/plugins/sun2000_192.168.1.2
# ...will monitor the inverter with ip 192.168.1.2
# ln -s /usr/share/munin/plugins/sun2000_ \
# /etc/munin/plugins/sun2000_192.168.1.2
# ...will monitor the dongle with ip 192.168.1.2
#
# prerequisite is pymodbus library, install with 'pip3 install pymodbus[all]'
#
Expand All @@ -16,12 +18,14 @@
# env.ADDITIONAL_INVERTERS
#
# Parameters
# MODBUS_PORT - Specifies the TCP-Port of the sun200 smart donge. Defaults to 502
# HAS_BATTERY - If the inverter has battery storage attached, set to 1 for additional graphs.
# Defaults to 0
# ADDITIONAL_INVERTERS - if you have additional inverters attached, put their modbus id(s)
# comma-separated here (e.g. 16,32). Usually the first additional
# slave inverter does have id 16
# MODBUS_PORT - Specifies the TCP-Port of the sun2000 smart dongle.
# Defaults to 502
# HAS_BATTERY - If the inverter has battery storage attached, set to 1
# for additional graphs. Defaults to 0
# ADDITIONAL_INVERTERS - if you have additional inverters attached, put
# their modbus id(s) comma-separated here (e.g.
# 16,32). Usually the first additional slave
# inverter does have id 16
#
# The same parameters can also be specified on a per-inverter basis, eg:
# [sun2000_inverter1]
Expand Down Expand Up @@ -63,10 +67,10 @@ from pymodbus.transaction import ModbusSocketFramer
plugin_name = list(os.path.split(sys.argv[0]))[1]
PORT = os.environ.get('MODBUS_PORT') or 502
HASBATTERY = os.environ.get('HAS_BATTERY') or 0
ADDINVERTERS = os.environ.get('ADDITIONAL_INVERTERS') or []
if (len(ADDINVERTERS) != 0):
ADDINVERTERS = ADDINVERTERS.split(",")
plugin_version = "0.5"
ADDINV = os.environ.get('ADDITIONAL_INVERTERS') or []
if (len(ADDINV) != 0):
ADDINV = ADDINV.split(",")
plugin_version = "0.6"


def get_sun2000_ip(plugin_name):
Expand Down Expand Up @@ -108,13 +112,23 @@ def to_I16(i):


def print_config():
print("multigraph sun2000_green")
print("graph_title SUN2000 pct green power")
print("graph_order power1 pctgreen1")
print("graph_category sensors")
print("graph_vlabel Green Power (%)")
print("graph_args -l 0 -u 100")
print("graph_info Percentage of green power")
print("pctgreen1.label Green power (%)")
print("pctgreen1.colour 00cccc")
print("")
print("multigraph sun2000_plant")
print("graph_title SUN2000 PowerPlant")
print("graph_order power1 watt1 usage1")
print("graph_category sensors")
print("graph_vlabel Power (W)")
print("graph_scale yes")
print("graph_info Solar IN/Out Values in W. positive = sending to, negative = getting from")
print("graph_info Solar IN/Out Values in W. + = sending, - = getting")
print("power1.label Solar power (W)")
print("power1.colour 00cc00")
print("watt1.label Grid (W)")
Expand Down Expand Up @@ -167,35 +181,45 @@ if len(sys.argv) > 1:
sys.exit(1)

if client.connect():
print("multigraph sun2000_plant")
power1 = 0
bat1 = 0
watt1 = 0
usage1 = 0
pctgreen1 = 0
APPD = client.read_holding_registers(32064, 2, 1) # Power from solar
if hasattr(APPD, "registers"):
power1 = to_I32(APPD.registers)
if (len(ADDINVERTERS) > 0):
for i in range(0, len(ADDINVERTERS)):
APPD = client.read_holding_registers(32064, 2, int(ADDINVERTERS[i]))
if (len(ADDINV) > 0):
for i in range(0, len(ADDINV)):
APPD = client.read_holding_registers(32064, 2, int(ADDINV[i]))
if hasattr(APPD, "registers"):
power1 += to_I32(APPD.registers)
print("power1.value", -(power1))
# Watt to/from Grid (>0 = feeding, <0 = getting)
APPD = client.read_holding_registers(37113, 2, 1)
if hasattr(APPD, "registers"):
watt1 = to_I32(APPD.registers)
print("watt1.value", watt1)
if (HASBATTERY != 0):
# Watt to/from battery (>0 = charge, <0 = discharge)
APPD = client.read_holding_registers(37001, 2, 1)
if hasattr(APPD, "registers"):
bat1 = to_I32(APPD.registers)
print("bat1.value", bat1)
APPD = client.read_holding_registers(37004, 1, 1) # battery SOC
if hasattr(APPD, "registers"):
pct1 = (to_I16(APPD.registers) / 10)
print("usage1.value", abs(int(power1) - int(bat1) - int(watt1)))
usage1 = abs(int(power1) - int(bat1) - int(watt1))
if (watt1 > 0):
pctgreen1 = 100
elif watt1 + usage1 > 0:
pctgreen1 = 100 - (abs(watt1) / usage1 * 100)
print("multigraph sun2000_green")
print("pctgreen1.value", pctgreen1)
print("")
print("multigraph sun2000_plant")
print("power1.value", -(power1))
print("watt1.value", watt1)
print("usage1.value", usage1)
if (HASBATTERY != 0):
print("bat1.value", bat1)
print("")
print("multigraph sun2000_battery")
print("pct1.value", pct1)

0 comments on commit c320806

Please sign in to comment.