init
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.env
|
||||||
29
main.py
Normal file
29
main.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import serial
|
||||||
|
import requests
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
ntfy_token = os.environ['NTFY_Token']
|
||||||
|
shutdown_timer = 10
|
||||||
|
|
||||||
|
with serial.Serial('COM10', 115200, timeout=1) as ser:
|
||||||
|
inverter_offline_counter = 0
|
||||||
|
while True:
|
||||||
|
if ser.readline().decode().strip() == "0":
|
||||||
|
print("Inverter Online")
|
||||||
|
inverter_offline_counter = 0
|
||||||
|
elif inverter_offline_counter >= shutdown_timer:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
inverter_offline_counter += 1
|
||||||
|
print(f"Running on UPS reserve, offline for {inverter_offline_counter}s")
|
||||||
|
print(f"Inverter offline for {shutdown_timer} seconds")
|
||||||
|
requests.post("https://ntfy.fieryeagle.org/Internet-Alerts",
|
||||||
|
data="Inverter offline, shutting down".encode(encoding='utf-8'),
|
||||||
|
headers={
|
||||||
|
"Title": "Hydrogen running on reserve power",
|
||||||
|
"Authorization": f"Bearer {ntfy_token}"
|
||||||
|
}
|
||||||
|
)
|
||||||
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
pyserial
|
||||||
|
requests
|
||||||
|
python-dotenv
|
||||||
Reference in New Issue
Block a user