-
Notifications
You must be signed in to change notification settings - Fork 0
/
intergas-exporter.py
executable file
·314 lines (278 loc) · 12.9 KB
/
intergas-exporter.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#! /usr/bin/python3
import sys, serial, time
import prometheus_client as prom
def Get_int(lsb, msb):
value = int(msb * 256 + lsb)
return value
def Get_int32(bytelist):
value = bytelist[3] * 16777216 + bytelist[2] * 65536 + bytelist[1] * 256 + bytelist[0]
return value
def Getsigned(lsb):
if lsb > 127:
value = -int((lsb ^ 255) + 1)
else:
value = lsb
return value
def Getfloat(lsb, msb):
if msb > 127:
value = -(float((msb ^ 255) + 1) * 256 - lsb) / 100
else:
value = float(msb * 256 + lsb) / 100
return value
def Get_CRC(byte1, byte2, byte3, byte4):
hexstr1 = hex(byte1)[2:]
hexstr2 = hex(byte2)[2:]
hexstr3 = hex(byte3)[2:]
hexstr4 = hex(byte4)[2:]
hexstr_list = [
hexstr1, hexstr2, hexstr3, hexstr4]
crc = ''
for string in hexstr_list:
if len(string) == 1:
string = '0' + string
crc = crc + string
return crc
def read_raw(ser, command):
try:
ser.write(command)
except Exception as e:
sys.exit("Seriele poort {} kan niet geschreven worden.\n{}: {}".format(ser.name, type(e).__name__, str(e)))
try:
raw = ser.read(32)
except Exception as e:
sys.exit("Seriele poort {} kan niet gelezen worden.\n{}: {}".format(ser.name, type(e).__name__, str(e)))
return raw
def read_status(ser):
ig_raw = read_raw(ser, b'S?\r')
data = {};
if len(ig_raw) == 32:
data['t_aanvoer'] = Getfloat(ig_raw[0] , ig_raw[1])
data['t_flow'] = Getfloat(ig_raw[2] , ig_raw[3])
data['t_retour'] = Getfloat(ig_raw[4] , ig_raw[5])
data['t_warmw'] = Getfloat(ig_raw[6] , ig_raw[7])
data['t_boiler'] = Getfloat(ig_raw[8] , ig_raw[9])
data['t_buiten'] = Getfloat(ig_raw[10], ig_raw[11])
data['ch_pressure'] = Getfloat(ig_raw[12], ig_raw[13])
data['temp_set'] = Getfloat(ig_raw[14], ig_raw[15])
data['fanspeed_set'] = Getfloat(ig_raw[16], ig_raw[17]) * 100
data['fanspeed'] = Getfloat(ig_raw[18], ig_raw[19]) * 100
data['fan_pwm'] = Getfloat(ig_raw[20], ig_raw[21]) * 10
data['io_curr'] = Getfloat(ig_raw[22], ig_raw[23])
data['displ_code'] = ig_raw[24]
data['gp_switch'] = bool(ig_raw[26] & 1 << 7)
data['tap_switch'] = bool(ig_raw[26] & 1 << 6)
data['roomtherm'] = bool(ig_raw[26] & 1 << 5)
data['pump'] = bool(ig_raw[26] & 1 << 4)
data['dwk'] = bool(ig_raw[26] & 1 << 3)
data['alarm_status'] = bool(ig_raw[26] & 1 << 2)
data['ch_cascade_relay'] = bool(ig_raw[26] & 1 << 1)
data['opentherm'] = bool(ig_raw[26] & 1 << 0)
data['gasvalve'] = bool(ig_raw[28] & 1 << 7)
data['spark'] = bool(ig_raw[28] & 1 << 6)
data['io_signal'] = bool(ig_raw[28] & 1 << 5)
data['ch_ot_disabled'] = bool(ig_raw[28] & 1 << 4)
data['low_water_pressure'] = bool(ig_raw[28] & 1 << 3)
data['pressure_sensor'] = bool(ig_raw[28] & 1 << 2)
data['burner_block'] = bool(ig_raw[28] & 1 << 1)
data['grad_flag'] = bool(ig_raw[28] & 1 << 0)
# Change display code if a fault occurred
if ig_raw[27] == 128:
fault_code = ig_raw[29]
data['displ_code'] = fault_code + 256
# Known display codes (see also https://github.com/rickvanderzwet/IntergasBoilerReader/blob/trunk/intergas_prestige_cw6.py)
# 0: "CV brandt",
# 51: "Warm water",
# 102: "CV brandt",
# 126: "CV in rust",
# 204: "Tapwater nadraaien",
# 231: "CV nadraaien",
return data
def read_status_extra(ser):
ig_raw = read_raw(ser, b'S2\r')
data = {};
if len(ig_raw) == 32:
data['tapflow'] = Getfloat(ig_raw[0], ig_raw[1])
data['pump_pwm'] = (200 - ig_raw[2]) / 2.0
data['room_override_zone1'] = Getfloat(ig_raw[4], ig_raw[5])
data['room_set_zone1'] = Getfloat(ig_raw[6], ig_raw[7])
data['room_temp_zone1'] = Getfloat(ig_raw[8], ig_raw[9])
data['room_override_zone2'] = Getfloat(ig_raw[10], ig_raw[11])
data['room_set_zone2'] = Getfloat(ig_raw[12], ig_raw[13])
data['room_temp_zone2'] = Getfloat(ig_raw[14], ig_raw[15])
data['override_outside_temp'] = Getfloat(ig_raw[16], ig_raw[17])
data['OT_master_member_id'] = ig_raw[3]
data['OT_therm_prod_version'] = ig_raw[18]
data['OT_therm_prod_type'] = ig_raw[19]
return data
def read_crc(ser):
ig_raw = read_raw(ser, b'CRC')
data = {};
if len(ig_raw) == 32:
data['interrupt_time'] = Get_int(ig_raw[0], ig_raw[1]) / float(5)
data['interrupt_load'] = Get_int(ig_raw[2], ig_raw[3]) / 6.25
data['main_load'] = Get_int(ig_raw[4], ig_raw[5]) / float(8)
freq_number = Get_int(ig_raw[6], ig_raw[7])
if freq_number > 0:
data['net_frequency'] = float(2000) / freq_number
else:
data['net_frequency'] = 0
data['voltage_reference'] = Get_int(ig_raw[8], ig_raw[9]) * 5 / float(1024)
data['checksum1'] = Get_CRC(ig_raw[24], ig_raw[25], ig_raw[26], ig_raw[27])
data['checksum2'] = Get_CRC(ig_raw[28], ig_raw[29], ig_raw[30], ig_raw[31])
return data
def read_hours(ser):
ig_raw = read_raw(ser, b'HN\r')
data = {};
if len(ig_raw) == 32:
data['line_power_connected'] = Get_int(ig_raw[0], ig_raw[1]) + ig_raw[30] * 65536
data['line_power_disconnect'] = Get_int(ig_raw[2], ig_raw[3])
data['ch_function'] = Get_int(ig_raw[4], ig_raw[5])
data['dhw_function'] = Get_int(ig_raw[6], ig_raw[7])
data['burnerstarts'] = Get_int(ig_raw[8], ig_raw[9]) + ig_raw[31] * 65536
data['ignition_failed'] = Get_int(ig_raw[10], ig_raw[11])
data['flame_lost'] = Get_int(ig_raw[12], ig_raw[13])
data['reset'] = Get_int(ig_raw[14], ig_raw[15])
data['gasmeter_cv'] = Get_int32(ig_raw[16:20]) / float(10000)
data['gasmeter_dhw'] = Get_int32(ig_raw[20:24]) / float(10000)
data['watermeter'] = Get_int32(ig_raw[24:26] + ig_raw[28].to_bytes(2,'little')) / float(10000)
data['burnerstarts_dhw'] = Get_int32(ig_raw[26:28] + ig_raw[29].to_bytes(2,'little'))
return data
def read_params(ser):
ig_raw = read_raw(ser, b'V?\r')
data = {};
if len(ig_raw) == 32:
data['heater_on'] = Getsigned(ig_raw[0])
data['comfort_mode'] = Getsigned(ig_raw[1])
data['ch_set_max'] = Getsigned(ig_raw[2])
data['dhw_set'] = Getsigned(ig_raw[3])
data['eco_days'] = Getsigned(ig_raw[4])
data['comfort_set'] = Getsigned(ig_raw[5])
data['dhw_at_night'] = Getsigned(ig_raw[6])
data['ch_at_night'] = Getsigned(ig_raw[7])
data['param_1'] = Getsigned(ig_raw[8])
data['param_2'] = Getsigned(ig_raw[9])
data['param_3'] = Getsigned(ig_raw[10])
data['param_4'] = Getsigned(ig_raw[11])
data['param_5'] = Getsigned(ig_raw[12])
data['param_6'] = Getsigned(ig_raw[13])
data['param_7'] = Getsigned(ig_raw[14])
data['param_8'] = Getsigned(ig_raw[15])
data['param_9'] = Getsigned(ig_raw[16])
data['param_A'] = Getsigned(ig_raw[17])
data['param_b'] = Getsigned(ig_raw[18])
data['param_C'] = Getsigned(ig_raw[19])
data['param_c'] = Getsigned(ig_raw[20])
data['param_d'] = Getsigned(ig_raw[21])
data['param_E'] = Getsigned(ig_raw[22])
data['param_E.'] = Getsigned(ig_raw[23])
data['param_F'] = Getsigned(ig_raw[24])
data['param_H'] = Getsigned(ig_raw[25])
data['param_n'] = Getsigned(ig_raw[26])
data['param_o'] = Getsigned(ig_raw[27])
data['param_P'] = Getsigned(ig_raw[28])
data['param_r'] = Getsigned(ig_raw[29])
data['param_F.'] = Getsigned(ig_raw[30])
return data
def read_intergas():
# Set COM port config
ser = serial.Serial()
ser.baudrate = 9600
ser.timeout=10
ser.port="/dev/ttyUSB-PL2303"
# Open COM port
try:
ser.open()
except Exception as e:
sys.exit("Fout bij het openen van {}.\n{}: {}".format(ser.name, type(e).__name__, str(e)))
unixtime_utc = time.time()
temp = []
temp.append(read_status(ser))
temp.append(read_status_extra(ser))
temp.append(read_crc(ser))
temp.append(read_hours(ser))
data = {}
if all(temp):
data['timestamp'] = unixtime_utc
for t in temp:
data.update(t)
params = read_params(ser)
# Close port and show status
try:
ser.close()
except Exception as e:
sys.exit("Fout blij sluiten van {}.\n{}: {}".format(ser.name, type(e).__name__, str(e)))
return data, params
if __name__ == '__main__':
temp = prom.Gauge('intergas_temperature_celcius' , 'Temperature in celsius', ['type'])
pressure = prom.Gauge('intergas_water_pressure_bar' , 'Water pressure in bar')
dispcode = prom.Gauge('intergas_display_code' , 'Display code')
f_speed = prom.Gauge('intergas_fanspeed_rpm' , 'Fan speed in rpm', ['type'])
f_pwm = prom.Gauge('intergas_fan_pwm' , 'Fan PWM duty cycle percentage')
p_pwm = prom.Gauge('intergas_pump_pwm' , 'Pump PWM duty cycle percentage')
flag = prom.Gauge('intergas_flag' , 'Boolean flags', ['name'])
io_curr = prom.Gauge('intergas_ionization_current_microampere', 'Ionization current in µA')
int_time = prom.Gauge('intergas_interrupt_time' , 'Interupt time')
load = prom.Gauge('intergas_load' , 'Load %', ['type'])
hours = prom.Gauge('intergas_hours' , 'Duration in hours', ['type'])
stats = prom.Gauge('intergas_stats' , 'Statistics in number of times', ['type'])
gasmeter = prom.Gauge('intergas_gasmeter' , 'Gas usage in m3', ['type'])
watermeter = prom.Gauge('intergas_watermeter' , 'Hot water usage in m3')
parameter = prom.Gauge('intergas_parameter' , 'Setting parameter', ['type'])
tapflow = prom.Gauge('intergas_tapflow' , 'Warm water tap flow')
updated = prom.Gauge('updated' , 'Client data last updated')
up = prom.Gauge('up' , 'Client status')
prom.start_http_server(8080)
while True:
ig, params = read_intergas()
if ig:
up.set(1)
updated.set(ig['timestamp'])
temp.labels('aanvoer').set(ig['t_aanvoer'])
temp.labels('flow').set(ig['t_flow'])
temp.labels('retour').set(ig['t_retour'])
temp.labels('warmwater').set(ig['t_warmw'])
temp.labels('set').set(ig['temp_set'])
pressure.set(ig['ch_pressure'])
dispcode.set(ig['displ_code'])
f_speed.labels('set').set(ig['fanspeed_set'])
f_speed.labels('measured').set(ig['fanspeed'])
f_pwm.set(ig['fan_pwm'])
p_pwm.set(ig['pump_pwm'])
io_curr.set(ig['io_curr'])
int_time.set(ig['interrupt_time'])
load.labels('interrupt').set(ig['interrupt_load'])
load.labels('main').set(ig['main_load'])
hours.labels('line_power').set(ig['line_power_connected'])
hours.labels('ch_function').set(ig['ch_function'])
hours.labels('dhw_function').set(ig['dhw_function'])
stats.labels('power_disconnect').set(ig['line_power_disconnect'])
stats.labels('burnerstarts').set(ig['burnerstarts'])
stats.labels('burnerstarts_dhw').set(ig['burnerstarts_dhw'])
stats.labels('ignition_failed').set(ig['ignition_failed'])
stats.labels('flame_lost').set(ig['flame_lost'])
stats.labels('reset').set(ig['reset'])
gasmeter.labels('cv').set(ig['gasmeter_cv'])
gasmeter.labels('warmwater').set(ig['gasmeter_dhw'])
watermeter.set(ig['watermeter'])
tapflow.set(ig['tapflow'])
flag.labels('gp_switch').set(ig['gp_switch'])
flag.labels('tap_switch').set(ig['tap_switch'])
flag.labels('roomtherm').set(ig['roomtherm'])
flag.labels('pump').set(ig['pump'])
flag.labels('dwk').set(ig['dwk'])
flag.labels('alarm_status').set(ig['alarm_status'])
flag.labels('ch_cascade_relay').set(ig['ch_cascade_relay'])
flag.labels('opentherm').set(ig['opentherm'])
flag.labels('gasvalve').set(ig['gasvalve'])
flag.labels('spark').set(ig['spark'])
flag.labels('io_signal').set(ig['io_signal'])
flag.labels('ch_ot_disabled').set(ig['ch_ot_disabled'])
flag.labels('low_water_pressure').set(ig['low_water_pressure'])
flag.labels('pressure_sensor').set(ig['pressure_sensor'])
flag.labels('burner_block').set(ig['burner_block'])
flag.labels('grad_flag').set(ig['grad_flag'])
else:
up.set(0)
for k,v in params.items():
parameter.labels(k).set(v)
time.sleep(5)