Skip to content

Commit

Permalink
Fix for: the first value for the day is too high #16 (#18)
Browse files Browse the repository at this point in the history
* Fixed bug for status 'Waiting' \nStart new day with 0kWh \n Add argument --pv-voltage to send pv voltage instead of grid voltage

* fix vpv -> vpv1

* argument order
  • Loading branch information
JaapBraam authored and markruys committed Jun 13, 2019
1 parent 1147253 commit 878d328
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ usage: gw2pvo [-h] --gw-station-id ID --gw-account ACCOUNT --gw-password
[--pvo-interval {5,10,15}]
[--darksky-api-key DARKSKY_API_KEY]
[--log {debug,info,warning,critical}] [--date YYYY-MM-DD]
[--skip-offline] [--city CITY] [--csv CSV] [--version]
[--pv-voltage] [--skip-offline] [--city CITY] [--csv CSV] [--version]
Upload GoodWe power inverter data to PVOutput.org
Expand All @@ -51,6 +51,7 @@ optional arguments:
--log {debug,info,warning,critical}
Set log level (default info)
--date YYYY-MM-DD Copy all readings (max 14/90 days ago)
--pv-voltage Send pv voltage instead of grid voltage
--skip-offline Skip uploads when inverter is offline
--city CITY Skip uploads from dusk till dawn
--csv CSV Append readings to a Excel compatible CSV file, DATE
Expand Down
18 changes: 9 additions & 9 deletions gw2pvo/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from gw2pvo import gw_csv
from gw2pvo import pvo_api
from gw2pvo import __version__
from gw2pvo import average

__author__ = "Mark Ruys"
__copyright__ = "Copyright 2017-2018, Mark Ruys"
Expand All @@ -21,7 +20,7 @@

last_eday_kwh = 0

def run_once(args, aver):
def run_once(args):
global last_eday_kwh

# Check if we only want to run during daylight
Expand Down Expand Up @@ -53,7 +52,7 @@ def run_once(args, aver):
csv.append(data)

# Submit reading to PVOutput, if they differ from the previous set
eday_kwh = aver.add(data['eday_kwh'])
eday_kwh = data['eday_kwh']
if data['pgrid_w'] == 0 and abs(eday_kwh - last_eday_kwh) < 0.001:
logging.debug("Ignore unchanged reading")
else:
Expand All @@ -62,9 +61,13 @@ def run_once(args, aver):
if args.darksky_api_key:
ds = ds_api.DarkSkyApi(args.darksky_api_key)
data['temperature'] = ds.get_temperature(data['latitude'], data['longitude'])

voltage = data['grid_voltage']
if args.pv_voltage:
voltage=data['pv_voltage']

pvo = pvo_api.PVOutputApi(args.pvo_system_id, args.pvo_api_key)
pvo.add_status(data['pgrid_w'], last_eday_kwh, data.get('temperature'), data['grid_voltage'])
pvo.add_status(data['pgrid_w'], last_eday_kwh, data.get('temperature'), voltage)

def copy(args):
# Fetch readings from GoodWe
Expand Down Expand Up @@ -96,6 +99,7 @@ def run():
parser.add_argument("--darksky-api-key", help="Dark Sky Weather API key")
parser.add_argument("--log", help="Set log level (default info)", choices=['debug', 'info', 'warning', 'critical'], default="info")
parser.add_argument("--date", help="Copy all readings (max 14/90 days ago)", metavar='YYYY-MM-DD')
parser.add_argument("--pv-voltage", help="Send pv voltage instead of grid voltage", action='store_true')
parser.add_argument("--skip-offline", help="Skip uploads when inverter is offline", action='store_true')
parser.add_argument("--city", help="Skip uploads from dusk till dawn")
parser.add_argument('--csv', help="Append readings to a Excel compatible CSV file, DATE in the name will be replaced by the current date")
Expand All @@ -120,13 +124,9 @@ def run():

startTime = datetime.now()

# The shorter the interval, the stronger we need some running average for GoodWe
subset_size = 4 - args.pvo_interval / 5 if args.pvo_interval else 1
aver = average.MovingAverage(subset_size)

while True:
try:
run_once(args, aver)
run_once(args)
except Exception as exp:
logging.error(exp)

Expand Down
3 changes: 2 additions & 1 deletion gw2pvo/gw_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, system_id, account, password):
self.token = '{"version":"v2.0.4","client":"ios","language":"en"}'
self.global_url = 'https://globalapi.sems.com.cn/api/'
self.base_url = self.global_url
self.status = { -1 : 'Offline', 1 : 'Normal' }
self.status = { -1 : 'Offline', 0 : 'Waiting', 1 : 'Normal' }

def getCurrentReadings(self):
''' Download the most recent readings from the GoodWe API. '''
Expand All @@ -38,6 +38,7 @@ def getCurrentReadings(self):
'eday_kwh' : inverterData['eday'],
'etotal_kwh' : inverterData['etotal'],
'grid_voltage' : self.parseValue(inverterData['output_voltage'], 'V'),
'pv_voltage' : inverterData['d']['vpv1'],
'latitude' : data['info'].get('latitude'),
'longitude' : data['info'].get('longitude')
}
Expand Down

0 comments on commit 878d328

Please sign in to comment.