From cf8d9653f302f96a781ee22d1bf5bc56f8c83ab9 Mon Sep 17 00:00:00 2001 From: bohdan-s Date: Thu, 10 Mar 2022 11:24:59 +1100 Subject: [PATCH] v0.3.7: fix issues with cumulative flag in PVOutput --- README.md | 63 ++++++----------------------------- SunGather/exports/pvoutput.py | 15 +++++++-- SunGather/sungather.py | 1 + SunGather/version.py | 2 +- 4 files changed, 25 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 69f3c46..1214d10 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,14 @@
-

SunGather

+

SunGather

Collect data from Sungrow Inverters using ModbusTcpClient, SungrowModbusTcpClient or SungrowModbusWebClient and export to various locations.

+ Website Sungather.app + · Report Bug · Request Feature @@ -51,64 +53,19 @@ I have learned a lot from the following projects, THANK YOU ## Raodmap / TO DO * Full Home Assistant integration, as HACS addon -## Updates -**0.3.2** -* Added logging to file -* Hopefully better connection recovery -* Bug fixes - -**0.3.0** -**IMPORTANT: If updating from v0.1.x or v0.2.x please check config against config-example. some options for MQTT and PVOutput have changed** -* Heaps bug fixes -* Fixed PVOutput not working after midnight -* MQTT now auto-reconnects -* MQTT/PVOutput now verify values exist before trying to publish -* Rasberry Pi Docker support -* lots more... - - -**0.2.2** -* Minor bug fixes -* Add support for some inverter scrapes to fail -* Add support for zero_on_standby, this will 0 registers like temp that 'stick' to the last value when the inverter goes into standy. Handy if you want to graph 0 instead of the last read overnight - -**0.2.1** -* Minor bug fixes -* Updated config-example.yaml to clearly explain each option and if it is required or optional -* Replace is_running with run_state, was using bool which was causing errors in MQTT, run_state uses "ON" and "OFF" - -**0.2.0** -**IMPORTANT: If updating from v0.1.x please check config against config-example. some options for MQTT and PVOutput have changed** -* Re-write to Inverter scanning code, improved performance and more resilient to failures -* Re-write to PVOutput code, now uploads every 5 minutes as per API documentation, averages all data points over the 5 min window to reduce random high/low values -* Re-Write to MQTT code, now supports multiple sensor types - -**0.1.3** -* Improved error recovery, e.g. Inverter powers down overnight - -**0.1.2** -* Added InfluxDB export - -**0.1.1** -* Added docker image -* Added simple http web server -* Improved recovery when errors (See: SungrowModbusWebClient 0.2.6) - -**0.1.0** -Initial build ### Built With * [Python3](https://www.python.org/) ### Requires -* [paho-mqtt>=1.5.1](https://pypi.org/project/paho-mqtt/) -* [pymodbus>=2.4.0](https://pypi.org/project/pymodbus/) -* [SungrowModbusTcpClient>=0.1.6](https://pypi.org/project/SungrowModbusTcpClient/) -* [SungrowModbusWebClient>=0.2.6](https://pypi.org/project/SungrowModbusWebClient/) -* [PyYAML>=6.0](https://pypi.org/project/PyYAML/) -* [requests>=2.26.0](https://pypi.org/project/requests/) -* [influxdb-client>=1.24.0](https://pypi.org/project/influxdb-client/) +* [paho-mqtt](https://pypi.org/project/paho-mqtt/) +* [pymodbus](https://pypi.org/project/pymodbus/) +* [SungrowModbusTcpClient](https://pypi.org/project/SungrowModbusTcpClient/) +* [SungrowModbusWebClient](https://pypi.org/project/SungrowModbusWebClient/) +* [PyYAML](https://pypi.org/project/PyYAML/) +* [requests](https://pypi.org/project/requests/) +* [influxdb-client](https://pypi.org/project/influxdb-client/)

(back to top)

diff --git a/SunGather/exports/pvoutput.py b/SunGather/exports/pvoutput.py index 8d555a8..32404e1 100644 --- a/SunGather/exports/pvoutput.py +++ b/SunGather/exports/pvoutput.py @@ -125,10 +125,17 @@ class export_pvoutput(object): # Add new data to old data and increase count of data points for parameter in self.pvoutput_parameters: value = inverter.getRegisterValue(parameter.get('register')) + if parameter.get('multiple'): value = value * parameter.get('multiple') - if self.collected_data.get(parameter.get('name'),False): + # If using Cumulative Energy we just need the last data point, not the average + if parameter.get('name') == 'v1' and (self.pvoutput_config['cumulative_flag'] == 1 or self.pvoutput_config['cumulative_flag'] == 2): + self.collected_data[parameter.get('name')] = value + elif parameter.get('name') == 'v3' and (self.pvoutput_config['cumulative_flag'] == 1 or self.pvoutput_config['cumulative_flag'] == 3): + self.collected_data[parameter.get('name')] = value + # Add the last data point to the previous data point if exists, otherwise set as the last data point + elif self.collected_data.get(parameter.get('name'),False): self.collected_data[parameter.get('name')] = round(self.collected_data[parameter.get('name')] + value,3) else: self.collected_data[parameter.get('name')] = value @@ -153,7 +160,11 @@ class export_pvoutput(object): for x in range(1, 13): field = 'v' + str(x) if self.collected_data.get(field): - if x == 6 or x == 7: # Round to 1 decimal place + if x == 1 and (self.pvoutput_config['cumulative_flag'] == 1 or self.pvoutput_config['cumulative_flag'] == 2): + continue # Do nothing + elif x == 3 and (self.pvoutput_config['cumulative_flag'] == 1 or self.pvoutput_config['cumulative_flag'] == 3): + continue # do nothing + elif x == 6 or x == 7: # Round to 1 decimal place value = round(self.collected_data[field] / self.collected_data['count'], 1) else: # Getting errors when uploading decimals for power/energy so return INT value = int((self.collected_data[field] / self.collected_data['count'])) diff --git a/SunGather/sungather.py b/SunGather/sungather.py index 3346972..e2f4da5 100644 --- a/SunGather/sungather.py +++ b/SunGather/sungather.py @@ -405,6 +405,7 @@ def main(): for opt, arg in opts: if opt == '-h': print(f'\nSunGather {__version__}') + print(f'\nhttps://sungather.app') print(f'usage: python3 sungather.py [options]') print(f'\nCommandling arguments override any config file settings') print(f'Options and arguments:') diff --git a/SunGather/version.py b/SunGather/version.py index 5547ce2..61b594a 100644 --- a/SunGather/version.py +++ b/SunGather/version.py @@ -1 +1 @@ -__version__ = '0.3.6' \ No newline at end of file +__version__ = '0.3.7' \ No newline at end of file