Skip to content

Commit

Permalink
add more fields to ConsumerPowerflow
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Ott <[email protected]>
  • Loading branch information
DerOetzi committed Jan 3, 2024
1 parent 49f22f1 commit 4c375a2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
27 changes: 25 additions & 2 deletions solaredge2mqtt/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,15 @@ def discharge(self) -> int:
class ConsumerPowerflow(InfluxDBModel):
house: int
evcharger: int = 0
inverter: int

used_pv_production: int
used_battery_production: int

@computed_field
@property
def total(self) -> int:
return self.house + self.evcharger
return self.house + self.evcharger + self.inverter

@staticmethod
def calc(
Expand All @@ -454,7 +458,26 @@ def calc(
# Happens when EV Charger starts up and meters are not yet updated
evcharger = 0

return ConsumerPowerflow(house=house, evcharger=evcharger)
if inverter.pv_production > inverter.production - grid.delivery:
pv_production = inverter.pv_production - grid.delivery
else:
pv_production = inverter.pv_production

if inverter.battery_production > inverter.production - grid.delivery:
battery_production = inverter.battery_production - grid.delivery
else:
battery_production = inverter.battery_production

return ConsumerPowerflow(
house=house,
evcharger=evcharger,
used_pv_production=pv_production,
used_battery_production=battery_production,
inverter=inverter.consumption,
)

def is_valid(self) -> bool:
return self.total >= self.used_battery_production + self.used_pv_production


class PowerFlow(InfluxDBModel):
Expand Down
2 changes: 2 additions & 0 deletions solaredge2mqtt/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ async def modbus_and_wallbox_loop(
evcharger = 0

powerflow = PowerFlow.calc(inverter_data, meters_data, batteries_data, evcharger)
if not powerflow.consumer.is_valid:
logger.warning("Invalid powerflow data: {powerflow}", powerflow=powerflow)

logger.debug(powerflow)
logger.info(
Expand Down

0 comments on commit 4c375a2

Please sign in to comment.