From e05f25077e520aad8d63d70492f0c725cb5a0e52 Mon Sep 17 00:00:00 2001 From: Pim van den Berg Date: Thu, 3 Dec 2020 13:39:06 +0100 Subject: [PATCH] feat(itho-wpu): use (hardcoded) datatype from getdatatype in datalog Action "getdatatype" returns a list of bytes representing the datatype for each field in action "getdatalog". This is a subset of these datatypes: * 0x0: integer (1 byte) * 0xc: integer (1 byte) * 0x10: unsigned integer (2 bytes) * 0x92: 2 decimal signed float (2 bytes) --- itho-wpu.py | 69 ++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/itho-wpu.py b/itho-wpu.py index 21f0a4f..7a56b57 100755 --- a/itho-wpu.py +++ b/itho-wpu.py @@ -219,48 +219,51 @@ def process_datalog(response): # 2 = SignedIntDec2 Field = namedtuple('Field', 'index type label description') datalog = [ - Field(0, 2, "t_out", "Buitentemperatuur"), - Field(2, 2, "t_boiltop", "Boiler laag"), - Field(4, 2, "t_boildwn", "Boiler hoog"), - Field(6, 2, "t_evap", "Verdamper temperatuur"), - Field(8, 2, "t_suct", "Zuiggas temperatuur"), - Field(10, 2, "t_disc", "Persgas temperatuur"), - Field(12, 2, "t_cond", "Vloeistof temperatuur"), - Field(14, 2, "t_source_r", "Naar bron"), - Field(16, 2, "t_source_s", "Van bron"), - Field(18, 2, "t_ch_supp", "CV aanvoer"), - Field(20, 2, "t_ch_ret", "CV retour"), - Field(22, 2, "p_sens", "Druksensor (Bar)"), - Field(24, 2, "i_tr1", "Stroom trafo 1 (A)"), - Field(26, 2, "i_tr2", "Stroom trafo 2 (A)"), - Field(34, 1, "in_flow", "Flow sensor bron (l/h)"), - Field(37, 0, "out_ch", "Snelheid cv pomp (%)"), - Field(38, 0, "out_src", "Snelheid bron pomp (%)"), - Field(39, 0, "out_dhw", "Snelheid boiler pomp (%)"), - Field(44, 0, "out_c1", "Compressor aan/uit"), - Field(45, 0, "out_ele", "Elektrisch element aan/uit"), - Field(46, 0, "out_trickle", "Trickle heating aan/uit"), - Field(47, 0, "out_fault", "Fout aanwezig (0=J, 1=N)"), - Field(48, 0, "out_fc", "Vrijkoelen actief (0=uit, 1=aan)"), - Field(51, 2, "ot_room", "Kamertemperatuur"), - Field(55, 0, "ot_mod", "Warmtevraag (%)"), - Field(56, 0, "state", "State (0=init,1=uit,2=CV,3=boiler,4=vrijkoel,5=ontluchten)"), - Field(57, 0, "sub_state", "Substatus (255=geen)"), - Field(67, 0, "fault_reported", "Fout gevonden (foutcode)"), - Field(92, 1, "tr_fc", "Vrijkoelen interval (sec)"), + Field(0, 0x92, "t_out", "Buitentemperatuur"), + Field(2, 0x92, "t_boiltop", "Boiler laag"), + Field(4, 0x92, "t_boildwn", "Boiler hoog"), + Field(6, 0x92, "t_evap", "Verdamper temperatuur"), + Field(8, 0x92, "t_suct", "Zuiggas temperatuur"), + Field(10, 0x92, "t_disc", "Persgas temperatuur"), + Field(12, 0x92, "t_cond", "Vloeistof temperatuur"), + Field(14, 0x92, "t_source_r", "Naar bron"), + Field(16, 0x92, "t_source_s", "Van bron"), + Field(18, 0x92, "t_ch_supp", "CV aanvoer"), + Field(20, 0x92, "t_ch_ret", "CV retour"), + Field(22, 0x92, "p_sens", "Druksensor (Bar)"), + Field(24, 0x92, "i_tr1", "Stroom trafo 1 (A)"), + Field(26, 0x92, "i_tr2", "Stroom trafo 2 (A)"), + Field(34, 0x10, "in_flow", "Flow sensor bron (l/h)"), + Field(37, 0x0, "out_ch", "Snelheid cv pomp (%)"), + Field(38, 0x0, "out_src", "Snelheid bron pomp (%)"), + Field(39, 0x0, "out_dhw", "Snelheid boiler pomp (%)"), + Field(44, 0xc, "out_c1", "Compressor aan/uit"), + Field(45, 0xc, "out_ele", "Elektrisch element aan/uit"), + Field(46, 0xc, "out_trickle", "Trickle heating aan/uit"), + Field(47, 0xc, "out_fault", "Fout aanwezig (0=J, 1=N)"), + Field(48, 0xc, "out_fc", "Vrijkoelen actief (0=uit, 1=aan)"), + Field(51, 0x92, "ot_room", "Kamertemperatuur"), + Field(55, 0x0, "ot_mod", "Warmtevraag (%)"), + Field(56, 0x0, "state", "State (0=init,1=uit,2=CV,3=boiler,4=vrijkoel,5=ontluchten)"), + Field(57, 0x0, "sub_state", "Substatus (255=geen)"), + Field(67, 0x0, "fault_reported", "Fout gevonden (foutcode)"), + Field(92, 0x10, "tr_fc", "Vrijkoelen interval (sec)"), ] message = response[5:] measurements = {} for d in datalog: - if d.type == 0: + if d.type == 0x0 or d.type == 0x12: m = message[d.index:d.index+1] num = int(m[0], 0) - elif d.type == 1: + elif d.type == 0x10: m = message[d.index:d.index+2] num = ((int(m[0], 0) << 8) + int(m[1], 0)) - elif d.type == 2: + elif d.type == 0x92: m = message[d.index:d.index+2] - num = round(((int(m[0], 0) << 8) + int(m[1], 0)) / 100.0, 2) + num = ((int(m[0], 0) << 8) + int(m[1], 0)) + if num >= 32768: + num -= 65536 + num = round(num / 100, 2) logger.info(f"{d.description}: {num}") measurements[d.label] = num return measurements