return float(power)
+# use our stateFile to determine if we have a state change
+# used to decide if we print something - thus generate a mail - later on
+def stateCheck(newState, stateFile):
+ try:
+ with open(stateFile, "r") as f:
+ oldState = f.read()
+ except FileNotFoundError:
+ oldState = "NULL"
+
+ if newState == oldState:
+ change = False
+ else:
+ change = True
+ with open(stateFile, "w") as f:
+ f.write(newState)
+
+ return change
+
+
# read configuration file
conf = configparser.ConfigParser()
conf.read('portalmonitor.ini')
print(f"Current Power: {currentPower}")
if currentPower == 0:
- print('Error: Power dropped to 0 but we should have daylight!')
+ if stateCheck('FAILED', conf['config']['stateFile']):
+ print('Error: Power dropped to 0 but we should have daylight!')
sys.exit(1)
+ else:
+ if stateCheck('OK', conf['config']['stateFile']):
+ print(f"Resolved: Inverter reports {currentPower}W")