Skip to content

Instantly share code, notes, and snippets.

@h3xagn
Created June 10, 2024 20:09
Show Gist options
  • Save h3xagn/7eefed7972a138ad3c5578d56683fa2a to your computer and use it in GitHub Desktop.
Save h3xagn/7eefed7972a138ad3c5578d56683fa2a to your computer and use it in GitHub Desktop.
Building a home energy monitoring dashboard for your clevrHome
import time
import requests
from datetime import datetime
# URL to read the data from Geyserwala
URL = "http://192.168.2.20/api/value?f=status,tank-temp,collector-temp,element-demand,pump-status,element-seconds,element-cycles,pump-seconds,pump-cycles"
# Connect to Geyserwala and read the parameters
while True:
try:
request = requests.get(URL, timeout=10)
data = request.json()
# Get the current timestamp
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
for key, value in data.items():
# Create a new key for the tagname
updated_key = "gw_" + key.replace("-", "_")
# Convert status to 0 or 1
if key == "pump-status" or key == "element-demand":
updated_value = 1 if value == True else 0
# Convert seconds to minutes
elif key == "pump-seconds" or key == "element-seconds":
updated_value = value / 60
updated_key = updated_key.replace("_seconds", "_minutes")
# Convert status to 0 or 1
elif key == "status":
updated_value = 0 if value == "Idle" else 1
else:
updated_value = value
print(f"{updated_key}: {updated_value} ({value})")
# Write the data to the database
WriteSQLToDB(timestamp, updated_key, updated_value)
except:
print("ERROR - Could not connect to Geyserwala.")
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment