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

Sungrow Fixes #2736

Merged
merged 16 commits into from
Jun 2, 2023
8 changes: 6 additions & 2 deletions modules/bezug_sungrow/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ else
MYLOGFILE="$RAMDISKDIR/evu.log"
fi

bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "counter" "$speicher1_ip" "$sungrowspeicherport" "$sungrowspeicherid" "$sungrowsr" >>"$MYLOGFILE" 2>&1
ret=$?
if [[ "$pvwattmodul" == "wr_sungrow" ]]; then
echo "value read at pv modul" >/dev/null
else
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "counter" "$pv1_ipa" "$pv1_ida" "$sungrowsr" "0" "0" >>"$MYLOGFILE" 2>&1
ret=$?
fi

openwbDebugLog $DMOD 2 "EVU RET: $ret"

Expand Down
2 changes: 1 addition & 1 deletion modules/speicher_sungrow/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ else
MYLOGFILE="$RAMDISKDIR/bat.log"
fi

bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "bat" "$speicher1_ip" "$sungrowspeicherport" "$sungrowspeicherid" >>"$MYLOGFILE" 2>&1
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "bat" "$pv1_ipa" "$pv1_ida" "0" "0" >>"$MYLOGFILE" 2>&1
ret=$?

openwbDebugLog $DMOD 2 "BAT RET: $ret"
3 changes: 2 additions & 1 deletion modules/wr2_sungrow/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ if [ ${DMOD} == "MAIN" ]; then
else
MYLOGFILE="$RAMDISKDIR/nurpv.log"
fi
read_counter=0

bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "inverter" "$pv2ip" "$pv2port" "$pv2id" "2" >>"$MYLOGFILE" 2>&1
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "inverter" "$pv2ip" "$pv2id" "2" "$read_counter" "$sungrow2sr" >>"$MYLOGFILE" 2>&1

cat "$RAMDISKDIR/pv2watt"
7 changes: 6 additions & 1 deletion modules/wr_sungrow/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ else
MYLOGFILE="$RAMDISKDIR/nurpv.log"
fi

bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "inverter" "$speicher1_ip" "$sungrowspeicherport" "$sungrowspeicherid" "1" >>"$MYLOGFILE" 2>&1
if [[ "$wattbezugmodul" == "bezug_sungrow" ]]; then
read_counter=1
else
read_counter=0
fi
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "inverter" "$pv1_ipa" "$pv1_ida" "1" "$read_counter" "$sungrowsr" >>"$MYLOGFILE" 2>&1

cat "$RAMDISKDIR/pvwatt"
13 changes: 8 additions & 5 deletions packages/modules/devices/sungrow/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self,
self.store = get_counter_value_store(self.component_config.id)
self.component_info = ComponentInfo.from_component_config(self.component_config)

def update(self):
def update(self, pv_power: float):
unit = self.__device_modbus_id
if self.component_config.configuration.version == Version.SH:
power = self.__tcp_client.read_input_registers(13009, ModbusDataType.INT_32,
Expand All @@ -38,10 +38,13 @@ def update(self):
# powers = [power / 10 for power in powers]
# log.info("power: " + str(power) + " powers?: " + str(powers))
else:
power = self.__tcp_client.read_input_registers(5082, ModbusDataType.INT_32,
wordorder=Endian.Little, unit=unit)
if self.component_config.configuration.version == Version.SG_winet_dongle:
power = power * -1
if pv_power != 0:
power = self.__tcp_client.read_input_registers(5082, ModbusDataType.INT_32,
wordorder=Endian.Little, unit=unit)
else:
power = self.__tcp_client.read_input_registers(5090, ModbusDataType.INT_32,
wordorder=Endian.Little, unit=unit)

# no valid data for powers per phase
# powers = self.__tcp_client.read_input_registers(5084, [ModbusDataType.UINT_16] * 3,
# wordorder=Endian.Little, unit=unit)
Expand Down
67 changes: 45 additions & 22 deletions packages/modules/devices/sungrow/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
from helpermodules.cli import run_using_positional_cli_args
from modules.common import modbus
from modules.common.abstract_device import AbstractDevice, DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.component_context import MultiComponentUpdateContext
from modules.devices.sungrow import bat
from modules.devices.sungrow import counter
from modules.devices.sungrow import inverter
from modules.devices.sungrow.config import (Sungrow, SungrowBatSetup, SungrowCounterConfiguration, SungrowCounterSetup,
SungrowInverterSetup)
from modules.devices.sungrow.version import Version


log = logging.getLogger(__name__)


sungrow_component_classes = Union[bat.SungrowBat, counter.SungrowCounter, inverter.SungrowInverter]


Expand All @@ -33,21 +31,21 @@ def __init__(self, device_config: Union[Dict, Sungrow]) -> None:
try:
self.device_config = dataclass_from_dict(Sungrow, device_config)
self.client = modbus.ModbusTcpClient_(self.device_config.configuration.ip_address,
self.device_config.configuration.port)
502)
except Exception:
log.exception("Fehler im Modul "+self.device_config.name)
log.exception("Fehler im Modul " + self.device_config.name)

