From deb97978f00fecf2de6cb0160a994578e78f2e67 Mon Sep 17 00:00:00 2001 From: Michael Kotten Date: Fri, 29 Jul 2022 10:22:54 +0200 Subject: [PATCH] copy of export_power and load_power for hybrid models to calculate export_to_grid and import_from_grid --- SunGather/registers-sungrow.yaml | 19 +++++++++++++--- SunGather/sungather.py | 38 +++++++++----------------------- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/SunGather/registers-sungrow.yaml b/SunGather/registers-sungrow.yaml index 358ffc5..23ad902 100644 --- a/SunGather/registers-sungrow.yaml +++ b/SunGather/registers-sungrow.yaml @@ -1216,18 +1216,31 @@ registers: accuracy: 0.1 unit: "kWh" models: ["SH5K-20","SH3K6","SH4K6","SH5K-V13","SH5K-30","SH3K6-30","SH4K6-30","SH5.0RS","SH3.6RS","SH4.6RS","SH6.0RS","SH10RT","SH8.0RT","SH6.0RT","SH5.0RT"] - - name: "load_power_hybrid" + - name: "load_power" level: 1 address: 13008 datatype: "S32" unit: "W" - models: ["SH5K-20","SH3K6","SH4K6","SH5K-V13","SH5K-30","SH3K6-30","SH4K6-30","SH5.0RS","SH3.6RS","SH4.6RS","SH6.0RS","SH10RT","SH8.0RT","SH6.0RT","SH5.0RT"] - - name: "export_power_hybrid" + models: ["SH5K-20","SH3K6","SH4K6","SH5K-V13","SH5K-30","SH3K6-30","SH4K6-30","SH5.0RS","SH3.6RS","SH4.6RS","SH6.0RS","SH10RT","SH8.0RT","SH6.0RT","SH5.0RT"] + - name: "load_power_hybrid" + level: 1 + address: 13008 + datatype: "S32" + unit: "W" + models: ["SH5K-20","SH3K6","SH4K6","SH5K-V13","SH5K-30","SH3K6-30","SH4K6-30","SH5.0RS","SH3.6RS","SH4.6RS","SH6.0RS","SH10RT","SH8.0RT","SH6.0RT","SH5.0RT"] + - name: "export_power_hybrid" level: 1 address: 13010 datatype: "S32" unit: "W" models: ["SH5K-20","SH3K6","SH4K6","SH5K-V13","SH5K-30","SH3K6-30","SH4K6-30","SH5.0RS","SH3.6RS","SH4.6RS","SH6.0RS","SH10RT","SH8.0RT","SH6.0RT","SH5.0RT"] + - name: "export_power" + level: 1 + address: 13010 + datatype: "S32" + accuracy: -1 + unit: "W" + models: ["SH5K-20","SH3K6","SH4K6","SH5K-V13","SH5K-30","SH3K6-30","SH4K6-30","SH5.0RS","SH3.6RS","SH4.6RS","SH6.0RS","SH10RT","SH8.0RT","SH6.0RT","SH5.0RT"] - name: "daily_battery_charge_from_pv" level: 1 address: 13012 diff --git a/SunGather/sungather.py b/SunGather/sungather.py index 285d500..2a7e756 100644 --- a/SunGather/sungather.py +++ b/SunGather/sungather.py @@ -323,37 +323,19 @@ def scrape(self): # Leave connection open, see if helps resolve the connection issues #self.close() - # Create a registers for Power imported and exported to/from Grid + # Create registers for Power imported and exported to/from Grid + power = 0 if self.inverter_config['level'] >= 1: self.latest_scrape["export_to_grid"] = 0 self.latest_scrape["import_from_grid"] = 0 - - if self.validateRegister('meter_power'): - try: - power = self.latest_scrape.get('meter_power', self.latest_scrape.get('export_power', 0)) - if power < 0: - self.latest_scrape["export_to_grid"] = abs(power) - elif power >= 0: - self.latest_scrape["import_from_grid"] = power - except Exception: - pass - # in this case we connected to a hybrid inverter and need to use export_power_hybrid - # export_power_hybrid is negative in case of importing from the grid - elif self.validateRegister('export_power_hybrid'): - try: - power = self.latest_scrape.get('export_power_hybrid', 0) - if power < 0: - self.latest_scrape["import_from_grid"] = abs(power) - elif power >= 0: - self.latest_scrape["export_to_grid"] = power - except Exception: - pass - - try: # If inverter is returning no data for load_power, we can calculate it manually - if not self.latest_scrape["load_power"]: - self.latest_scrape["load_power"] = int(self.latest_scrape.get('total_active_power')) + int(self.latest_scrape.get('meter_power')) - except Exception: - pass + power = self.latest_scrape.get('meter_power', self.latest_scrape.get('export_power', 0)) + if power < 0: + self.latest_scrape["export_to_grid"] = abs(power) + elif power >= 0: + self.latest_scrape["import_from_grid"] = power + # If inverter is returning no data for load_power, we can calculate it manually + if not self.latest_scrape.get("load_power"): + self.latest_scrape["load_power"] = self.latest_scrape.get('total_active_power', 0) + power # See if the inverter is running, This is added to inverters so can be read via MQTT etc... # It is also used below, as some registers hold the last value on 'stop' so we need to set to 0