Skip to content

Commit

Permalink
add different factors for deye three phase inverters
Browse files Browse the repository at this point in the history
  • Loading branch information
ndrsnhs committed Jul 8, 2024
1 parent f996d02 commit 9c8951f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
9 changes: 9 additions & 0 deletions packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1571,3 +1571,12 @@ def upgrade(topic: str, payload) -> Optional[dict]:
return {topic: updated_payload}
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 48)

def upgrade_datastore_48(self) -> None:
def upgrade(topic: str, payload) -> Optional[dict]:
if re.search("openWB/chargepoint/template/[0-9]+$", topic) is not None:
payload = decode_payload(payload)
if payload.get("type") == "deye" and "factor" not in payload["configuration"]:
payload["configuration"].update({"factor": 1})
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 49)
4 changes: 2 additions & 2 deletions packages/modules/devices/deye/bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def __init__(self, device_id: int, component_config: DeyeBatSetup) -> None:
self.__device_id = device_id
self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="speicher")

def update(self, client: ModbusTcpClient_, device_type: DeviceType) -> None:
def update(self, client: ModbusTcpClient_, device_type: DeviceType, factor: int) -> None:
unit = self.component_config.configuration.modbus_id

if device_type == DeviceType.THREE_PHASE:
power = client.read_holding_registers(590, ModbusDataType.INT_16, unit=unit) * -10
power = client.read_holding_registers(590, ModbusDataType.INT_16, unit=unit) * -1 * factor
soc = client.read_holding_registers(588, ModbusDataType.INT_16, unit=unit)
# 516: Geladen in kWh * 0,1
imported = client.read_holding_registers(516, ModbusDataType.UINT_16, unit=unit) * 100
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/deye/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ class DeyeConfiguration:
def __init__(self,
ip_address: Optional[str] = None,
port: int = 8899,
device_type: str = "three_phase"):
device_type: str = "three_phase", factor: int = 1):
self.ip_address = ip_address
self.port = port
self.device_type = device_type
self.factor = factor


class Deye:
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/devices/deye/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, device_id: int, component_config: DeyeCounterSetup) -> None:
self.__device_id = device_id
self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="bezug")

def update(self, client: ModbusTcpClient_, device_type: DeviceType):
def update(self, client: ModbusTcpClient_, device_type: DeviceType, factor: int):
unit = self.component_config.configuration.modbus_id

if device_type == DeviceType.THREE_PHASE:
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/deye/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def update_components(components: Iterable[Union[DeyeBat, DeyeCounter, DeyeInver
with client as c:
for component in components:
with SingleComponentUpdateContext(component.fault_state):
component.update(c, DeviceType(device_config.configuration.device_type))
component.update(c, DeviceType(device_config.configuration.device_type),
device_config.configuration.factor)

try:
client = ModbusTcpClient_(device_config.configuration.ip_address, device_config.configuration.port)
Expand Down
4 changes: 2 additions & 2 deletions packages/modules/devices/deye/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def __init__(self, device_id: int, component_config: Union[Dict, DeyeInverterSet
self.__device_id = device_id
self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="pv")

def update(self, client: ModbusTcpClient_, device_type: DeviceType) -> None:
def update(self, client: ModbusTcpClient_, device_type: DeviceType, factor: int) -> None:
unit = self.component_config.configuration.modbus_id

if device_type == DeviceType.THREE_PHASE:
# Wechselrichter hat 2 mppt Tracker
power = sum(client.read_holding_registers(672, [ModbusDataType.INT_16]*2, unit=unit)) * -10
power = sum(client.read_holding_registers(672, [ModbusDataType.INT_16]*2, unit=unit)) * -1 * factor
# 534: Gesamt Produktion Wechselrichter unsigned integer in kWh * 0,1
exported = client.read_holding_registers(534, ModbusDataType.UINT_16, unit=unit) * 100
elif device_type == DeviceType.SINGLE_PHASE_STRING or device_type == DeviceType.SINGLE_PHASE_HYBRID:
Expand Down

0 comments on commit 9c8951f

Please sign in to comment.