--- /dev/null
+#!/usr/bin/env python3
+
+import requests
+import time
+import sys
+import configparser
+from suntime import Sun
+from optparse import OptionParser
+
+parser = OptionParser(usage="usage: %prog [options]")
+parser.add_option("-s",
+ "--status",
+ action="store_true",
+ dest="printStatus",
+ help="Print Status Information",
+ default=False)
+parser.add_option("-f",
+ "--force",
+ action="store_true",
+ dest="force",
+ help="Force retrieval of Power value",
+ default=False)
+(options, args) = parser.parse_args()
+
+
+def isDaylight(lat, lon, toleranceSeconds):
+ daylight = False
+ sun = Sun(lat, lon)
+ sunriseTimestamp = int(sun.get_local_sunrise_time().timestamp())
+ sunsetTimestamp = int(sun.get_local_sunset_time().timestamp())
+ nowTimestamp = int(time.time())
+
+ if ((sunriseTimestamp + toleranceSeconds) < nowTimestamp) and (
+ (sunsetTimestamp - toleranceSeconds) > nowTimestamp):
+ daylight = True
+
+ return daylight
+
+
+def getCurrentPower(userName, password, stationId):
+ with requests.Session() as s:
+ r = s.post('https://www.envertecportal.com/apiaccount/login',
+ data={
+ 'userName': userName,
+ 'pwd': password
+ },
+ timeout=(10, 30))
+
+ r = s.post('https://www.envertecportal.com/ApiStations/getStationInfo',
+ data={
+ 'stationId': stationId
+ },
+ timeout=(10, 60)).json()
+ power = r['Data']['Power']
+
+ r = s.post('https://www.envertecportal.com/apiAccount/Logout',
+ timeout=(10, 30))
+
+ return float(power)
+
+
+# read configuration file
+conf = configparser.ConfigParser()
+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 options.force:
+ currentPower = getCurrentPower(conf['config']['userName'],
+ conf['config']['password'],
+ conf['config']['stationId'])
+
+ if options.printStatus:
+ print('Current Power: ' + str(currentPower))
+
+ if currentPower == 0:
+ print('Error: Power dropped to 0 but we should have daylight!')
+ sys.exit(1)