-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinflux
executable file
·42 lines (31 loc) · 1.17 KB
/
influx
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/env python3
import os
import time
import urllib.request
from total_connect_comfort import client
influx_server = os.environ.get('server')
influx_database = os.environ.get('database')
username = os.environ.get('username')
password = os.environ.get('password')
c = client.Client(username, password)
data = c.locations()
devices = []
timestamp = time.time()
for location in data:
for device in location['Devices']:
info = {
'id': str(device['DeviceID']),
'label': device['Name'],
'temp': device['ThermostatData']['IndoorTemperature'],
'setpoint_heat': device['ThermostatData']['ScheduleHeatSp'],
'setpoint_cool': device['ThermostatData']['ScheduleCoolSp'],
'units': 'F' if device['ThermostatData']['DisplayUnits']==1 else 'C'
}
devices.append(info)
lines = []
for device in devices:
lines.append('total_connect_comfort,location=%s measurement=%s,heat_setpoint=%s,cool_setpoint=%s %i000000000' % (
device['label'].replace(' ', '\\ '), device['temp'], device['setpoint_heat'], device['setpoint_cool'], timestamp)
)
url = 'http://%s:8086/write?db=%s' % (influx_server, influx_database)
urllib.request.urlopen(url, data='\n'.join(lines).encode('utf-8'))