-
Notifications
You must be signed in to change notification settings - Fork 3
/
ultraheat.py
77 lines (66 loc) · 3.24 KB
/
ultraheat.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
##################################################################################################
# Script to read telegram from Landis&Gyr Ultraheat 2WR5 'Stadsverwarming' #
# Might also work for Ultraheat UH50 (T550) #
# #
# This script sends the MJ and m3 values to Domoticz on the given IDX #
# Add a custom sensor with MJ and m3 Y-axis settings (Add through dummy sensor hardware) #
# #
# Source: #
# Script from Magnat in https://gathering.tweakers.net/forum/list_messages/1535019 #
# #
# Requirement: Python3 #
##################################################################################################
import serial
import re
import requests
from time import sleep
# domoticz URL like: http://192.168.38.110:8080
domoticzUrl="http://192.168.38.110:8080"
kjIDX=3788
m3IDX=3789
conn = serial.Serial('/dev/serial/by-id/usb-Silicon_Labs_CP2104_USB_to_UART_Bridge_Controller_010658AC-if00-port0',
baudrate=300,
bytesize=serial.SEVENBITS,
parity=serial.PARITY_EVEN,
stopbits=serial.STOPBITS_TWO,
timeout=1,
xonxoff=0,
rtscts=0
)
# Wake up
conn.setRTS(False)
conn.setDTR(False)
sleep(5)
conn.setDTR(True)
conn.setRTS(True)
# send /?!
conn.write(str.encode("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2F\x3F\x21\x0D\x0A"))
# Read at 300 BAUD, typenr
print(conn.readline())
print(conn.readline())
# Read at 2400 BAUD, higher might be possible
conn.baudrate=2400
# Read 18 lines (the size of the telegram)
counter = 0
try:
while counter < 18:
line=conn.readline().decode('utf-8')
print(line)
# This will match on the first line of the telegram with GJ and m3 values.
matchObj = re.match(r".+6\.8\(([0-9]{4}\.[0-9]{3})\*GJ\)6\.26\(([0-9]{5}\.[0-9]{2})\*m3\)9\.21\(([0-9]{8})\).+", line, re.I|re.S)
if matchObj:
kjValue=round(float(matchObj.group(1)) * 1000)
m3Value=round(float(matchObj.group(2)) * 1000)
print("GJ : " + str(kjValue))
print("m3: " + str(m3Value))
# Send kJ value to kJ IDX
url=domoticzUrl + "/json.htm?type=command¶m=udevice&idx=" + str(kjIDX) + "&nvalue=0&svalue=" + str(kjValue)
print(url)
requests.get(url)
# Send m3 value to m3 IDX
url=domoticzUrl + "/json.htm?type=command¶m=udevice&idx=" + str(m3IDX) + "&nvalue=0&svalue=" + str(m3Value)
print(url)
requests.get(url)
counter = counter + 1
finally:
conn.close()