From: Sven Höxter Date: Mon, 14 Apr 2025 12:48:22 +0000 (+0200) Subject: Output per panel / micro inverter power information X-Git-Url: http://git.sven.stormbind.net/?a=commitdiff_plain;h=438c47f82ea427d1c5808f342d660f12cd21f297;p=sven%2Fscripts.git Output per panel / micro inverter power information Sometimes the envertech portal reports incorrent or no data for the total power retrieved from the getStationInfo API. Include the more detailed information in the status output to aid narrowing down the problem. --- diff --git a/home/portalmonitor.py b/home/portalmonitor.py index c8b732b..993aa65 100755 --- a/home/portalmonitor.py +++ b/home/portalmonitor.py @@ -1,11 +1,11 @@ #!/usr/bin/env python3 +from suntime import Sun import argparse +import configparser import requests -import time import sys -import configparser -from suntime import Sun +import time parser = argparse.ArgumentParser() parser.add_argument("-s", @@ -36,8 +36,22 @@ def isDaylight(lat, lon, toleranceSeconds): return daylight +# Condense the per Panel/Microinverter details down to +# the information we want to print out later on +def powerDetailsCondensed(powerDetails): + powerCondensed = [] + for panel in powerDetails: + panelData = {} + panelData["name"] = panel["SNALIAS"] + panelData["power"] = panel["POWER"] + panelData["timestamp"] = panel["SITETIME"] + powerCondensed.append(panelData) -def getCurrentPower(userName, password, stationId): + return(powerCondensed) + + +# Query all relevant System Information in one Session +def retrieveData(userName, password, stationId): with requests.Session() as s: try: r = s.post('https://www.envertecportal.com/apiaccount/login', @@ -55,6 +69,18 @@ def getCurrentPower(userName, password, stationId): timeout=(20, 60)).json() power = r['Data']['Power'] + # ignores paging for now, inputs are website defaults + r = s.post( + 'https://www.envertecportal.com/ApiInverters/QueryTerminalReal', + data={ + 'page': 1, + 'perPage': 20, + 'orderBy': 'GATEWAYSN', + 'whereCondition': f"{{\"STATIONID\":\"{stationId}\"}}" + }, + timeout=(10, 60)).json() + powerDetails = powerDetailsCondensed(r['Data']['QueryResults']) + r = s.post('https://www.envertecportal.com/apiAccount/Logout', timeout=(20, 40)) @@ -66,7 +92,7 @@ def getCurrentPower(userName, password, stationId): print(e) raise SystemExit(e) - return float(power) + return float(power), powerDetails # use our stateFile to determine if we have a state change @@ -95,12 +121,14 @@ conf.read('portalmonitor.ini') # retrieve current power value as reported by envertecportal if isDaylight(conf['config'].getfloat('lat'), conf['config'].getfloat('lon'), conf['config'].getint('toleranceSeconds')) or args.force: - currentPower = getCurrentPower(conf['config']['userName'], + currentPower = retrieveData(conf['config']['userName'], conf['config']['password'], conf['config']['stationId']) if args.printStatus: - print(f"Current Power: {currentPower}") + print(f"Reported Total Power: {currentPower[0]}") + for panel in currentPower[1]: + print(f"{panel['name']}: {panel['power']} - {panel['timestamp']}") if currentPower == 0: if stateCheck('FAILED', conf['config']['stateFile']):