-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimport_influxdb.py
More file actions
executable file
·115 lines (99 loc) · 3.28 KB
/
Copy pathimport_influxdb.py
File metadata and controls
executable file
·115 lines (99 loc) · 3.28 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python3
import json
import influxdb
import time
from lennox_lcc import Client, LCC
from settings import *
client = Client(CLIENT_ID, IP)
client.command({
"systemControl": {
"diagControl": {
"level": 2
}
}
})
client.request_data(["/devices", "/equipments", "/zones"])
lcc = LCC()
influx = influxdb.InfluxDBClient(host=INFLUXDB_HOSTNAME, port=INFLUXDB_PORT, database=INFLUXDB_DATABASE)
def log_diagnostics(lcc: LCC):
metrics = set()
measurements = []
for equipment in lcc.equipments.values():
for d in equipment.diagnostics.values():
if d.name in ("Cooling Rate", "Heating Rate", "Indoor Blower Power"):
measurement_name = d.name.lower().replace(" ", "_")
if measurement_name in metrics: # 2 Heating Rate
measurement_name = measurement_name + "_2"
metrics.add(measurement_name)
measurements.append({
"measurement": "%",
"tags": {
"domain": "sensor",
"entity_id": measurement_name
},
"fields": {
"value": float(d.value)
}
})
influx.write_points(measurements, time_precision='s')
def log_zonestatus(lcc: LCC):
measurements = []
for zone in lcc.zones.values():
if zone.temperature > 0:
measurements.append({
"measurement": "°F",
"tags": {
"domain": "sensor",
"entity_id": "ChillCat_temp_2"
},
"fields": {
"value": float(zone.temperature)
}
})
if zone.humidity > 0:
measurements.append({
"measurement": "%",
"tags": {
"domain": "sensor",
"entity_id": "ChillCat_humidity_2"
},
"fields": {
"value": float(zone.humidity)
}
})
influx.write_points(measurements, time_precision='s')
def log_system_status(lcc: LCC):
measurements = []
temp = lcc.systemStatus.outdoorTemperature
if temp > 0:
measurements.append({
"measurement": "°F",
"tags": {
"domain": "sensor",
"entity_id": "ChillCat_outdoor_temp"
},
"fields": {
"value": float(temp)
}
})
influx.write_points(measurements, time_precision='s')
for message in client.messages():
if "Data" in message:
lcc.load_data(message["Data"])
if "equipments" in message["Data"]:
log_diagnostics(lcc)
elif "zones" in message["Data"]:
# log_zonestatus(lcc)
pass
elif "system" in message["Data"] and "status" in message["Data"]["system"]:
log_system_status(lcc)
elif not message:
client.command({
"systemControl": {
"diagControl": {
"level": 2
}
}
})
client.request_data(["/devices", "/equipments", "/zones"])
#print(json.dumps(message, indent=4, sort_keys=True))