def add_component(self,
component_config: Union[Dict,
SungrowBatSetup, SungrowCounterSetup, SungrowInverterSetup]) -> None:
component_config: Union[
Dict, SungrowBatSetup, SungrowCounterSetup, SungrowInverterSetup]) -> None:
if isinstance(component_config, Dict):
component_type = component_config["type"]
else:
component_type = component_config.type
component_config = dataclass_from_dict(COMPONENT_TYPE_TO_MODULE[
component_type].component_descriptor.configuration_factory, component_config)
component_config = dataclass_from_dict(
COMPONENT_TYPE_TO_MODULE[component_type].component_descriptor.configuration_factory, component_config)
if component_type in self.COMPONENT_TYPE_TO_CLASS:
self.components["component"+str(component_config.id)] = (self.COMPONENT_TYPE_TO_CLASS[component_type](
self.components["component" + str(component_config.id)] = (self.COMPONENT_TYPE_TO_CLASS[component_type](
self.device_config.id, self.device_config.configuration.modbus_id, component_config, self.client))
else:
raise Exception(
Expand All @@ -59,10 +57,13 @@ def update(self) -> None:
log.debug("Start device reading " + str(self.components))
if self.components:
with self.client:
for component in self.components:
# Auch wenn bei einer Komponente ein Fehler auftritt, sollen alle anderen noch ausgelesen werden.
with SingleComponentUpdateContext(self.components[component].component_info):
self.components[component].update()
with MultiComponentUpdateContext(self.components):
for component in self.components:
if isinstance(component, inverter.SungrowInverter):
pv_power = component.update()
for component in self.components:
if isinstance(component, counter.SungrowCounter):
component.update(pv_power)
else:
log.warning(
self.device_config.name +
Expand All @@ -77,27 +78,49 @@ def update(self) -> None:
}


def read_legacy(ip_address: str, port: int, modbus_id: int, component_config: dict):
def read_legacy(ip_address: str,
modbus_id: int,
component_config: dict):
device_config = Sungrow()
device_config.configuration.ip_address = ip_address
device_config.configuration.port = port
device_config.configuration.port = 502
device_config.configuration.modbus_id = modbus_id
dev = Device(device_config)
dev.add_component(component_config)
dev.update()


def read_legacy_bat(ip_address: str, port: int, modbus_id: int, num: Optional[int] = None):
read_legacy(ip_address, port, modbus_id, bat.component_descriptor.configuration_factory(id=None))
def read_legacy_bat(ip_address: str, modbus_id: int,
num: Optional[int] = None,
read_counter: Optional[int] = None,
version: Optional[int] = None):
read_legacy(ip_address, modbus_id, bat.component_descriptor.configuration_factory(id=None))


def read_legacy_counter(ip_address: str, port: int, modbus_id: int, version: int):
read_legacy(ip_address, port, modbus_id, counter.component_descriptor.configuration_factory(
def read_legacy_counter(ip_address: str, modbus_id: int,
version: int,
read_counter: int,
unused_version: int):
read_legacy(ip_address, modbus_id, counter.component_descriptor.configuration_factory(
id=None, configuration=SungrowCounterConfiguration(version=Version(version))))


def read_legacy_inverter(ip_address: str, port: int, modbus_id: int, num: int):
read_legacy(ip_address, port, modbus_id, inverter.component_descriptor.configuration_factory(id=num))
def read_legacy_inverter(ip_address: str,

modbus_id: int,
num: int,
read_counter: int,
version: int):
device_config = Sungrow()
device_config.configuration.ip_address = ip_address
device_config.configuration.port = 502
device_config.configuration.modbus_id = modbus_id
dev = Device(device_config)
dev.add_component(inverter.component_descriptor.configuration_factory(id=num))
if read_counter == 1:
dev.add_component(counter.component_descriptor.configuration_factory(
id=None, configuration=SungrowCounterConfiguration(version=Version(version))))
dev.update()


def main(argv: List[str]):
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/sungrow/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self,
self.store = get_inverter_value_store(self.component_config.id)
self.component_info = ComponentInfo.from_component_config(self.component_config)

def update(self) -> None:
def update(self) -> float:
unit = self.__device_modbus_id
power = self.__tcp_client.read_input_registers(5016,
ModbusDataType.UINT_32,
Expand All @@ -40,6 +40,7 @@ def update(self) -> None:
exported=exported
)
self.store.set(inverter_state)
return power


component_descriptor = ComponentDescriptor(configuration_factory=SungrowInverterSetup)
20 changes: 4 additions & 16 deletions web/settings/modulconfigbat.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<option <?php if($speichermodulold == "speicher_solax") echo "selected" ?> value="speicher_solax">Solax Speicher</option>
<option <?php if($speichermodulold == "speicher_sonneneco") echo "selected" ?> value="speicher_sonneneco">Sonnen eco</option>
<option <?php if($speichermodulold == "speicher_studer") echo "selected" ?> value="speicher_studer">Studer-Innotec System</option>
<option <?php if($speichermodulold == "speicher_sungrow") echo "selected" ?> value="speicher_sungrow">Sungrow Hybrid</option>
<option <?php if($speichermodulold == "speicher_sungrow") echo "selected" ?> value="speicher_sungrow">Sungrow SH Speicher</option>
<option <?php if($speichermodulold == "speicher_powerwall") echo "selected" ?> value="speicher_powerwall">Tesla Powerwall</option>
<option <?php if($speichermodulold == "speicher_tesvoltsma") echo "selected" ?> value="speicher_tesvoltsma">Tesvolt mit SMA</option>
<option <?php if($speichermodulold == "speicher_varta") echo "selected" ?> value="speicher_varta">Varta Element u.a.</option>
Expand Down Expand Up @@ -261,22 +261,11 @@ function visibility_solarwatt_ip2() {
</div>

<div id="divspeichersungrow" class="hide">
<div class="form-row mb-1">
<label for="sungrowspeicherport" class="col-md-4 col-form-label">Netzwerk-Port</label>
<div class="col">
<input class="form-control" type="number" min="1" step="1" name="sungrowspeicherport" id="sungrowspeicherport" value="<?php echo $sungrowspeicherportold ?>">
<span class="form-text small">Hier kann ein abweichender Netzwerk-Port angegeben werden, auf dem die Modbus/TCP Verbindung aufgebaut wird.Standard ist 502.</span>
</div>
</div>
<div class="form-row mb-1">
<label for="sungrowspeicherid" class="col-md-4 col-form-label">Geräteadresse</label>
<div class="col">
<input class="form-control" type="number" min="1" max="254" step="1" name="sungrowspeicherid" id="sungrowspeicherid" value="<?php echo $sungrowspeicheridold ?>">
<span class="form-text small">Gültige Werte 1-254. Standard ist 1.</span>
</div>
<div class="card-text alert alert-warning">
Bitte halten Sie zur Fehlervermeidung die Firmware des Sungrow Wechselrichters und Wii Net Dongels aktuell.
</div>
<div class="alert alert-info">
Es muss Sungrow als PV und EVU Modul gewählt werden.
Es muss Sungrow Variante SH im Modul PV1 und gegebenenfalls Sungrow als EVU Modul gewählt werden.
</div>
</div>

Expand Down Expand Up @@ -801,7 +790,6 @@ function display_speichermodul() {
}

if($('#speichermodul').val() == 'speicher_sungrow') {
showSection('#divspeicherip');
showSection('#divspeichersungrow');
}
if($('#speichermodul').val() == 'speicher_good_we') {
Expand Down
14 changes: 2 additions & 12 deletions web/settings/modulconfigevu.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<option <?php if($wattbezugmodulold == "bezug_solarworld") echo "selected" ?> value="bezug_solarworld">Solarworld</option>
<option <?php if($wattbezugmodulold == "bezug_solax") echo "selected" ?> value="bezug_solax">Solax</option>
<option <?php if($wattbezugmodulold == "bezug_sonneneco") echo "selected" ?> value="bezug_sonneneco">Sonnen eco</option>
<option <?php if($wattbezugmodulold == "bezug_sungrow") echo "selected" ?> value="bezug_sungrow">Sungrow Speicher</option>
<option <?php if($wattbezugmodulold == "bezug_sungrow") echo "selected" ?> value="bezug_sungrow">Sungrow</option>
<option <?php if($wattbezugmodulold == "bezug_powerwall") echo "selected" ?> value="bezug_powerwall">Tesla Powerwall</option>
<option <?php if($wattbezugmodulold == "bezug_varta") echo "selected" ?> value="bezug_varta">Varta Speicher</option>
<option <?php if($wattbezugmodulold == "bezug_victrongx") echo "selected" ?> value="bezug_victrongx">Victron (z.B. GX)</option>
Expand Down Expand Up @@ -141,17 +141,7 @@
</div>
<div id="wattbezugsungrow" class="hide">
<div class="card-text alert alert-info">
Konfiguration im zugehörigen Speichermodul des Sungrow erforderlich!
</div>
<div class="form-row mb-1">
<label for="sungrowsr" class="col-md-4 col-form-label">Version des Sungrow</label>
<div class="col">
<select name="sungrowsr" id="sungrowsr" class="form-control">
<option <?php if($sungrowsrold == 0) echo "selected" ?> value="0">SH (Hybrid)</option>
<option <?php if($sungrowsrold == 1) echo "selected" ?> value="1">SG (kein Hybrid)</option>
<option <?php if($sungrowsrold == 2) echo "selected" ?> value="2">SG mit WiNet-Dongle (kein Hybrid)</option>
</select>
</div>
Konfiguration im zugehörigen PV-Modul 1 mit Auswahl Sungrow erforderlich!
</div>
</div>
<div id="wattbezugsonneneco" class="hide">
Expand Down
35 changes: 34 additions & 1 deletion web/settings/modulconfigpv.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@
</div>
</div>
<div id="pvsungrow" class="hide">
<div class="form-row mb-1">
<label for="sungrowsr" class="col-md-4 col-form-label">Variante des Sungrow</label>
<div class="col">
<select name="sungrowsr" id="sungrowsr" class="form-control">
<option <?php if($sungrowsrold == 0) echo "selected" ?> value="0">SH (Hybrid)</option>
<option <?php if($sungrowsrold == 1) echo "selected" ?> value="1">SG (kein Hybrid)</option>
<option <?php if($sungrowsrold == 2) echo "selected" ?> value="2">SG mit WiNet-Dongle (kein Hybrid)</option>
</select>
</div>
<div class="card-text alert alert-warning">
1) Die Variante SH mit Batterie nur über die LAN IP mit OpenWB nutzbar (Hierzu hinter dem WiNet den Lan Anschluss nutzen). WiNet zusätzlich ins Heimnetz (per Lan oder Wlan) einbinden um ISolarCloud nutzen zu können.
2) Bitte halten Sie zur Fehlervermeidung die Firmware des Sungrow Wechselrichters und WiNet-Dongls aktuell.
</div>
</div>
<div class="card-text alert alert-info">
Konfiguration im zugehörigen Speichermodul des Sungrow erforderlich!
</div>
Expand Down Expand Up @@ -1118,6 +1132,8 @@ function display_pvwattmodul() {
showSection('#pvbatterx');
}
if($('#pvwattmodul').val() == 'wr_sungrow') {
showSection('#pvip');
showSection('#pvid');
showSection('#pvsungrow');
}
if($('#pvwattmodul').val() == 'wr_sonneneco') {
Expand Down Expand Up @@ -1357,6 +1373,22 @@ function display_pvwattmodul() {
</div>
</div>
</div>
<div id="pv2sungrow" class="hide">
<div class="form-row mb-1">
<label for="sungrow2sr" class="col-md-4 col-form-label">Variante des Sungrow</label>
<div class="col">
<select name="sungrow2sr" id="sungrow2sr" class="form-control">
<option <?php if($sungrowsrold == 0) echo "selected" ?> value="0">SH (Hybrid)</option>
<option <?php if($sungrowsrold == 1) echo "selected" ?> value="1">SG (kein Hybrid)</option>
<option <?php if($sungrowsrold == 2) echo "selected" ?> value="2">SG mit WiNet-Dongle (kein Hybrid)</option>
</select>
</div>
<div class="card-text alert alert-warning">
1) Die Variante SH kann bei PV2 nur ohne Batterie berücksichtigt werden. Mit angeschlossener Batterie und Sungrow EVU nur an PV1 nutzbar.
2) Bitte halten Sie zur Fehlervermeidung die Firmware des Sungrow Wechselrichters und WiNet-Dongls aktuell.
</div>
</div>
</div>
<div id="pv2solarlogdiv" class="hide">
<div class="form-row mb-1">
<label for="bezug2_solarlog_ip" class="col-md-4 col-form-label">IP Adresse</label>
Expand Down Expand Up @@ -1439,8 +1471,9 @@ function display_pv2wattmodul() {
}
if($('#pv2wattmodul').val() == 'wr2_sungrow') {
showSection('#pv2ipdiv');
showSection('#pv2portdiv');
showSection('#pv2iddiv');
showSection('#pv2sungrow');

}

if($('#pv2wattmodul').val() == 'wr2_kostalpiko') {
Expand Down