-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrent_energy.py
42 lines (38 loc) · 1.25 KB
/
current_energy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/python
#current_energy.py
import MySQLdb
import ConfigParser
###############################################################
config = ConfigParser.RawConfigParser()
config.read('/home/pi/gfiske.cfg')
db_user = config.get('section1', 'db_user')
db_passwd = config.get('section1', 'db_passwd')
db_user = db_user.decode('base64','strict')
db_passwd = db_passwd.decode('base64','strict')
###############################################################
#connect to db
db = MySQLdb.connect("127.0.0.1", db_user, db_passwd, "energy")
#do query on trend table
myq = "select * from trend order by ts1 desc limit 1;"
cursor = db.cursor()
cursor.execute(myq)
myq = cursor.fetchone()
timestamp = str(myq[1])
temp = float(myq[2]) - 5.0
netwatts = myq[3]
oldpv = myq[4]
newpv = myq[5]
totalpv = myq[6]
hvac = myq[7]
db.commit()
db.close()
#report to user
print
print "Current timestamp: " + timestamp
print "Basement temperature is: " + str(round(temp,2))
print "Current netwatts is: " + str(round(netwatts,2))
print "Old PV system is producing: " + str(round(oldpv,2))
print "New PV system is producing: " + str(round(newpv,2))
print "Total PV production is: " + str(round(totalpv,2))
print "HVAC is using: " + str(round(hvac,2))
print