-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaikin-zappi.py
executable file
·100 lines (74 loc) · 2.92 KB
/
daikin-zappi.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
"""A simple script to print some state every 10 minutes.
The temperatures come from the daikin site.
The power consumption comes from myenergi.
"""
from datetime import datetime
import time
import logging
import gzip
from daikin import Daikin
from myenergi import MyenergiApi
_logger = logging.getLogger(__name__)
def setup_logging(zf):
# log to both file and console
gz_log_handler = logging.StreamHandler(zf)
_logger.addHandler(gz_log_handler)
stderr_log_handler = logging.StreamHandler()
_logger.addHandler(stderr_log_handler)
# prefix timestamp onto the file logger
formatter = logging.Formatter(
fmt="%(asctime)s: %(message)s", datefmt="%Y-%m-%d--%H:%M"
)
gz_log_handler.setFormatter(formatter)
_logger.setLevel(logging.DEBUG)
def monitor():
daikin = Daikin()
myenergi = MyenergiApi()
while True:
# heatpump is attached to CT#2
# direction is backwards so that app animates it correctly
stat = myenergi.get("/cgi-jstatus-Z")
zappi = stat["zappi"][0]
power = -zappi["ectp3"]
mp = daikin.management_points()
# from time to time this produces empty results
try:
sd = mp["climateControlMainZone"]["sensoryData"]["value"]
lwt = sd["leavingWaterTemperature"]["value"]
outdoor = sd["outdoorTemperature"]["value"]
room = sd["roomTemperature"]["value"]
tc = mp["climateControlMainZone"]["temperatureControl"]["value"]
# should this be "auto", or "heating" ?
target = tc["operationModes"]["auto"]["setpoints"]["roomTemperature"]["value"]
offs = tc["operationModes"]["auto"]["setpoints"]["leavingWaterOffset"]["value"]
tc = mp["climateControlMainZone"]["temperatureControl"]["value"]
# should this be "auto", or "heating" ?
target = tc["operationModes"]["auto"]["setpoints"]["roomTemperature"]["value"]
hwt = mp["domesticHotWaterTank"]["sensoryData"]["value"]
hw = hwt["tankTemperature"]["value"]
_logger.info(
"power=%4d outdoor=%2d room=%2.1f / %2.1f hw=%d lwt=%d (offs=%d)",
power,
outdoor,
room,
target,
hw,
lwt,
offs,
)
except KeyError:
_logger.warning("Hmm - got a key error")
# Daikin API requests are limited to 200 per day
# They suggest one per 10 minutes, which leaves around 50 for
# actually controlling the system. Or perhaps downloading
# consumption figures at the end of the day.
time.sleep(600)
def main():
now = datetime.now()
tstamp = now.strftime("%Y%m%d-%H%M")
with gzip.open(filename="/tmp/daikin." + tstamp + ".log.gz", mode="wt") as zf:
setup_logging(zf)
monitor()
if __name__ == "__main__":
main()