Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisBrock committed Sep 2, 2024
2 parents e0b48e2 + b491e9e commit 9afd86d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Additional settings are required depending on the selected device plugin:
| Setting | Description |
| ----------------------------- | ------------------------------------------------------------- |
| fronius::host_name | IP address or host name of your fronius inverter. |
| fronius::has_meter | True/False - Is there a Fronius smart meter present? |
## Deveopment Environment
Expand Down
31 changes: 21 additions & 10 deletions backend/devices/Fronius.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def __init__(self, config):
self.url_meter = (
f"http://{self.host_name}/solar_api/v1/GetMeterRealtimeData.cgi?Scope=System")

self.has_meter = config.config_data['fronius']['has_meter'] # True / False - Smart Meter active?

# Initialize with default values
self.total_energy_produced_kwh = 0.0
self.total_energy_consumed_kwh = 0.0
Expand All @@ -40,11 +42,17 @@ def copy_data(self, inverter_data, meter_data):
str_total_produced_wh = inverter_data["Body"]["Data"]["Site"]["E_Total"]
total_produced_kwh = float(str_total_produced_wh) * 0.001
# Meter data
str_total_consumed_from_grid_wh = meter_data["Body"]["Data"]["0"]["EnergyReal_WAC_Plus_Absolute"]
total_consumed_from_grid_kwh = float(
str_total_consumed_from_grid_wh) * 0.001
str_total_fed_in_wh = meter_data["Body"]["Data"]["0"]["EnergyReal_WAC_Minus_Absolute"]
total_fed_in_kwh = float(str_total_fed_in_wh) * 0.001
if self.has_meter:
str_total_consumed_from_grid_wh = meter_data["Body"]["Data"]["0"]["EnergyReal_WAC_Plus_Absolute"]
total_consumed_from_grid_kwh = float(
str_total_consumed_from_grid_wh) * 0.001
str_total_fed_in_wh = meter_data["Body"]["Data"]["0"]["EnergyReal_WAC_Minus_Absolute"]
total_fed_in_kwh = float(str_total_fed_in_wh) * 0.001
else:
str_total_consumed_from_grid_wh = 0
total_consumed_from_grid_kwh = 0
str_total_fed_in_wh = 0
total_fed_in_kwh = 0
# Compute other values
total_self_consumption_kwh = total_produced_kwh - total_fed_in_kwh
total_consumption_kwh = total_consumed_from_grid_kwh + total_self_consumption_kwh
Expand All @@ -67,7 +75,7 @@ def copy_data(self, inverter_data, meter_data):
str_cur_production_w = inverter_data["Body"]["Data"]["Site"]["P_PV"]
cur_production_kw = 0.0 if str_cur_production_w is None else float(
str_cur_production_w) * 0.001
str_grid_power_w = inverter_data["Body"]["Data"]["Site"]["P_Grid"]
str_grid_power_w = inverter_data["Body"]["Data"]["Site"]["P_Grid"] or 0
grid_power_kw = float(str_grid_power_w) * 0.001
cur_feed_in_kw = (-grid_power_kw) if grid_power_kw < 0.0 else 0.0
cur_consumption_from_grid = grid_power_kw if grid_power_kw > 0.0 else 0.0
Expand Down Expand Up @@ -99,10 +107,13 @@ def update(self):
r_inverter = requests.get(self.url_inverter, timeout=5)
r_inverter.raise_for_status()
# Query smart meter data
r_meter = requests.get(self.url_meter, timeout=5)
r_meter.raise_for_status()
# Extract and process relevant data
self.copy_data(r_inverter.json(), r_meter.json())
if self.has_meter:
r_meter = requests.get(self.url_meter, timeout=5)
r_meter.raise_for_status()
# Extract and process relevant data
self.copy_data(r_inverter.json(), r_meter.json())
else:
self.copy_data(r_inverter.json(), "{}") # Null meter data
except requests.exceptions.Timeout:
logging.error(f"Fronius device: Timeout requesting "
f"'{self.url_inverter}' or '{self.url_meter}'")
Expand Down
2 changes: 1 addition & 1 deletion backend/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Version = "0.31.0"
Version = "0.32.0"


def get_version():
Expand Down
3 changes: 2 additions & 1 deletion templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ device:
# Enable if you want to use Fronius hardware
#fronius:
# host_name: 192.168.178.200 # Host name/IP address of the Fronius end point
# has_meter: False # Is smart meter present?

# Electricity prices. Used to calculate earnings in the UI.
prices:
Expand All @@ -34,4 +35,4 @@ server:

# Data grabber configuration. Do not modify!
grabber:
interval_s: 5 # Interval for the data acquisition in seconds
interval_s: 5 # Interval for the data acquisition in seconds

0 comments on commit 9afd86d

Please sign in to comment.