forked from hahn-th/homematicip-rest-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump_devicevalues.py
58 lines (44 loc) · 2.14 KB
/
dump_devicevalues.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
# coding=utf-8
import os.path
import config
import homematicip
homematicip.init(config.ACCESS_POINT)
homematicip.set_auth_token(config.AUTH_TOKEN)
home = homematicip.Home()
home.get_current_state()
def write_shutter(device):
if not os.path.isfile("shutter.csv"):
with open("shutter.csv", "w") as csv:
csv.write("name;timestamp;open/close\n")
with open("shutter.csv", "a") as csv:
csv.write("{};{};{}\n".format(device.id, unicode(device.lastStatusUpdate), d.open))
def write_heatingthermostat(device):
if not os.path.isfile("heatingthermostat.csv"):
with open("heatingthermostat.csv", "w") as csv:
csv.write("name;timestamp;valveposition\n")
with open("heatingthermostat.csv", "a") as csv:
csv.write("{};{};{}\n".format(device.id, unicode(device.lastStatusUpdate), d.valvePosition))
def write_plugableswitchmeasuring(device):
if not os.path.isfile("plugableswitchmeasuring.csv"):
with open("plugableswitchmeasuring.csv", "w") as csv:
csv.write("name;timestamp;on;currentPowerConsumption;energyCounter\n")
with open("plugableswitchmeasuring.csv", "a") as csv:
csv.write(
"{};{};{};{};{}\n".format(device.id, unicode(device.lastStatusUpdate), d.on, d.currentPowerConsumption,
d.energyCounter))
def write_wallmountedthermostatpro(device):
if not os.path.isfile("wallmountedthermostatpro.csv"):
with open("wallmountedthermostatpro.csv", "w") as csv:
csv.write("name;timestamp;humidity;actualTemperature\n")
with open("wallmountedthermostatpro.csv", "a") as csv:
csv.write(
"{};{};{}%;{}°C\n".format(device.id, unicode(device.lastStatusUpdate), d.humidity, d.actualTemperature))
for d in home.devices:
if isinstance(d, homematicip.ShutterContact):
write_shutter(d)
elif isinstance(d, homematicip.HeatingThermostat):
write_heatingthermostat(d)
elif isinstance(d, homematicip.PlugableSwitchMeasuring):
write_plugableswitchmeasuring(d)
elif isinstance(d, homematicip.WallMountedThermostatPro):
write_wallmountedthermostatpro(d)