-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnergyLink.py
77 lines (60 loc) · 2.03 KB
/
EnergyLink.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# This Python Script uses Python 3.7
# Author: Andre Seesink
# Version 1.0 - date 15-02-2019 initial release
# Version 1.1 - date 16-02-2019 time format changed
# date format changed
#
# http:// <Homewizard-ip-adres>/<Homewizard-password>
# Read Meter: "/el/get/0/readings"
#
# fill in the url and Password variable.
import json
import http.client
import datetime
ExportString = ""
url = "<fill in your ip>"
Password = "<fill in your password>"
command = "/el/get/0/readings"
TijdStip = datetime.datetime.now()
tijd = TijdStip.strftime("%H:%M")
datum = TijdStip.strftime("%d-%m-%y")
connection = http.client.HTTPConnection(url)
connection.request("GET", "/" + Password + command)
response = connection.getresponse()
connection.close()
#print("Status pagina oproepen Energie Link: ", response.status, response.reason, "\n")
#print(data)
data = json.loads(response.read())
AantalRecords = len(data['response'])
def Electricity():
#print("Electriciteit")
ELtariff = data["response"] [a] ['tariff']
ELconsumed = data["response"] [a] ["consumed"]
ELproduced = data["response"] [a] ['produced']
if ELtariff == 1:
#print("Laag tarief: ",ELtariff)
#print("Verbruikt: ", ELconsumed)
#print("Geproduceerd: ",ELproduced)
return ELconsumed
if ELtariff == 2:
#print("Hoog tarief: ",ELtariff)
#print("Verbruikt: ", ELconsumed)
#print("Geproduceerd: ",ELproduced)
return ELconsumed
def Gas():
#print("Gas")
ELconsumed = data["response"] [a] ["consumed"]
ELtimestamp = data["response"] [a] ['timestamp']
#print("Verbruikt: ", ELconsumed)
#print("Tijd: ",ELtimestamp)
return ELconsumed
a=0
while a < AantalRecords:
ELtype = data["response"] [a] ["type"]
if ELtype == 'electricity':
ExportString = ExportString + str(Electricity()) + ","
if ELtype == 'gas':
ExportString = ExportString + str(Gas())
a=a+1
ExportString = datum + "," + tijd + "," + ExportString
print(ExportString)