diff --git a/README.md b/README.md index 4566bed..350bbb4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/backend/devices/Fronius.py b/backend/devices/Fronius.py index 772e4e9..a24adf0 100644 --- a/backend/devices/Fronius.py +++ b/backend/devices/Fronius.py @@ -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 @@ -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 @@ -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 @@ -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}'") diff --git a/backend/version.py b/backend/version.py index 68e15ea..0c0832b 100644 --- a/backend/version.py +++ b/backend/version.py @@ -1,4 +1,4 @@ -Version = "0.31.0" +Version = "0.32.0" def get_version(): diff --git a/templates/config.yml b/templates/config.yml index 20d4903..508c344 100644 --- a/templates/config.yml +++ b/templates/config.yml @@ -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: @@ -34,4 +35,4 @@ server: # Data grabber configuration. Do not modify! grabber: - interval_s: 5 # Interval for the data acquisition in seconds \ No newline at end of file + interval_s: 5 # Interval for the data acquisition in seconds