]> git.sven.stormbind.net Git - sven/scripts.git/commitdiff
Output per panel / micro inverter power information
authorSven Höxter <sven@stormbind.net>
Mon, 14 Apr 2025 12:48:22 +0000 (14:48 +0200)
committerSven Höxter <sven@stormbind.net>
Mon, 14 Apr 2025 12:48:22 +0000 (14:48 +0200)
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.

home/portalmonitor.py

index c8b732b46afb64181df4c0cc7cefed2e16747209..993aa656b795c15587e3c39307ed3306a6355240 100755 (executable)
@@ -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']):