00_THZ.pm 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220
  1. ##############################################
  2. # 00_THZ
  3. # $Id: 00_THZ.pm 15219 2017-10-09 19:01:39Z immi $
  4. # by immi 10/2017
  5. my $thzversion = "0.171";
  6. # this code is based on the hard work of Robert; I just tried to port it
  7. # http://robert.penz.name/heat-pump-lwz/
  8. ########################################################################################
  9. #
  10. # This programm is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # The GNU General Public License can be found at
  16. # http://www.gnu.org/copyleft/gpl.html.
  17. # A copy is found in the textfile GPL.txt and important notices to the license
  18. # from the author is found in LICENSE.txt distributed with these scripts.
  19. #
  20. # This script is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. # GNU General Public License for more details.
  24. #
  25. ########################################################################################
  26. package main;
  27. use strict;
  28. use warnings;
  29. use Time::HiRes qw(gettimeofday);
  30. use feature ":5.10";
  31. use SetExtensions;
  32. use Blocking;
  33. sub THZ_Read($);
  34. sub THZ_ReadAnswer($);
  35. sub THZ_Ready($);
  36. sub THZ_Write($$);
  37. sub THZ_Parse1($$);
  38. sub THZ_checksum($);
  39. sub THZ_replacebytes($$$);
  40. sub THZ_decode($);
  41. sub THZ_overwritechecksum($);
  42. sub THZ_encodecommand($$);
  43. sub hex2int($);
  44. sub quaters2time($);
  45. sub time2quaters($);
  46. sub THZ_debugread($);
  47. sub THZ_GetRefresh($);
  48. sub THZ_Refresh_all_gets($);
  49. sub THZ_Get_Comunication($$);
  50. sub THZ_PrintcurveSVG;
  51. sub THZ_RemoveInternalTimer($);
  52. sub THZ_Set($@);
  53. sub function_heatSetTemp($$);
  54. sub THZ_Get($@);
  55. ########################################################################################
  56. #
  57. # %parsinghash - known type of message structure
  58. #
  59. ########################################################################################
  60. my %parsinghash = (
  61. #msgtype => parsingrule
  62. "01pxx206" => [["p37Fanstage1AirflowInlet: ", 4, 4, "hex", 1],[" p38Fanstage2AirflowInlet: ", 8, 4, "hex", 1], [" p39Fanstage3AirflowInlet: ", 12, 4, "hex", 1],
  63. [" p40Fanstage1AirflowOutlet: ", 16, 4, "hex", 1],[" p41Fanstage2AirflowOutlet: ", 20, 4, "hex", 1], [" p42Fanstage3AirflowOutlet: ", 24, 4, "hex", 1],
  64. [" p43UnschedVent3: ", 28, 4, "hex", 1], [" p44UnschedVent2: ", 32, 4, "hex", 1], [" p45UnschedVent1: ", 36, 4, "hex", 1],
  65. [" p46UnschedVent0: ", 40, 4, "hex", 1], [" p75PassiveCooling: ", 44, 4, "hex", 1]
  66. ],
  67. "01pxx214" => [["p37Fanstage1AirflowInlet: ", 4, 2, "hex", 1],[" p38Fanstage2AirflowInlet: ", 6, 2, "hex", 1], [" p39Fanstage3AirflowInlet: ", 8, 2, "hex", 1],
  68. [" p40Fanstage1AirflowOutlet: ", 10, 2, "hex", 1],[" p41Fanstage2AirflowOutlet: ", 12, 2, "hex", 1], [" p42Fanstage3AirflowOutlet: ", 14, 2, "hex", 1],
  69. [" p43UnschedVent3: ", 16, 4, "hex", 1], [" p44UnschedVent2: ", 20, 4, "hex", 1], [" p45UnschedVent1: ", 24, 4, "hex", 1],
  70. [" p46UnschedVent0: ", 28, 4, "hex", 1], [" p75PassiveCooling: ", 32, 2, "hex", 1]
  71. ],
  72. "03pxx206" => [["UpTempLimitDefrostEvaporatorEnd: ", 4, 4, "hex", 10], [" MaxTimeDefrostEvaporator: ", 8, 4, "hex", 1], [" LimitTempCondenserElectBoost: ", 12, 4, "hex", 10],
  73. [" LimitTempCondenserDefrostTerm: ", 16, 4, "hex", 10], [" CompressorRestartDelay: ", 20, 2, "hex", 1], [" MainFanSpeed: ", 22, 2, "hex", 1]
  74. ],
  75. "04pxx206" => [["MaxDefrostDurationAAExchenger: ", 4, 2, "hex", 1], [" DefrostStartThreshold: ", 6, 4, "hex", 10], [" VolumeFlowFilterReplacement: ", 10, 4, "hex", 1]
  76. ],
  77. "05pxx206" => [["p13GradientHC1: ", 4, 4, "hex", 10], [" p14LowEndHC1: ", 8, 4, "hex", 10], [" p15RoomInfluenceHC1: ", 12, 2, "hex", 10],
  78. [" p16GradientHC2: ", 14, 4, "hex", 10], [" p17LowEndHC2: ", 18, 4, "hex", 10], [" p18RoomInfluenceHC2: ", 22, 2, "hex", 10],
  79. [" p19FlowProportionHC1: ", 24, 4, "hex", 1], [" p20FlowProportionHC2: ", 28, 4, "hex", 1], [" MaxSetHeatFlowTempHC1: ", 32, 4, "hex", 10],
  80. [" MinSetHeatFlowTempHC1: ", 36, 4, "hex", 10], [" MaxSetHeatFlowTempHC2: ", 40, 4, "hex", 10], [" MinSetHeatFlowTempHC2: ", 44, 4, "hex", 10],
  81. ],
  82. "06pxx206" => [["p21Hyst1: ", 4, 2, "hex", 10], [" p22Hyst2: ", 6, 2, "hex", 10], [" p23Hyst3: ", 8, 2, "hex", 10],
  83. [" p24Hyst4: ", 10, 2, "hex", 10], [" p25Hyst5: ", 12, 2, "hex", 10], [" p26Hyst6: ", 14, 2, "hex", 10],
  84. [" p27Hyst7: ", 16, 2, "hex", 10], [" p28Hyst8: ", 18, 2, "hex", 10], [" p29HystAsymmetry: ", 20, 2, "hex", 1],
  85. [" p30integralComponent: ", 22, 4, "hex", 1], [" p31MaxBoostStages: ", 26, 2, "hex", 1], [" MaxHeatFlowTemp: ", 28, 4, "hex", 10],
  86. [" p49SummerModeTemp: ", 32, 4, "hex", 10], [" p50SummerModeHysteresis: ", 36, 4, "hex", 10], [" p77OutTempAdjust: ", 40, 4, "hex", 1],
  87. [" p78DualModePoint: ", 44, 4, "hex2int", 10], [" p79ReHeatingDelay: ", 48, 2, "hex", 1]
  88. ],
  89. "07pxx206" => [["p32HystDHW: ", 4, 2, "hex", 10], [" p33BoosterTimeoutDHW: ", 6, 2, "hex", 1], [" p34TempLimitBoostDHW: ", 8, 4, "hex2int", 10], [" p35PasteurisationInterval: ", 12, 2, "hex", 1],
  90. [" p36MaxDurationDHWLoad: ", 14, 2, "hex", 1], [" PasteurisationTemp: ", 16, 4, "hex", 10], [" MaxBoostStagesDHW: ", 20, 2, "hex", 1],
  91. [" p84EnableDHWBuffer: ", 22, 2, "hex", 1]
  92. ],
  93. "08pxx206" => [["p80EnableSolar: ", 4, 2, "hex", 1], [" p81DiffTempSolarLoading: ", 6, 4, "hex", 10], [" p82DelayCompStartSolar: ", 10, 2, "hex", 1],
  94. [" p84DHWTempSolarMode: ", 12, 4, "hex", 10], [" HystDiffTempSolar: ", 16, 4, "hex", 10], [" CollectLimitTempSolar: ", 20, 4, "hex", 10]
  95. ],
  96. "09his" => [["compressorHeating: ", 4, 4, "hex", 1], [" compressorCooling: ", 8, 4, "hex", 1],
  97. [" compressorDHW: ", 12, 4, "hex", 1], [" boosterDHW: ", 16, 4, "hex", 1],
  98. [" boosterHeating: ", 20, 4, "hex", 1]
  99. ],
  100. "09his206" => [["operatingHours1: ", 4, 4, "hex", 1], [" operatingHours2: ", 8, 4, "hex", 1],
  101. [" heatingHours: ", 12, 4, "hex", 1], [" DHWhours: ", 16, 4, "hex", 1],
  102. [" coolingHours: ", 20, 4, "hex", 1]
  103. ],
  104. "0Apxx206" => [["p54MinPumpCycles: ", 4, 2, "hex", 1], [" p55MaxPumpCycles: ", 6, 4, "hex", 1], [" p56OutTempMaxPumpCycles: ", 10, 4, "hex", 10],
  105. [" p57OutTempMinPumpCycles: ", 14, 4, "hex", 10], [" p58SuppressTempCaptPumpStart: ", 18, 4, "hex", 1]
  106. ],
  107. "0Bpxx206" => [["pHTG1StartTime: ", 4, 4, "hex2time", 1], [" pHTG1EndTime: ", 8, 4, "hex2time", 1], [" pHTG1Weekdays: ", 12, 2, "hex2wday", 1],
  108. [" pHTG1Enable: ", 14, 2, "hex", 1], [" pHTG2StartTime: ", 16, 4, "hex2time", 1], [" pHTG2EndTime: ", 20, 4, "hex2time", 1],
  109. [" pHTG2Weekdays: ", 24, 2, "hex2wday", 1], [" pHTG2Enable: ", 26, 2, "hex", 1]
  110. ],
  111. "0Cpxx206" => [["pDHWStartTime: ", 4, 4, "hex2time", 1], [" pDHWEndTime: ", 8, 4, "hex2time", 1], [" pDHWWeekdays: ", 12, 2, "hex2wday", 1],
  112. [" pDHWEnable: ", 14, 2, "hex", 1],
  113. ],
  114. "0Dpxx206" => [["pFAN1StartTime: ", 4, 4, "hex2time", 1], [" pFAN1EndTime: ", 8, 4, "hex2time", 1], [" pFAN1Weekdays: ", 12, 2, "hex2wday", 1],
  115. [" pFAN1Enable: ", 14, 2, "hex", 1], [" pFAN2StartTime: ", 16, 4, "hex2time", 1], [" pFAN2EndTime: ", 20, 4, "hex2time", 1],
  116. [" pFAN2Weekdays: ", 24, 2, "hex2wday", 1], [" pFAN2Enable: ", 26, 2, "hex", 1]
  117. ],
  118. "0Epxx206" => [["p59RestartBeforeSetbackEnd: ", 4, 4, "hex", 1]
  119. ],
  120. "0Fpxx206" => [["pA0DurationUntilAbsenceStart: ", 4, 4, "hex", 10], [" pA0AbsenceDuration: ", 8, 4, "hex", 10], [" pA0EnableAbsenceProg: ", 12, 2, "hex", 1]
  121. ],
  122. "10pxx206" => [["p70StartDryHeat: ", 4, 2, "hex", 1], [" p71BaseTemp: ", 6, 4, "hex", 10], [" p72PeakTemp: ", 10, 4, "hex", 10],
  123. [" p73TempDuration: ", 14, 4, "hex", 1], [" p74TempIncrease: ", 18, 4, "hex", 10]
  124. ],
  125. "16sol" => [["collector_temp: ", 4, 4, "hex2int", 10], [" dhw_temp: ", 8, 4, "hex2int", 10],
  126. [" flow_temp: ", 12, 4, "hex2int", 10], [" ed_sol_pump_temp: ", 16, 4, "hex2int", 10],
  127. [" x20: ", 20, 4, "hex2int", 1], [" x24: ", 24, 4, "hex2int", 1],
  128. [" x28: ", 28, 4, "hex2int", 1], [" x32: ", 32, 2, "hex2int", 1]
  129. ],
  130. "17pxx206" => [["p01RoomTempDay: ", 4, 4, "hex", 10], [" p02RoomTempNight: ", 8, 4, "hex", 10],
  131. [" p03RoomTempStandby: ", 12, 4, "hex", 10], [" p04DHWsetTempDay: ", 16, 4, "hex", 10],
  132. [" p05DHWsetTempNight: ", 20, 4, "hex", 10], [" p06DHWsetTempStandby: ", 24, 4, "hex", 10],
  133. [" p07FanStageDay: ", 28, 2, "hex", 1], [" p08FanStageNight: ", 30, 2, "hex", 1],
  134. [" p09FanStageStandby: ", 32, 2, "hex", 1], [" p10HCTempManual: ", 34, 4, "hex", 10],
  135. [" p11DHWsetTempManual: ", 38, 4, "hex", 10], [" p12FanStageManual: ", 42, 2, "hex", 1],
  136. ],
  137. "D1last" => [["number_of_faults: ", 4, 2, "hex", 1],
  138. [" fault0CODE: ", 8, 2, "faultmap", 1], [" fault0TIME: ", 12, 4, "turnhex2time", 1], [" fault0DATE: ", 16, 4, "turnhexdate", 1],
  139. [" fault1CODE: ", 20, 2, "faultmap", 1], [" fault1TIME: ", 24, 4, "turnhex2time", 1], [" fault1DATE: ", 28, 4, "turnhexdate", 1],
  140. [" fault2CODE: ", 32, 2, "faultmap", 1], [" fault2TIME: ", 36, 4, "turnhex2time", 1], [" fault2DATE: ", 40, 4, "turnhexdate", 1],
  141. [" fault3CODE: ", 44, 2, "faultmap", 1], [" fault3TIME: ", 48, 4, "turnhex2time", 1], [" fault3DATE: ", 52, 4, "turnhexdate", 1]
  142. ],
  143. "D1last206" => [["number_of_faults: ", 4, 2, "hex", 1],
  144. [" fault0CODE: ", 8, 4, "faultmap", 1], [" fault0TIME: ", 12, 4, "hex2time", 1], [" fault0DATE: ", 16, 4, "hexdate", 1],
  145. [" fault1CODE: ", 20, 4, "faultmap", 1], [" fault1TIME: ", 24, 4, "hex2time", 1], [" fault1DATE: ", 28, 4, "hexdate", 1],
  146. [" fault2CODE: ", 32, 4, "faultmap", 1], [" fault2TIME: ", 36, 4, "hex2time", 1], [" fault2DATE: ", 40, 4, "hexdate", 1],
  147. [" fault3CODE: ", 44, 4, "faultmap", 1], [" fault3TIME: ", 48, 4, "hex2time", 1], [" fault3DATE: ", 52, 4, "hexdate", 1]
  148. ],
  149. "EEprg206" => [["OpMode: ", 4, 2, "hex", 1], [" ProgStateHC: ", 10, 2, "opmodehc", 1], [" ProgStateDHW: ", 12, 2, "opmodehc", 1],
  150. [" ProgStateFAN: ", 14, 2, "opmodehc", 1], [" BaseTimeAP0: ", 16, 8, "hex", 1], [" StatusAP0: ", 24, 2, "hex", 1],
  151. [" StartTimeAP0: ", 26, 8, "hex", 1], [" EndTimeAP0: ", 34, 8, "hex", 1]
  152. ],
  153. "F3dhw" => [["dhw_temp: ", 4, 4, "hex2int", 10], [" outside_temp: ", 8, 4, "hex2int", 10],
  154. [" dhw_set_temp: ", 12, 4, "hex2int", 10], [" comp_block_time: ", 16, 4, "hex2int", 1],
  155. [" x20: ", 20, 4, "hex2int", 1], [" heat_block_time: ", 24, 4, "hex2int", 1],
  156. [" BoosterStage: ", 28, 2, "hex", 1], [" x30: ", 30, 4, "hex", 1],
  157. [" opMode: ", 34, 2, "opmodehc", 1], [" x36: ", 36, 4, "hex", 1]
  158. ],
  159. "F4hc1" => [["outsideTemp: ", 4, 4, "hex2int", 10], [" x08: ", 8, 4, "hex2int", 10],
  160. [" returnTemp: ", 12, 4, "hex2int", 10], [" integralHeat: ", 16, 4, "hex2int", 1],
  161. [" flowTemp: ", 20, 4, "hex2int", 10], [" heatSetTemp: ", 24, 4, "hex2int", 10],
  162. [" heatTemp: ", 28, 4, "hex2int", 10],
  163. [" seasonMode: ", 38, 2, "somwinmode", 1], #[" x40: ", 40, 4, "hex2int", 1],
  164. [" integralSwitch: ", 44, 4, "hex2int", 1], [" opMode: ", 48, 2, "opmodehc", 1],
  165. #[" x52: ", 52, 4, "hex2int", 1],
  166. [" roomSetTemp: ", 56, 4, "hex2int", 10], [" x60: ", 60, 4, "hex2int", 10],
  167. [" x64: ", 64, 4, "hex2int", 10], [" insideTempRC: ", 68, 4, "hex2int", 10],
  168. [" x72: ", 72, 4, "hex2int", 10], [" x76: ", 76, 4, "hex2int", 10],
  169. [" onHysteresisNo: ", 32, 2, "hex", 1], [" offHysteresisNo: ", 34, 2, "hex", 1],
  170. [" HCBoosterStage: ", 36, 2, "hex", 1]
  171. ],
  172. "F4hc1214" => [["outsideTemp: ", 4, 4, "hex2int", 10], [" x08: ", 8, 4, "hex2int", 10],
  173. [" returnTemp: ", 12, 4, "hex2int", 10], [" integralHeat: ", 16, 4, "hex2int", 1],
  174. [" flowTemp: ", 20, 4, "hex2int", 10], [" heatSetTemp: ", 24, 4, "hex2int", 10],
  175. [" heatTemp: ", 28, 4, "hex2int", 10],
  176. [" seasonMode: ", 38, 2, "somwinmode", 1], #[" x40: ", 40, 4, "hex2int", 1],
  177. [" integralSwitch: ", 44, 4, "hex2int", 1], [" opMode: ", 48, 2, "opmodehc", 1],
  178. #[" x52: ", 52, 4, "hex2int", 1],
  179. [" roomSetTemp: ", 62, 4, "hex2int", 10], [" x60: ", 60, 4, "hex2int", 10],
  180. [" x64: ", 64, 4, "hex2int", 10], [" insideTempRC: ", 68, 4, "hex2int", 10],
  181. [" x72: ", 72, 4, "hex2int", 10], [" x76: ", 76, 4, "hex2int", 10],
  182. [" onHysteresisNo: ", 32, 2, "hex", 1], [" offHysteresisNo: ", 34, 2, "hex", 1],
  183. [" HCBoosterStage: ", 36, 2, "hex", 1]
  184. ],
  185. "F5hc2" => [["outsideTemp: ", 4, 4, "hex2int", 10], [" returnTemp: ", 8, 4, "hex2int", 10],
  186. [" vorlaufTemp: ", 12, 4, "hex2int", 10], [" heatSetTemp: ", 16, 4, "hex2int", 10],
  187. [" heatTemp: ", 20, 4, "hex2int", 10], [" stellgroesse: ", 24, 4, "hex2int", 10],
  188. [" seasonMode: ", 30, 2, "somwinmode",1], [" opMode: ", 36, 2, "opmodehc", 1]
  189. ],
  190. "F6sys206" => [["UserSetFanStage: ", 30, 2, "hex", 1], [" UserSetFanRemainingTime: ", 36, 4, "hex", 1],
  191. [" LastErrors: ", 4, 8, "hex2error", 1],
  192. ],
  193. "FBglob" => [["outsideTemp: ", 8, 4, "hex2int", 10], [" flowTemp: ", 12, 4, "hex2int", 10],
  194. [" returnTemp: ", 16, 4, "hex2int", 10], [" hotGasTemp: ", 20, 4, "hex2int", 10],
  195. [" dhwTemp: ", 24, 4, "hex2int", 10], [" flowTempHC2: ", 28, 4, "hex2int", 10],
  196. [" evaporatorTemp: ", 36, 4, "hex2int", 10], [" condenserTemp: ", 40, 4, "hex2int", 10],
  197. [" mixerOpen: ", 45, 1, "bit0", 1], [" mixerClosed: ", 45, 1, "bit1", 1],
  198. [" heatPipeValve: ", 45, 1, "bit2", 1], [" diverterValve: ", 45, 1, "bit3", 1],
  199. [" dhwPump: ", 44, 1, "bit0", 1], [" heatingCircuitPump: ", 44, 1, "bit1", 1],
  200. [" solarPump: ", 44, 1, "bit3", 1], [" compressor: ", 47, 1, "bit3", 1],
  201. [" boosterStage3: ", 46, 1, "bit0", 1], [" boosterStage2: ", 46, 1, "bit1", 1],
  202. [" boosterStage1: ", 46, 1, "bit2", 1], [" highPressureSensor: ", 49, 1, "nbit0", 1],
  203. [" lowPressureSensor: ", 49, 1, "nbit1", 1], [" evaporatorIceMonitor: ", 49, 1, "bit2", 1],
  204. [" signalAnode: ", 49, 1, "bit3", 1], [" evuRelease: ", 48, 1, "bit0", 1],
  205. [" ovenFireplace: ", 48, 1, "bit1", 1], [" STB: ", 48, 1, "bit2", 1],
  206. [" outputVentilatorPower: ",50, 4, "hex", 10], [" inputVentilatorPower: ", 54, 4, "hex", 10], [" mainVentilatorPower: ", 58, 4, "hex", 10],
  207. [" outputVentilatorSpeed: ",62, 4, "hex", 1], [" inputVentilatorSpeed: ", 66, 4, "hex", 1], [" mainVentilatorSpeed: ", 70, 4, "hex", 1],
  208. [" outside_tempFiltered: ",74, 4, "hex2int", 10], [" relHumidity: ", 78, 4, "hex2int", 10],
  209. [" dewPoint: ", 82, 4, "hex2int", 10],
  210. [" P_Nd: ", 86, 4, "hex2int", 100], [" P_Hd: ", 90, 4, "hex2int", 100],
  211. [" actualPower_Qc: ", 94, 8, "esp_mant", 1], [" actualPower_Pel: ", 102, 8, "esp_mant", 1],
  212. [" collectorTemp: ", 4, 4, "hex2int", 10], [" insideTemp: ", 32, 4, "hex2int", 10] #, [" x84: ", 84, 4, "donottouch", 1]
  213. ],
  214. "FBglob206" => [["outsideTemp: ", 8, 4, "hex2int", 10], [" flowTemp: ", 12, 4, "hex2int", 10],
  215. [" returnTemp: ", 16, 4, "hex2int", 10], [" hotGasTemp: ", 20, 4, "hex2int", 10],
  216. [" dhwTemp: ", 24, 4, "hex2int", 10], [" flowTempHC2: ", 28, 4, "hex2int", 10],
  217. [" evaporatorTemp: ", 36, 4, "hex2int", 10], [" condenserTemp: ", 40, 4, "hex2int", 10],
  218. [" mixerOpen: ", 47, 1, "bit1", 1], [" mixerClosed: ", 47, 1, "bit0", 1],
  219. [" heatPipeValve: ", 45, 1, "bit3", 1], [" diverterValve: ", 45, 1, "bit2", 1],
  220. [" dhwPump: ", 45, 1, "bit1", 1], [" heatingCircuitPump: ", 45, 1, "bit0", 1],
  221. [" solarPump: ", 44, 1, "bit2", 1], [" compressor: ", 44, 1, "bit0", 1],
  222. [" boosterStage3: ", 44, 1, "bit3", 1], [" boosterStage2: ", 44, 1, "n.a.", 1],
  223. [" boosterStage1: ", 44, 1, "bit1", 1], [" highPressureSensor: ", 49, 1, "n.a.", 1],
  224. [" lowPressureSensor: ", 49, 1, "n.a.", 1], [" evaporatorIceMonitor: ", 49, 1, "n.a.", 1],
  225. [" signalAnode: ", 49, 1, "n.a.", 1], [" evuRelease: ", 48, 1, "n.a.", 1],
  226. [" ovenFireplace: ", 48, 1, "n.a.", 1], [" STB: ", 48, 1, "n.a.", 1],
  227. [" outputVentilatorPower: ",48, 2, "hex", 1], [" inputVentilatorPower: ", 50, 2, "hex", 1], [" mainVentilatorPower: ", 52, 2, "hex", 1],
  228. [" outputVentilatorSpeed: ",56, 2, "hex", 1], [" inputVentilatorSpeed: ", 58, 2, "hex", 1], [" mainVentilatorSpeed: ", 60, 2, "hex", 1],
  229. [" outside_tempFiltered: ",64, 4, "hex2int", 10], [" relHumidity: ", 70, 4, "n.a.", 1],
  230. [" dewPoint: ", 5, 4, "n.a.", 1],
  231. [" P_Nd: ", 5, 4, "n.a.", 1], [" P_Hd: ", 5, 4, "n.a.", 1],
  232. [" actualPower_Qc: ", 5, 8, "n.a.", 1], [" actualPower_Pel: ", 5, 8, "n.a.", 1],
  233. [" collectorTemp: ", 4, 4, "hex2int", 10], [" insideTemp: ", 32, 4, "hex2int", 10] #, [" x84: ", 84, 4, "donottouch", 1]
  234. ],
  235. "FCtime" => [["Weekday: ", 5, 1, "weekday", 1], [" Hour: ", 6, 2, "hex", 1],
  236. [" Min: ", 8, 2, "hex", 1], [" Sec: ", 10, 2, "hex", 1],
  237. [" Date: ", 12, 2, "year", 1], ["/", 14, 2, "hex", 1],
  238. ["/", 16, 2, "hex", 1]
  239. ],
  240. "FCtime206" => [["Weekday: ", 7, 1, "weekday", 1], [" pClockHour: ", 8, 2, "hex", 1],
  241. [" pClockMinutes: ", 10, 2, "hex", 1], [" Sec: ", 12, 2, "hex", 1],
  242. [" pClockYear: ", 14, 2, "hex", 1], [" pClockMonth: ", 18, 2, "hex", 1],
  243. [" pClockDay: ", 20, 2, "hex", 1]
  244. ],
  245. "FDfirm" => [["version: ", 4, 4, "hexdate", 1]
  246. ],
  247. "FEfirmId" => [[" HW: ", 30, 2, "hex", 1], [" SW: ", 32, 4, "swver", 1],
  248. [" Date: ", 36, 22, "hex2ascii", 1]
  249. ],
  250. "0A0176Dis" => [[" switchingProg: ", 11, 1, "bit0", 1], [" compressor: ", 11, 1, "bit1", 1],
  251. [" heatingHC: ", 11, 1, "bit2", 1], [" heatingDHW: ", 10, 1, "bit0", 1],
  252. [" boosterHC: ", 10, 1, "bit1", 1], [" filterBoth: ", 9, 1, "bit0", 1],
  253. [" ventStage: ", 9, 1, "bit1", 1], [" pumpHC: ", 9, 1, "bit2", 1],
  254. [" defrost: ", 9, 1, "bit3", 1], [" filterUp: ", 8, 1, "bit0", 1],
  255. [" filterDown: ", 8, 1, "bit1", 1], [" cooling: ", 11, 1, "bit3", 1]
  256. ],
  257. "0clean" => [["", 8, 2, "hex", 1]
  258. ],
  259. "1clean" => [["", 8, 4, "hex", 1]
  260. ],
  261. "2opmode" => [["", 8, 2, "opmode", 1]
  262. ],
  263. "4temp" => [["", 8, 4, "hex2int",2560]
  264. ],
  265. "5temp" => [["", 8, 4, "hex2int",10]
  266. ],
  267. "6gradient" => [["", 8, 4, "hex", 100]
  268. ],
  269. "7prog" => [["", 8, 2, "quater", 1], ["--", 10, 2, "quater", 1]
  270. ],
  271. "8party" => [["", 10, 2, "quater", 1], ["--", 8, 2, "quater", 1]
  272. ],
  273. "9holy" => [["", 10, 2, "quater", 1]
  274. ]
  275. );
  276. ########################################################################################
  277. #
  278. # %sets - all supported protocols are listed 59E
  279. #
  280. ########################################################################################
  281. my %sets439technician =(
  282. # "zResetLast10errors" => {cmd2=>"D1", argMin => "0", argMax => "0", type =>"0clean", unit =>""},
  283. # "zPassiveCoolingtrigger" => {cmd2=>"0A0597", argMin => "0", argMax => "50", type =>"1clean", unit =>""},
  284. "zPumpHC" => {cmd2=>"0A0052", argMin => "0", argMax => "1", type =>"0clean", unit =>""},
  285. "zPumpDHW" => {cmd2=>"0A0056", argMin => "0", argMax => "1", type =>"0clean", unit =>""}
  286. );
  287. my %sets439539common = (
  288. "pOpMode" => {cmd2=>"0A0112", type => "2opmode"}, # 1 Standby bereitschaft; 11 in Automatic; 3 DAYmode; SetbackMode; DHWmode; Manual; Emergency
  289. "p01RoomTempDayHC1" => {cmd2=>"0B0005", argMin => "12", argMax => "28", type =>"5temp", unit =>" °C"},
  290. "p02RoomTempNightHC1" => {cmd2=>"0B0008", argMin => "12", argMax => "28", type =>"5temp", unit =>" °C"},
  291. "p03RoomTempStandbyHC1" => {cmd2=>"0B013D", argMin => "12", argMax => "28", type =>"5temp", unit =>" °C"},
  292. "p01RoomTempDayHC1SummerMode" => {cmd2=>"0B0569", argMin => "12", argMax => "28", type =>"5temp", unit =>" °C"},
  293. "p02RoomTempNightHC1SummerMode" => {cmd2=>"0B056B", argMin => "12", argMax => "28", type =>"5temp", unit =>" °C"},
  294. "p03RoomTempStandbyHC1SummerMode" => {cmd2=>"0B056A", argMin => "12", argMax => "28", type =>"5temp", unit =>" °C"},
  295. "p13GradientHC1" => {cmd2=>"0B010E", argMin => "0.1", argMax => "5", type =>"6gradient", unit =>""}, # 0..5 rappresentato/100
  296. "p14LowEndHC1" => {cmd2=>"0B059E", argMin => "0", argMax => "10", type =>"5temp", unit =>" K"}, #in °K 0..20°K rappresentato/10
  297. "p15RoomInfluenceHC1" => {cmd2=>"0B010F", argMin => "0", argMax => "100", type =>"0clean", unit =>" %"},
  298. "p19FlowProportionHC1" => {cmd2=>"0B059D", argMin => "0", argMax => "100", type =>"1clean", unit =>" %"}, #in % 0..100%
  299. "p01RoomTempDayHC2" => {cmd2=>"0C0005", argMin => "12", argMax => "28", type =>"5temp", unit =>" °C"},
  300. "p02RoomTempNightHC2" => {cmd2=>"0C0008", argMin => "12", argMax => "28", type =>"5temp", unit =>" °C"},
  301. "p03RoomTempStandbyHC2" => {cmd2=>"0C013D", argMin => "12", argMax => "28", type =>"5temp", unit =>" °C"},
  302. "p01RoomTempDayHC2SummerMode" => {cmd2=>"0C0569", argMin => "12", argMax => "28", type =>"5temp", unit =>" °C"},
  303. "p02RoomTempNightHC2SummerMode" => {cmd2=>"0C056B", argMin => "12", argMax => "28", type =>"5temp", unit =>" °C"},
  304. "p03RoomTempStandbyHC2SummerMode" => {cmd2=>"0C056A", argMin => "12", argMax => "28", type =>"5temp", unit =>" °C"},
  305. "p16GradientHC2" => {cmd2=>"0C010E", argMin => "0.1", argMax => "5", type =>"6gradient", unit =>""}, # /100
  306. "p17LowEndHC2" => {cmd2=>"0C059E", argMin => "0", argMax => "10", type =>"5temp", unit =>" K"},
  307. "p18RoomInfluenceHC2" => {cmd2=>"0C010F", argMin => "0", argMax => "100", type =>"0clean", unit =>" %"},
  308. "p04DHWsetDayTemp" => {cmd2=>"0A0013", argMin => "10", argMax => "55", type =>"5temp", unit =>" °C"},
  309. "p05DHWsetNightTemp" => {cmd2=>"0A05BF", argMin => "10", argMax => "55", type =>"5temp", unit =>" °C"},
  310. "p83DHWsetSolarTemp" => {cmd2=>"0A05BE", argMin => "10", argMax => "75", type =>"5temp", unit =>" °C"},
  311. "p06DHWsetStandbyTemp" => {cmd2=>"0A0581", argMin => "10", argMax => "55", type =>"5temp", unit =>" °C"},
  312. "p11DHWsetManualTemp" => {cmd2=>"0A0580", argMin => "10", argMax => "55", type =>"5temp", unit =>" °C"},
  313. "p36DHWMaxTime" => {cmd2=>"0A0180", argMin => "6", argMax => "12", type =>"1clean", unit =>""},
  314. "p07FanStageDay" => {cmd2=>"0A056C", argMin => "0", argMax => "3", type =>"1clean", unit =>""},
  315. "p08FanStageNight" => {cmd2=>"0A056D", argMin => "0", argMax => "3", type =>"1clean", unit =>""},
  316. "p09FanStageStandby" => {cmd2=>"0A056F", argMin => "0", argMax => "3", type =>"1clean", unit =>""},
  317. "p99FanStageParty" => {cmd2=>"0A0570", argMin => "0", argMax => "3", type =>"1clean", unit =>""},
  318. "p21Hyst1" => {cmd2=>"0A05C0", argMin => "0", argMax => "10", type =>"5temp", unit =>" K"},
  319. "p22Hyst2" => {cmd2=>"0A05C1", argMin => "0", argMax => "10", type =>"5temp", unit =>" K"},
  320. "p23Hyst3" => {cmd2=>"0A05C2", argMin => "0", argMax => "5", type =>"5temp", unit =>" K"},
  321. "p24Hyst4" => {cmd2=>"0A05C3", argMin => "0", argMax => "5", type =>"5temp", unit =>" K"},
  322. "p25Hyst5" => {cmd2=>"0A05C4", argMin => "0", argMax => "5", type =>"5temp", unit =>" K"},
  323. "p29HystAsymmetry" => {cmd2=>"0A05C5", argMin => "1", argMax => "5", type =>"1clean", unit =>""},
  324. "p30integralComponent" => {cmd2=>"0A0162", argMin => "10", argMax => "999", type =>"1clean", unit =>" Kmin"},
  325. "p32HystDHW" => {cmd2=>"0A0140", argMin => "0", argMax => "10", type =>"5temp", unit =>" K"},
  326. "p33BoosterTimeoutDHW" => {cmd2=>"0A0588", argMin => "0", argMax => "200", type =>"1clean", unit =>" min"}, #during DHW heating
  327. "p79BoosterTimeoutHC" => {cmd2=>"0A05A0", argMin => "0", argMax => "60", type =>"1clean", unit =>" min"}, #delayed enabling of booster heater
  328. "p46UnschedVent0" => {cmd2=>"0A0571", argMin => "0", argMax => "1000", type =>"1clean", unit =>" min"}, #in min
  329. "p45UnschedVent1" => {cmd2=>"0A0572", argMin => "0", argMax => "1000", type =>"1clean", unit =>" min"}, #in min
  330. "p44UnschedVent2" => {cmd2=>"0A0573", argMin => "0", argMax => "1000", type =>"1clean", unit =>" min"}, #in min
  331. "p43UnschedVent3" => {cmd2=>"0A0574", argMin => "0", argMax => "1000", type =>"1clean", unit =>" min"}, #in min
  332. "p37Fanstage1AirflowInlet" => {cmd2=>"0A0576", argMin => "50", argMax => "300", type =>"1clean", unit =>" m3/h"}, #zuluft
  333. "p38Fanstage2AirflowInlet" => {cmd2=>"0A0577", argMin => "50", argMax => "300", type =>"1clean", unit =>" m3/h"}, #zuluft
  334. "p39Fanstage3AirflowInlet" => {cmd2=>"0A0578", argMin => "50", argMax => "300", type =>"1clean", unit =>" m3/h"}, #zuluft
  335. "p40Fanstage1AirflowOutlet" => {cmd2=>"0A0579", argMin => "50", argMax => "300", type =>"1clean", unit =>" m3/h"}, #abluft extrated
  336. "p41Fanstage2AirflowOutlet" => {cmd2=>"0A057A", argMin => "50", argMax => "300", type =>"1clean", unit =>" m3/h"}, #abluft extrated
  337. "p42Fanstage3AirflowOutlet" => {cmd2=>"0A057B", argMin => "50", argMax => "300", type =>"1clean", unit =>" m3/h"}, #abluft extrated
  338. "p49SummerModeTemp" => {cmd2=>"0A0116", argMin => "10", argMax => "24", type =>"5temp", unit =>" °C"}, #threshold for summer mode !!
  339. "p50SummerModeHysteresis" => {cmd2=>"0A05A2", argMin => "0.5", argMax => "5", type =>"5temp", unit =>" K"}, #Hysteresis for summer mode !!
  340. "p78DualModePoint" => {cmd2=>"0A01AC", argMin => "-10", argMax => "20", type =>"5temp", unit =>" °C"},
  341. "p54MinPumpCycles" => {cmd2=>"0A05B8", argMin => "1", argMax => "24", type =>"1clean", unit =>""},
  342. "p55MaxPumpCycles" => {cmd2=>"0A05B7", argMin => "25", argMax => "200", type =>"1clean", unit =>""},
  343. "p56OutTempMaxPumpCycles" => {cmd2=>"0A05B9", argMin => "0", argMax => "20", type =>"5temp", unit =>" °C"},
  344. "p57OutTempMinPumpCycles" => {cmd2=>"0A05BA", argMin => "0", argMax => "25", type =>"5temp", unit =>" °C"},
  345. "p76RoomThermCorrection" => {cmd2=>"0A0109", argMin => "-5", argMax => "5", type =>"4temp", unit =>" K"},
  346. "p77OutThermFilterTime" => {cmd2=>"0A010C", argMin => "1", argMax => "24", type =>"0clean", unit =>" h"},
  347. "p35PasteurisationInterval" => {cmd2=>"0A0586", argMin => "1", argMax => "30", type =>"1clean", unit =>""},
  348. "p35PasteurisationTemp" => {cmd2=>"0A0587", argMin => "10", argMax => "65", type =>"5temp", unit =>" °C"},
  349. "p34BoosterDHWTempAct" => {cmd2=>"0A0589", argMin => "-10", argMax => "10", type =>"5temp", unit =>" °C"},
  350. "p99DHWmaxFlowTemp" => {cmd2=>"0A058C", argMin => "10", argMax => "75", type =>"5temp", unit =>" °C"},
  351. "p99HC1maxFlowTemp" => {cmd2=>"0A0027", argMin => "10", argMax => "75", type =>"5temp", unit =>" °C"},
  352. "p89DHWeco" => {cmd2=>"0A058D", argMin => "0", argMax => "1", type =>"1clean", unit =>""},
  353. "p99startUnschedVent" => {cmd2=>"0A05DD", argMin => "0", argMax => "3", type =>"1clean", unit =>""},
  354. "p99FrostProtectionBoost" => {cmd2=>"0A05B3", argMin => "10", argMax => "30", type =>"5temp", unit =>" °C"}, #added by TheTrumpeter __EINFRIERSCHUTZ NE
  355. "p99FrostProtectionCancel" => {cmd2=>"0A05B4", argMin => "0", argMax => "20", type =>"5temp", unit =>" °C"}, #added by TheTrumpeter __ABTAUABBR.
  356. "pClockDay" => {cmd2=>"0A0122", argMin => "1", argMax => "31", type =>"0clean", unit =>""},
  357. "pClockMonth" => {cmd2=>"0A0123", argMin => "1", argMax => "12", type =>"0clean", unit =>""},
  358. "pClockYear" => {cmd2=>"0A0124", argMin => "12", argMax => "20", type =>"0clean", unit =>""},
  359. "pClockHour" => {cmd2=>"0A0125", argMin => "0", argMax => "23", type =>"0clean", unit =>""},
  360. "pClockMinutes" => {cmd2=>"0A0126", argMin => "0", argMax => "59", type =>"0clean", unit =>""},
  361. "pHolidayBeginDay" => {cmd2=>"0A011B", argMin => "1", argMax => "31", type =>"0clean", unit =>""},
  362. "pHolidayBeginMonth" => {cmd2=>"0A011C", argMin => "1", argMax => "12", type =>"0clean", unit =>""},
  363. "pHolidayBeginYear" => {cmd2=>"0A011D", argMin => "12", argMax => "20", type =>"0clean", unit =>""},
  364. "pHolidayBeginTime" => {cmd2=>"0A05D3", argMin => "00:00", argMax => "23:59", type =>"9holy", unit =>""},
  365. "pHolidayEndDay" => {cmd2=>"0A011E", argMin => "1", argMax => "31", type =>"0clean", unit =>""},
  366. "pHolidayEndMonth" => {cmd2=>"0A011F", argMin => "1", argMax => "12", type =>"0clean", unit =>""},
  367. "pHolidayEndYear" => {cmd2=>"0A0120", argMin => "12", argMax => "20", type =>"0clean", unit =>""},
  368. "pHolidayEndTime" => {cmd2=>"0A05D4", argMin => "00:00", argMax => "23:59", type =>"9holy", unit =>""}, # the answer look like 0A05D4-0D0A05D40029 for year 41 which is 10:15
  369. #"party-time" => {cmd2=>"0A05D1", argMin => "00:00", argMax => "23:59", type =>"8party", unit =>""}, # value 1Ch 28dec is 7 ; value 1Eh 30dec is 7:30
  370. "programHC1_Mo_0" => {cmd2=>"0B1410", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""}, #1 is monday 0 is first prog; start and end; value 1Ch 28dec is 7 ; value 1Eh 30dec is 7:30
  371. "programHC1_Mo_1" => {cmd2=>"0B1411", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  372. "programHC1_Mo_2" => {cmd2=>"0B1412", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  373. "programHC1_Tu_0" => {cmd2=>"0B1420", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  374. "programHC1_Tu_1" => {cmd2=>"0B1421", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  375. "programHC1_Tu_2" => {cmd2=>"0B1422", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  376. "programHC1_We_0" => {cmd2=>"0B1430", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  377. "programHC1_We_1" => {cmd2=>"0B1431", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  378. "programHC1_We_2" => {cmd2=>"0B1432", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  379. "programHC1_Th_0" => {cmd2=>"0B1440", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  380. "programHC1_Th_1" => {cmd2=>"0B1441", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  381. "programHC1_Th_2" => {cmd2=>"0B1442", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  382. "programHC1_Fr_0" => {cmd2=>"0B1450", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  383. "programHC1_Fr_1" => {cmd2=>"0B1451", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  384. "programHC1_Fr_2" => {cmd2=>"0B1452", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  385. "programHC1_Sa_0" => {cmd2=>"0B1460", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  386. "programHC1_Sa_1" => {cmd2=>"0B1461", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  387. "programHC1_Sa_2" => {cmd2=>"0B1462", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  388. "programHC1_So_0" => {cmd2=>"0B1470", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  389. "programHC1_So_1" => {cmd2=>"0B1471", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  390. "programHC1_So_2" => {cmd2=>"0B1472", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  391. "programHC1_Mo-Fr_0" => {cmd2=>"0B1480", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  392. "programHC1_Mo-Fr_1" => {cmd2=>"0B1481", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  393. "programHC1_Mo-Fr_2" => {cmd2=>"0B1482", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  394. "programHC1_Sa-So_0" => {cmd2=>"0B1490", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  395. "programHC1_Sa-So_1" => {cmd2=>"0B1491", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  396. "programHC1_Sa-So_2" => {cmd2=>"0B1492", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  397. "programHC1_Mo-So_0" => {cmd2=>"0B14A0", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  398. "programHC1_Mo-So_1" => {cmd2=>"0B14A1", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  399. "programHC1_Mo-So_2" => {cmd2=>"0B14A2", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  400. "programHC2_Mo_0" => {cmd2=>"0C1510", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""}, #1 is monday 0 is first prog; start and end; value 1Ch 28dec is 7 ; value 1Eh 30dec is 7:30
  401. "programHC2_Mo_1" => {cmd2=>"0C1511", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  402. "programHC2_Mo_2" => {cmd2=>"0C1512", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  403. "programHC2_Tu_0" => {cmd2=>"0C1520", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  404. "programHC2_Tu_1" => {cmd2=>"0C1521", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  405. "programHC2_Tu_2" => {cmd2=>"0C1522", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  406. "programHC2_We_0" => {cmd2=>"0C1530", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  407. "programHC2_We_1" => {cmd2=>"0C1531", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  408. "programHC2_We_2" => {cmd2=>"0C1532", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  409. "programHC2_Th_0" => {cmd2=>"0C1540", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  410. "programHC2_Th_1" => {cmd2=>"0C1541", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  411. "programHC2_Th_2" => {cmd2=>"0C1542", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  412. "programHC2_Fr_0" => {cmd2=>"0C1550", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  413. "programHC2_Fr_1" => {cmd2=>"0C1551", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  414. "programHC2_Fr_2" => {cmd2=>"0C1552", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  415. "programHC2_Sa_0" => {cmd2=>"0C1560", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  416. "programHC2_Sa_1" => {cmd2=>"0C1561", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  417. "programHC2_Sa_2" => {cmd2=>"0C1562", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  418. "programHC2_So_0" => {cmd2=>"0C1570", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  419. "programHC2_So_1" => {cmd2=>"0C1571", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  420. "programHC2_So_2" => {cmd2=>"0C1572", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  421. "programHC2_Mo-Fr_0" => {cmd2=>"0C1580", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  422. "programHC2_Mo-Fr_1" => {cmd2=>"0C1581", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  423. "programHC2_Mo-Fr_2" => {cmd2=>"0C1582", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  424. "programHC2_Sa-So_0" => {cmd2=>"0C1590", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  425. "programHC2_Sa-So_1" => {cmd2=>"0C1591", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  426. "programHC2_Sa-So_2" => {cmd2=>"0C1592", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  427. "programHC2_Mo-So_0" => {cmd2=>"0C15A0", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  428. "programHC2_Mo-So_1" => {cmd2=>"0C15A1", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  429. "programHC2_Mo-So_2" => {cmd2=>"0C15A2", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  430. "programDHW_Mo_0" => {cmd2=>"0A1710", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  431. "programDHW_Mo_1" => {cmd2=>"0A1711", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  432. "programDHW_Mo_2" => {cmd2=>"0A1712", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  433. "programDHW_Tu_0" => {cmd2=>"0A1720", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  434. "programDHW_Tu_1" => {cmd2=>"0A1721", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  435. "programDHW_Tu_2" => {cmd2=>"0A1722", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  436. "programDHW_We_0" => {cmd2=>"0A1730", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  437. "programDHW_We_1" => {cmd2=>"0A1731", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  438. "programDHW_We_2" => {cmd2=>"0A1732", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  439. "programDHW_Th_0" => {cmd2=>"0A1740", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  440. "programDHW_Th_1" => {cmd2=>"0A1741", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  441. "programDHW_Th_2" => {cmd2=>"0A1742", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  442. "programDHW_Fr_0" => {cmd2=>"0A1750", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  443. "programDHW_Fr_1" => {cmd2=>"0A1751", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  444. "programDHW_Fr_2" => {cmd2=>"0A1752", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  445. "programDHW_Sa_0" => {cmd2=>"0A1760", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  446. "programDHW_Sa_1" => {cmd2=>"0A1761", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  447. "programDHW_Sa_2" => {cmd2=>"0A1762", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  448. "programDHW_So_0" => {cmd2=>"0A1770", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  449. "programDHW_So_1" => {cmd2=>"0A1771", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  450. "programDHW_So_2" => {cmd2=>"0A1772", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  451. "programDHW_Mo-Fr_0" => {cmd2=>"0A1780", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  452. "programDHW_Mo-Fr_1" => {cmd2=>"0A1781", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  453. "programDHW_Mo-Fr_2" => {cmd2=>"0A1782", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  454. "programDHW_Sa-So_0" => {cmd2=>"0A1790", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  455. "programDHW_Sa-So_1" => {cmd2=>"0A1791", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  456. "programDHW_Sa-So_2" => {cmd2=>"0A1792", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  457. "programDHW_Mo-So_0" => {cmd2=>"0A17A0", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  458. "programDHW_Mo-So_1" => {cmd2=>"0A17A1", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  459. "programDHW_Mo-So_2" => {cmd2=>"0A17A2", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  460. "programFan_Mo_0" => {cmd2=>"0A1D10", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  461. "programFan_Mo_1" => {cmd2=>"0A1D11", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  462. "programFan_Mo_2" => {cmd2=>"0A1D12", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  463. "programFan_Tu_0" => {cmd2=>"0A1D20", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  464. "programFan_Tu_1" => {cmd2=>"0A1D21", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  465. "programFan_Tu_2" => {cmd2=>"0A1D22", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  466. "programFan_We_0" => {cmd2=>"0A1D30", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  467. "programFan_We_1" => {cmd2=>"0A1D31", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  468. "programFan_We_2" => {cmd2=>"0A1D32", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  469. "programFan_Th_0" => {cmd2=>"0A1D40", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  470. "programFan_Th_1" => {cmd2=>"0A1D41", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  471. "programFan_Th_2" => {cmd2=>"0A1D42", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  472. "programFan_Fr_0" => {cmd2=>"0A1D50", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  473. "programFan_Fr_1" => {cmd2=>"0A1D51", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  474. "programFan_Fr_2" => {cmd2=>"0A1D52", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  475. "programFan_Sa_0" => {cmd2=>"0A1D60", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  476. "programFan_Sa_1" => {cmd2=>"0A1D61", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  477. "programFan_Sa_2" => {cmd2=>"0A1D62", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  478. "programFan_So_0" => {cmd2=>"0A1D70", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  479. "programFan_So_1" => {cmd2=>"0A1D71", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  480. "programFan_So_2" => {cmd2=>"0A1D72", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  481. "programFan_Mo-Fr_0" => {cmd2=>"0A1D80", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  482. "programFan_Mo-Fr_1" => {cmd2=>"0A1D81", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  483. "programFan_Mo-Fr_2" => {cmd2=>"0A1D82", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  484. "programFan_Sa-So_0" => {cmd2=>"0A1D90", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  485. "programFan_Sa-So_1" => {cmd2=>"0A1D91", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  486. "programFan_Sa-So_2" => {cmd2=>"0A1D92", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  487. "programFan_Mo-So_0" => {cmd2=>"0A1DA0", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  488. "programFan_Mo-So_1" => {cmd2=>"0A1DA1", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""},
  489. "programFan_Mo-So_2" => {cmd2=>"0A1DA2", argMin => "00:00", argMax => "24:00", type =>"7prog", unit =>""}
  490. );
  491. my %sets439only =(
  492. "p75passiveCooling" => {cmd2=>"0A0575", argMin => "0", argMax => "2", type =>"1clean", unit =>""}
  493. );
  494. my %sets539only =(
  495. "p75passiveCooling" => {cmd2=>"0A0575", argMin => "0", argMax => "4", type =>"1clean", unit =>""},
  496. "p99PumpRateHC" => {cmd2=>"0A02CB", argMin => "0", argMax => "100", type =>"5temp", unit =>" %"},
  497. "p99PumpRateDHW" => {cmd2=>"0A02CC", argMin => "0", argMax => "100", type =>"5temp", unit =>" %"} ,
  498. "p99CoolingHC1Switch" => {cmd2=>"0B0287", argMin => "0", argMax => "1", type =>"1clean", unit =>""},
  499. "p99CoolingHC1SetTemp" => {cmd2=>"0B0582", argMin => "12", argMax => "27", type =>"5temp", unit =>" °C"}, #suggested by TheTrumpeter
  500. "p99CoolingHC1HystersisFlowTemp" => {cmd2=>"0B0583", argMin => "0.5", argMax => "5", type =>"5temp", unit =>" K"}, #suggested by TheTrumpeter
  501. "p99CoolingHC1HystersisRoomTemp" => {cmd2=>"0B0584", argMin => "0.5", argMax => "3", type =>"5temp", unit =>" K"} #suggested by TheTrumpeter
  502. );
  503. my %sets206 = (
  504. "p01RoomTempDay" => {parent=>"p01-p12", argMin => "10", argMax => "30", unit =>" °C"},
  505. "p02RoomTempNight" => {parent=>"p01-p12", argMin => "10", argMax => "30", unit =>" °C"},
  506. "p03RoomTempStandby" => {parent=>"p01-p12", argMin => "10", argMax => "30", unit =>" °C"},
  507. "p04DHWsetTempDay" => {parent=>"p01-p12", argMin => "10", argMax => "55", unit =>" °C"},
  508. "p05DHWsetTempNight" => {parent=>"p01-p12", argMin => "10", argMax => "55", unit =>" °C"},
  509. "p06DHWsetTempStandby"=> {parent=>"p01-p12", argMin => "10", argMax => "55", unit =>" °C"},
  510. "p07FanStageDay" => {parent=>"p01-p12", argMin => "0", argMax => "3", unit =>""},
  511. "p08FanStageNight" => {parent=>"p01-p12", argMin => "0", argMax => "3", unit =>""},
  512. "p09FanStageStandby" => {parent=>"p01-p12", argMin => "0", argMax => "3", unit =>""},
  513. "p10HCTempManual" => {parent=>"p01-p12", argMin => "10", argMax => "65", unit =>" °C"},
  514. "p11DHWsetTempManual" => {parent=>"p01-p12", argMin => "10", argMax => "65", unit =>" °C"},
  515. "p12FanStageManual" => {parent=>"p01-p12", argMin => "0", argMax => "3", unit =>""},
  516. "p80EnableSolar" => {parent=>"pSolar", argMin => "0", argMax => "1", unit =>""},
  517. "pClockDay" => {parent=>"sTimedate", argMin => "1", argMax => "31", unit =>""},
  518. "pClockMonth" => {parent=>"sTimedate", argMin => "1", argMax => "12", unit =>""},
  519. "pClockYear" => {parent=>"sTimedate", argMin => "12", argMax => "20", unit =>""},
  520. "pClockHour" => {parent=>"sTimedate", argMin => "0", argMax => "23", unit =>""},
  521. "pClockMinutes" => {parent=>"sTimedate", argMin => "0", argMax => "59", unit =>""}
  522. );
  523. my %setsonly214 = (
  524. "ResetErrors" => {cmd2=>"F8", argMin => "0", argMax => "0", type =>"0clean", unit =>""}
  525. );
  526. ########################################################################################
  527. #
  528. # %gets - all supported protocols are listed without header and footer
  529. #
  530. ########################################################################################
  531. my %getsonly439 = (
  532. #"debug_read_raw_register_slow" => { },
  533. "sSol" => {cmd2=>"16", type =>"16sol", unit =>""},
  534. "sDHW" => {cmd2=>"F3", type =>"F3dhw", unit =>""},
  535. "sHC1" => {cmd2=>"F4", type =>"F4hc1", unit =>""},
  536. "sHC2" => {cmd2=>"F5", type =>"F5hc2", unit =>""},
  537. "sHistory" => {cmd2=>"09", type =>"09his", unit =>""},
  538. "sLast10errors" => {cmd2=>"D1", type =>"D1last", unit =>""},
  539. "sGlobal" => {cmd2=>"FB", type =>"FBglob", unit =>""}, #allFB
  540. "sTimedate" => {cmd2=>"FC", type =>"FCtime", unit =>""},
  541. "sFirmware" => {cmd2=>"FD", type =>"FDfirm", unit =>""},
  542. "sFirmware-Id" => {cmd2=>"FE", type =>"FEfirmId", unit =>""},
  543. "sDisplay" => {cmd2=>"0A0176", type =>"0A0176Dis", unit =>""},
  544. "sBoostDHWTotal" => {cmd2=>"0A0924", cmd3=>"0A0925", type =>"1clean", unit =>" kWh"},
  545. "sBoostHCTotal" => {cmd2=>"0A0928", cmd3=>"0A0929", type =>"1clean", unit =>" kWh"},
  546. "sHeatRecoveredDay" => {cmd2=>"0A03AE", cmd3=>"0A03AF", type =>"1clean", unit =>" Wh"},
  547. "sHeatRecoveredTotal" => {cmd2=>"0A03B0", cmd3=>"0A03B1", type =>"1clean", unit =>" kWh"},
  548. "sHeatDHWDay" => {cmd2=>"0A092A", cmd3=>"0A092B", type =>"1clean", unit =>" Wh"},
  549. "sHeatDHWTotal" => {cmd2=>"0A092C", cmd3=>"0A092D", type =>"1clean", unit =>" kWh"},
  550. "sHeatHCDay" => {cmd2=>"0A092E", cmd3=>"0A092F", type =>"1clean", unit =>" Wh"},
  551. "sHeatHCTotal" => {cmd2=>"0A0930", cmd3=>"0A0931", type =>"1clean", unit =>" kWh"},
  552. "sElectrDHWDay" => {cmd2=>"0A091A", cmd3=>"0A091B", type =>"1clean", unit =>" Wh"},
  553. "sElectrDHWTotal" => {cmd2=>"0A091C", cmd3=>"0A091D", type =>"1clean", unit =>" kWh"},
  554. "sElectrHCDay" => {cmd2=>"0A091E", cmd3=>"0A091F", type =>"1clean", unit =>" Wh"},
  555. "sElectrHCTotal" => {cmd2=>"0A0920", cmd3=>"0A0921", type =>"1clean", unit =>" kWh"},
  556. "party-time" => {cmd2=>"0A05D1", argMin => "00:00", argMax => "23:59", type =>"8party", unit =>""} # value 1Ch 28dec is 7 ; value 1Eh 30dec is 7:30
  557. );
  558. my %getsonly539 = ( #info from belu and godmorgon
  559. "sFlowRate" => {cmd2=>"0A033B", type =>"1clean", unit =>" cl/min"},
  560. "sHumMaskingTime" => {cmd2=>"0A064F", type =>"1clean", unit =>" min"},
  561. "sHumThreshold" => {cmd2=>"0A0650", type =>"1clean", unit =>" %"},
  562. "sOutputReduction" => {cmd2=>"0A06A4", type =>"1clean", unit =>" %"},
  563. "sOutputIncrease" => {cmd2=>"0A06A5", type =>"1clean", unit =>" %"},
  564. "sHumProtection" => {cmd2=>"0A09D1", type =>"1clean", unit =>""},
  565. "sSetHumidityMin" => {cmd2=>"0A09D2", type =>"1clean", unit =>" %"},
  566. "sSetHumidityMax" => {cmd2=>"0A09D3", type =>"1clean", unit =>" %"},
  567. "sCoolHCTotal" => {cmd2=>"0A0648", cmd3=>"0A0649", type =>"1clean", unit =>" kWh"},
  568. "sDewPointHC1" => {cmd2=>"0B0264", type =>"5temp", unit =>" °C"}
  569. );
  570. %getsonly539=(%getsonly539, %getsonly439);
  571. my %getsonly2xx = (
  572. "pExpert" => {cmd2=>"02", type =>"02pxx206", unit =>""},
  573. "pDefrostEva" => {cmd2=>"03", type =>"03pxx206", unit =>""},
  574. "pDefrostAA" => {cmd2=>"04", type =>"04pxx206", unit =>""},
  575. "pHeat1" => {cmd2=>"05", type =>"05pxx206", unit =>""},
  576. "pHeat2" => {cmd2=>"06", type =>"06pxx206", unit =>""},
  577. "pDHW" => {cmd2=>"07", type =>"07pxx206", unit =>""},
  578. "pSolar" => {cmd2=>"08", type =>"08pxx206", unit =>""},
  579. "pCircPump" => {cmd2=>"0A", type =>"0Apxx206", unit =>""},
  580. "pHeatProg" => {cmd2=>"0B", type =>"0Bpxx206", unit =>""},
  581. "pDHWProg" => {cmd2=>"0C", type =>"0Cpxx206", unit =>""},
  582. "pFanProg" => {cmd2=>"0D", type =>"0Dpxx206", unit =>""},
  583. "pRestart" => {cmd2=>"0E", type =>"0Epxx206", unit =>""},
  584. "pAbsence" => {cmd2=>"0F", type =>"0Fpxx206", unit =>""},
  585. "pDryHeat" => {cmd2=>"10", type =>"10pxx206", unit =>""},
  586. "sSol" => {cmd2=>"16", type =>"16sol", unit =>""},
  587. "p01-p12" => {cmd2=>"17", type =>"17pxx206", unit =>""},
  588. "sProgram" => {cmd2=>"EE", type =>"EEprg206", unit =>""},
  589. "sDHW" => {cmd2=>"F3", type =>"F3dhw", unit =>""},
  590. "sHC2" => {cmd2=>"F5", type =>"F5hc2", unit =>""},
  591. "sSystem" => {cmd2=>"F6", type =>"F6sys206", unit =>""},
  592. "sHistory" => {cmd2=>"09", type =>"09his206", unit =>""},
  593. # "sLast10errors" => {cmd2=>"D1", type =>"D1last206", unit =>""}, removed after andres hint; 33211.msg658108
  594. "sGlobal" => {cmd2=>"FB", type =>"FBglob206", unit =>""}, #allFB
  595. "sTimedate" => {cmd2=>"FC", type =>"FCtime206", unit =>""},
  596. );
  597. my %getsonly206 = (
  598. "sHC1" => {cmd2=>"F4", type =>"F4hc1", unit =>""},
  599. "pFan" => {cmd2=>"01", type =>"01pxx206", unit =>""},
  600. "sLast10errors" => {cmd2=>"D1", type =>"D1last206", unit =>""},
  601. "sFirmware" => {cmd2=>"FD", type =>"FDfirm", unit =>""},
  602. "sFirmware-Id" => {cmd2=>"FE", type =>"FEfirmId", unit =>""},
  603. );
  604. my %getsonly214 = (
  605. "pFan" => {cmd2=>"01", type =>"01pxx214", unit =>""},
  606. "sHC1" => {cmd2=>"F4", type =>"F4hc1214", unit =>""},
  607. );
  608. my %sets=(%sets439539common, %sets439only);
  609. my %gets=(%getsonly439, %sets);
  610. my %OpMode = ("1" =>"standby", "11" => "automatic", "3" =>"DAYmode", "4" =>"setback", "5" =>"DHWmode", "14" =>"manual", "0" =>"emergency");
  611. my %Rev_OpMode = reverse %OpMode;
  612. my %OpModeHC = ("1" =>"normal", "2" => "setback", "3" =>"standby", "4" =>"restart", "5" =>"restart");
  613. my %SomWinMode = ( "01" =>"winter", "02" => "summer");
  614. my %weekday = ( "0" =>"Monday", "1" => "Tuesday", "2" =>"Wednesday", "3" => "Thursday", "4" => "Friday", "5" =>"Saturday", "6" => "Sunday" );
  615. my %weekdaymap = ( "1" =>"Mon", "2" => "Tue", "3" =>"Wed", "4" => "Thu", "5" => "Fri", "6" =>"Sat", "7" => "Sun" );
  616. my %faultmap = ( "0" =>"n.a.", "1" => "F01_AnodeFault", "2" => "F02_SafetyTempDelimiterEngaged", "3" => "F03_HighPreasureGuardFault", "4" => "F04_LowPreasureGuardFault", "5" => "F05_OutletFanFault", "6" => "F06_InletFanFault", "7" => "F07_MainOutputFanFault", "11" => "F11_LowPreasureSensorFault", "12"=> "F12_HighPreasureSensorFault", "15" => "F15_DHW_TemperatureFault", "17" => "F17_DefrostingDurationExceeded", "20" => "F20_SolarSensorFault", "21" => "F21_OutsideTemperatureSensorFault", "22" => "F22_HotGasTemperatureFault", "23" => "F23_CondenserTemperatureSensorFault", "24" => "F24_EvaporatorTemperatureSensorFault", "26" => "F26_ReturnTemperatureSensorFault", "28" => "F28_FlowTemperatureSensorFault", "29" => "F29_DHW_TemperatureSensorFault", "30" => "F30_SoftwareVersionFault", "31" => "F31_RAMfault", "32" => "F32_EEPromFault", "33" => "F33_ExtractAirHumiditySensor", "34" => "F34_FlowSensor", "35" => "F35_minFlowCooling", "36" => "F36_MinFlowRate", "37" => "F37_MinWaterPressure", "40" => "F40_FloatSwitch", "50" => "F50_SensorHeatPumpReturn", "51" => "F51_SensorHeatPumpFlow", "52" => "F52_SensorCondenserOutlet" );
  617. my $firstLoadAll = 0;
  618. my $noanswerreceived = 0;
  619. my $internalHash;
  620. ########################################################################################
  621. #
  622. # THZ_Initialize($)
  623. #
  624. # Parameter hash
  625. #
  626. ########################################################################################
  627. sub THZ_Initialize($) {
  628. my ($hash) = @_;
  629. require "$attr{global}{modpath}/FHEM/DevIo.pm";
  630. # Provider
  631. $hash->{ReadFn} = "THZ_Read";
  632. $hash->{WriteFn} = "THZ_Write";
  633. $hash->{ReadyFn} = "THZ_Ready";
  634. # Normal devices
  635. $hash->{DefFn} = "THZ_Define";
  636. $hash->{UndefFn} = "THZ_Undef";
  637. $hash->{GetFn} = "THZ_Get";
  638. $hash->{SetFn} = "THZ_Set";
  639. $hash->{AttrFn} = "THZ_Attr";
  640. $hash->{FW_detailFn} ="THZ_detailFn";
  641. $hash->{AttrList}= "IODev do_not_notify:1,0 ignore:0,1 dummy:1,0 showtime:1,0 "
  642. ."interval_sGlobal:0,60,120,180,300,600,3600,7200,43200,86400 "
  643. ."interval_sSol:0,60,120,180,300,600,3600,7200,43200,86400 "
  644. ."interval_sDHW:0,60,120,180,300,600,3600,7200,43200,86400 "
  645. ."interval_sHC1:0,60,120,180,300,600,3600,7200,43200,86400 "
  646. ."interval_sHC2:0,60,120,180,300,600,3600,7200,43200,86400 "
  647. ."interval_sHistory:0,3600,7200,28800,43200,86400 "
  648. ."interval_sLast10errors:0,3600,7200,28800,43200,86400 "
  649. ."interval_sHeatRecoveredDay:0,1200,3600,7200,28800,43200,86400 "
  650. ."interval_sHeatRecoveredTotal:0,3600,7200,28800,43200,86400 "
  651. ."interval_sHeatDHWDay:0,1200,3600,7200,28800,43200,86400 "
  652. ."interval_sHeatDHWTotal:0,3600,7200,28800,43200,86400 "
  653. ."interval_sHeatHCDay:0,1200,3600,7200,28800,43200,86400 "
  654. ."interval_sHeatHCTotal:0,3600,7200,28800,43200,86400 "
  655. ."interval_sElectrDHWDay:0,1200,3600,7200,28800,43200,86400 "
  656. ."interval_sElectrDHWTotal:0,3600,7200,28800,43200,86400 "
  657. ."interval_sElectrHCDay:0,1200,3600,7200,28800,43200,86400 "
  658. ."interval_sElectrHCTotal:0,3600,7200,28800,43200,86400 "
  659. ."interval_sBoostDHWTotal:0,3600,7200,28800,43200,86400 "
  660. ."interval_sBoostHCTotal:0,3600,7200,28800,43200,86400 "
  661. ."interval_sFlowRate:0,3600,7200,28800,43200,86400 "
  662. ."interval_sDisplay:0,60,120,180,300 "
  663. ."firmware:4.39,2.06,2.14,5.39,4.39technician "
  664. ."interval_sDewPointHC1:0,60,120,180,300 "
  665. ."simpleReadTimeout:0.25,0.5,1,2,3,4,5,6,7,8,9,10 " #standard has been 0.5 since msg468515 If blocking attribut is NOT enabled then set the timeout value to a maximum value of 0.5 sec.
  666. ."nonblocking:0,1 "
  667. . $readingFnAttributes;
  668. $data{FWEXT}{"/THZ_PrintcurveSVG"}{FUNC} = "THZ_PrintcurveSVG";
  669. }
  670. ########################################################################################
  671. #
  672. # THZ_define
  673. #
  674. # Parameter hash and configuration
  675. #
  676. ########################################################################################
  677. sub THZ_Define($$) {
  678. my ($hash, $def) = @_;
  679. my @a = split("[ \t][ \t]*", $def);
  680. my $name = $a[0];
  681. $hash->{VERSION} = $thzversion;
  682. return "wrong syntax. Correct is: define <name> THZ ".
  683. "{devicename[\@baudrate]|ip:port}"
  684. if(@a != 3);
  685. DevIo_CloseDev($hash);
  686. my $dev = $a[2];
  687. if($dev eq "none") {
  688. Log3 $name, 2, "$name device is none, commands will be echoed only";
  689. $attr{$name}{dummy} = 1;
  690. return undef;
  691. }
  692. $hash->{DeviceName} = $dev;
  693. $attr{$name}{devStateIcon} = 'opened:10px-kreis-gruen disconnected:10px-kreis-rot';
  694. my $ret = DevIo_OpenDev($hash, 0, "THZ_Refresh_all_gets");
  695. #THZ_Testloopapproach($hash);
  696. return $ret;
  697. }
  698. ########################################################################################
  699. #
  700. # THZ_Refresh_all_gets - Called once refreshes current reading for all gets and initializes the regular interval calls
  701. #
  702. # Parameter $hash
  703. #
  704. ########################################################################################
  705. sub THZ_Refresh_all_gets($) {
  706. my ($hash) = @_;
  707. # unlink("data.txt");
  708. THZ_RemoveInternalTimer("THZ_GetRefresh");
  709. Log3 $hash->{NAME}, 5, "thzversion = $thzversion ";
  710. my $timedelay= 5; #start after 5 seconds
  711. foreach my $cmdhash (keys %gets) {
  712. my %par = ( hash => $hash, command => $cmdhash );
  713. #RemoveInternalTimer(\%par); #commented out in v.0161 because appearently redundant; THZ_RemoveInternalTimer is more efficient and both are not needed
  714. InternalTimer(gettimeofday() + ($timedelay) , "THZ_GetRefresh", \%par, 0); #increment 0.6 $timedelay++
  715. $timedelay += 0.6;
  716. } #refresh all registers; the register with interval_command ne 0 will keep on refreshing
  717. }
  718. ########################################################################################
  719. #
  720. # THZ_GetRefresh - Called in regular intervals to obtain current reading
  721. #
  722. # Parameter (hash => $hash, command => "allFB" )
  723. # it get the intervall directly from a attribute; the register with interval_command ne 0 will keep on refreshing
  724. ########################################################################################
  725. sub THZ_GetRefresh($) {
  726. my ($par)=@_;
  727. my $hash=$par->{hash};
  728. my $command=$par->{command};
  729. my $name =$hash->{NAME};
  730. my $interval = AttrVal($name, ("interval_".$command), 0);
  731. if (AttrVal($name, "nonblocking" , "0") =~ /1/ ) {
  732. if (!(exists($hash->{helper}{RUNNING_PID}))) {
  733. DevIo_CloseDev($hash); #close device in parent process
  734. #$hash->{STATE}="disconnected";
  735. my $bctimeout = (AttrVal($name, "simpleReadTimeout", "0.5"))*2 +1;
  736. my $dev = $hash->{DeviceName};
  737. #$hash->{connection} =$hash->{STATE} ."||". $hash->{USBDev} ."||". $hash->{TCPDev} ."||". $hash->{conn} ."||". $hash->{FD} ."||". $selectlist{"$name.$dev"} ;
  738. $hash->{connection} =$hash->{STATE} ."||". $hash->{TCPDev} ."||". $hash->{FD} ."||". $selectlist{"$name.$dev"} ;
  739. Log3 $hash, 3, $hash->{connection};
  740. $hash->{helper}{RUNNING_PID} = BlockingCall("THZ_GetNB", $name."|".$command, "THZ_GetNBDone", $bctimeout, "THZ_GetNBAbort", $hash);
  741. Log3 $hash, 3, "[$name] THZ_GetRefresh($command) BlockingCall started";
  742. }
  743. else {
  744. Log3 $hash, 3, "[$name] THZ_GetRefresh($command) rescheduled (Blocking Call is still running)";
  745. InternalTimer(gettimeofday() + 2, "THZ_GetRefresh", $par, 1);
  746. return;
  747. }
  748. }
  749. else {
  750. THZ_Get($hash, $hash->{NAME}, $command) if ($hash->{STATE} ne "disconnected");
  751. }
  752. if ($interval) {
  753. $interval = 60 if ($interval < 60); #do not allow intervall <60 sec
  754. InternalTimer(gettimeofday()+ $interval, "THZ_GetRefresh", $par, 1) ;
  755. }
  756. if ($command =~ "sFirmware") { # model summary for statistics
  757. my $sFirmwareId = join('', (split(/ |:/, ReadingsVal($name,"sFirmware-Id"," : : : ")))[0..6]);
  758. my $sFirmware= (split(/ /, ReadingsVal($name,"sFirmware"," ")))[1];
  759. $hash->{model}= sprintf("%.5s%s%s", AttrVal($name,"firmware","n.a.")."______", $sFirmware, $sFirmwareId);
  760. }
  761. return;
  762. }
  763. #####################################
  764. # THZ_Write -- simple write
  765. # Parameter: hash and message HEX
  766. #
  767. ########################################################################################
  768. sub THZ_Write($$) {
  769. my ($hash,$bstring) = @_;
  770. my $name = $hash->{NAME};
  771. Log3 $hash->{NAME}, 5, "$hash->{NAME} sending $bstring";
  772. DevIo_SimpleWrite($hash, $bstring, 1);
  773. }
  774. #####################################
  775. # sub THZ_Read($)
  776. # called from the global loop, when the select for hash reports data
  777. # used just for testing the interface
  778. ########################################################################################
  779. sub THZ_Read($) {
  780. my ($hash) = @_;
  781. my $buf = DevIo_SimpleRead($hash);
  782. return "" if(!defined($buf));
  783. my $name = $hash->{NAME};
  784. $hash->{helper}{PARTIAL} .= uc(unpack('H*', $buf));
  785. my $msg=$hash->{helper}{PARTIAL};
  786. my $err;
  787. if ( !defined($hash->{helper}{step}) or (length($msg) == 1) or (($msg =~ m/^01/) and ($msg !~ m/1003$/m ))) {}
  788. else {
  789. if ($hash->{helper}{step} eq "step0") { #Expectedanswer0 is "10" DLE data link escape
  790. if ($msg ne "10") {$err .= " THZ_Get_Com: error found at step0 $msg"; $err .=" NAK!!" if ($msg eq "15"); THZ_Resethelper($hash);}
  791. else { THZ_Write($hash, $hash->{helper}{cmdHex}); $hash->{helper}{step}="step1"; $hash->{helper}{PARTIAL}=""; }
  792. }
  793. elsif ($hash->{helper}{step} eq "step1") { #Expectedanswer1 is "1002", DLE data link escape -- STX start of text
  794. if ($msg eq "10") { }
  795. elsif ($msg eq "15") { $err .= " THZ_Get_Com: error found at step1 NAK!! "; THZ_Resethelper($hash); }
  796. elsif ($msg eq "1002" || $msg eq "02") {THZ_Write($hash, "10"); $hash->{helper}{step}="step2"; $hash->{helper}{PARTIAL}=""; }
  797. }
  798. elsif ($hash->{helper}{step} eq "step2") { #Expectedanswer2 is message from the heatpump
  799. ($err, $msg) = THZ_decode($msg);
  800. $msg.=THZ_Parse1($hash,$msg);
  801. THZ_Write($hash, "10");
  802. #THZ_Resethelper($hash);
  803. }
  804. }
  805. Log3 $name, 3, "$name/RAW: $msg - $err - $hash->{helper}{step}";
  806. }
  807. #####################################
  808. #
  809. # THZ_Resethelper()
  810. #
  811. # Parameter hash
  812. #
  813. ########################################################################################
  814. sub THZ_Resethelper($) {
  815. my ($hash) = @_;
  816. $hash->{helper}{step}="";
  817. $hash->{helper}{cmdHex}="";
  818. $hash->{helper}{PARTIAL}="";
  819. }
  820. sub THZ_Testloopapproach($) {
  821. my ($hash) = @_;
  822. my $cmd="sGlobal";
  823. #my $cmd="sHC1";
  824. my $cmdhash = $gets{$cmd};
  825. THZ_Write($hash, "02");
  826. $hash->{helper}{step}="step0";
  827. $hash->{helper}{cmdHex}=THZ_encodecommand($cmdhash->{cmd2},"get");
  828. $hash->{helper}{PARTIAL}="";
  829. }
  830. #####################################
  831. #
  832. # THZ_Ready($) - Cchecks the status
  833. #
  834. # Parameter hash
  835. #
  836. ########################################################################################
  837. sub THZ_Ready($) {
  838. my ($hash) = @_;
  839. if($hash->{STATE} eq "disconnected")
  840. { THZ_RemoveInternalTimer("THZ_GetRefresh");
  841. select(undef, undef, undef, 0.25); #equivalent to sleep 250ms
  842. return DevIo_OpenDev($hash, 1, "THZ_Refresh_all_gets")
  843. }
  844. # This is relevant for windows/USB only
  845. my $po = $hash->{USBDev};
  846. if($po) {
  847. my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags) = $po->status;
  848. return ($InBytes>0);
  849. }
  850. }
  851. #####################################
  852. #
  853. # THZ_Set - provides a method for setting the heatpump
  854. #
  855. # Parameters: hash and command to be sent to the interface
  856. #
  857. ########################################################################################
  858. sub THZ_Set($@){
  859. my ($hash, @a) = @_;
  860. my $dev = $hash->{DeviceName};
  861. my $name = $hash->{NAME};
  862. return "\"set $name\" needs at least two parameters: <device-parameter> and <value-to-be-modified>" if(@a < 2);
  863. my $cmd = $a[1];
  864. my $arg = $a[2];
  865. my $arg1 = "00:00";
  866. my ($err, $msg) =("", " ");
  867. my $cmdhash = $sets{$cmd};
  868. #return "Unknown argument $cmd, choose one of " . join(" ", sort keys %sets) if(!defined($cmdhash));
  869. if(!defined($cmdhash)) {
  870. my $setList;
  871. foreach my $key (sort keys %sets) {
  872. my $value = $sets{$key};
  873. $setList .= $key;
  874. #if (($value->{type} eq "0clean" or $value->{type} eq "1clean") and $value->{unit} eq "") {
  875. if (($value->{type} eq "0clean" or $value->{type} eq "1clean")) {
  876. #if (($value->{argMax} - $value->{argMin})<2 ) {$setList .= ":uzsuToggle," . join (",", ($value->{argMin} .. $value->{argMax})) . " ";}
  877. if (($value->{argMax} - $value->{argMin})<13 ) {$setList .= ":uzsuSelectRadio," . join (",", ($value->{argMin} .. $value->{argMax})) . " ";}
  878. else {$setList .= ":textField ";}
  879. #else {$setList .= ":slider,$value->{argMin},1,$value->{argMax} ";}
  880. #else {$setList .= ":knob,min:$value->{argMin},max:$value->{argMax},step:1 " ;}
  881. }
  882. elsif ($value->{type} eq "2opmode"){
  883. $setList .= ":" . join (",", (sort {lc $a cmp lc $b} values %OpMode)) . " ";
  884. #$setList .= ":uzsuSelectRadio," . join (",", (sort {lc $a cmp lc $b} values %OpMode)) . " ";
  885. #attr Mythz widgetOverride pOpMode:uzsuDropDown,automatic,standby
  886. }
  887. #elsif ($value->{type} eq "9holy"){
  888. #$setList .= ":time ";
  889. # $setList .= ":textField ";
  890. # }
  891. # elsif ($value->{type} eq "5temp") {
  892. # $setList .= ":slider,$value->{argMin},0.1,$value->{argMax},1 " ;
  893. #$setList .= ":knob,min:$value->{argMin},max:$value->{argMax},step:0.1 " ;
  894. #$setList .= ":knob,min:$value->{argMin},max:$value->{argMax},step:0.1,angleOffset:-125,angleArc:250 "
  895. #attr Mythz widgetOverride p01RoomTempDayHC1:knob,min:22,max:26,step:0.1,angleOffset:-125,angleArc:250
  896. #attr Mythz widgetOverride p01RoomTempDayHC1:slider,$value->{argMin},0.1,$value->{argMax}
  897. #attr Mythz widgetOverride p01RoomTempDayHC1:uzsuDropDown,21,29
  898. #attr Mythz widgetOverride p01RoomTempDayHC1:uzsuSelectRadio,44,234,21
  899. # }
  900. #elsif ($value->{type} eq "6gradient") {
  901. # $setList .= ":slider,$value->{argMin},0.01,$value->{argMax},1 " ;
  902. #$setList .= ":knob,min:$value->{argMin},max:$value->{argMax},step:0.01 " ;
  903. # }
  904. else {
  905. #$setList .= ":textField ";
  906. $setList .= " ";
  907. }
  908. }
  909. return "Unknown argument $cmd, choose one of $setList";
  910. }
  911. return "\"set $name $cmd\" needs at least one further argument: <value-to-be-modified>" if(!defined($arg));
  912. my $cmdHex2 = $cmdhash->{cmd2};
  913. my $argMax = $cmdhash->{argMax};
  914. my $argMin = $cmdhash->{argMin};
  915. #-- check the parameter range
  916. if ($cmdhash->{type} =~ /7prog|8party/) {
  917. ($arg, $arg1)=split('--', $arg);
  918. return "Argument does not match the allowed inerval Min $argMin ...... Max $argMax " if (($arg ne "n.a.") and ($arg1 ne "n.a.") and (($arg1 gt $argMax) or ($arg1 lt $argMin) or ($arg gt $argMax) or ($arg lt $argMin)) ) ;
  919. }
  920. elsif ($cmdhash->{type} eq "2opmode") {
  921. $arg1=undef;
  922. $arg=$Rev_OpMode{$arg};
  923. return "Unknown argument $arg1: $cmd supports " . join(" ", sort values %OpMode) if(!defined($arg));
  924. }
  925. else {
  926. $arg1=undef;
  927. return "Argument does not match the allowed inerval Min $argMin ...... Max $argMax " if(($arg > $argMax) or ($arg < $argMin));
  928. }
  929. #--
  930. my $i=0; my $parsingrule;
  931. THZ_AvoidCollisions($hash);
  932. my $parent = $cmdhash->{parent};
  933. #if I have a father read from it: important for older firmwares
  934. if(defined($parent) ) {
  935. my $parenthash=$gets{$parent};
  936. $cmdHex2 = $parenthash->{cmd2}; #overwrite $cmdHex2 with the parent
  937. Log3 $hash->{NAME}, 5, "searching for parent; parenthash= $parenthash, parent = $parent, cmdHex2 = $cmdHex2 ";
  938. $cmdHex2=THZ_encodecommand($cmdHex2, "get"); #read before write the register
  939. ($err, $msg) = THZ_Get_Comunication($hash, $cmdHex2);
  940. if (defined($err)) {
  941. Log3 $hash->{NAME}, 3, "THZ_Set: error reading register: '$err'";
  942. return ($msg ."\n msg " . $err);
  943. }
  944. substr($msg, 0, 2, ""); #remove the checksum from the head of the payload
  945. Log3 $hash->{NAME}, 5, "read before write from THZ: $msg";
  946. #--
  947. $parsingrule = $parsinghash{$parenthash->{type}};
  948. for (@$parsingrule) {
  949. last if ((@$parsingrule[$i]->[0]) =~ m/$cmd/);
  950. $i++;
  951. }
  952. select(undef, undef, undef, 0.25);
  953. }
  954. else {
  955. $msg = $cmdHex2 . "0000";
  956. my $msgtype =$cmdhash->{type};
  957. $parsingrule = $parsinghash{$msgtype} if(defined($msgtype));
  958. }
  959. my $pos = @$parsingrule[$i]->[1] -2; #I removed the checksum
  960. my $len = @$parsingrule[$i]->[2];
  961. my $parsingtype = @$parsingrule[$i]->[3];
  962. my $dec = @$parsingrule[$i]->[4];
  963. Log3 $hash->{NAME}, 5, "write command (parsed element/pos/len/dec/parsingtype): $i / $pos / $len / $dec / $parsingtype";
  964. $arg *= $dec if ($dec != 1);
  965. $arg = time2quaters($arg) if ($parsingtype eq "quater");
  966. $arg = substr((sprintf(("%0".$len."X"), $arg)), (-1*$len)); #04X converts to hex and fills up 0s; for negative, it must be trunckated.
  967. substr($msg, $pos, $len, $arg);
  968. if (defined($arg1)) { #only in case of "8party" or "7prog"
  969. $arg1 = time2quaters($arg1);
  970. $arg1 = substr((sprintf(("%02X"), $arg1)), -2);
  971. $pos = @$parsingrule[($i+1)]->[1] -2;
  972. substr($msg, $pos, $len, $arg1);
  973. }
  974. Log3 $hash->{NAME}, 5, "THZ_Set: '$cmd $arg $msg' ... Check if port is open. State = '($hash->{STATE})'";
  975. $cmdHex2=THZ_encodecommand($msg,"set");
  976. ($err, $msg) = THZ_Get_Comunication($hash, $cmdHex2);
  977. #$err=undef;
  978. if (defined($err)) {
  979. Log3 $hash->{NAME}, 3, "THZ_Set: Error msg: $err -- $cmdHex2 -> $msg";
  980. return($cmdHex2 . "-". $msg ."--" . $err);
  981. }
  982. else {
  983. select(undef, undef, undef, 0.25);
  984. if (defined($gets{$cmd})) {
  985. $msg=THZ_Get($hash, $name, $cmd);
  986. }
  987. else {
  988. $msg=$cmd.": OK";
  989. }
  990. #because of F8 reset introduced by andre topic=33211 msg695420
  991. #take care of program of the week
  992. if ($a[1] =~ /Mo-So/){
  993. select(undef, undef, undef, 0.05);
  994. $a[1] =~ s/Mo-So/Mo-Fr/; $msg.= "\n" . THZ_Set($hash, @a);
  995. select(undef, undef, undef, 0.05);
  996. $a[1] =~ s/Mo-Fr/Sa-So/; $msg.="\n" . THZ_Set($hash, @a);
  997. }
  998. elsif ($a[1] =~ /Mo-Fr/) {
  999. select(undef, undef, undef, 0.05);
  1000. $a[1] =~ s/_Mo-Fr_/_Mo_/; $msg.="\n" . THZ_Set($hash, @a);
  1001. select(undef, undef, undef, 0.05);
  1002. $a[1] =~ s/_Mo_/_Tu_/ ; $msg.="\n" . THZ_Set($hash, @a);
  1003. select(undef, undef, undef, 0.05);
  1004. $a[1] =~ s/_Tu_/_We_/ ; $msg.="\n" . THZ_Set($hash, @a);
  1005. select(undef, undef, undef, 0.05);
  1006. $a[1] =~ s/_We_/_Th_/ ; $msg.="\n" . THZ_Set($hash, @a);
  1007. select(undef, undef, undef, 0.05);
  1008. $a[1] =~ s/_Th_/_Fr_/ ; $msg.="\n" . THZ_Set($hash, @a);
  1009. }
  1010. elsif ($a[1] =~ /Sa-So/){
  1011. select(undef, undef, undef, 0.05);
  1012. $a[1] =~ s/_Sa-So_/_Sa_/; $msg.="\n" . THZ_Set($hash, @a);
  1013. select(undef, undef, undef, 0.05);
  1014. $a[1] =~ s/_Sa_/_So_/ ; $msg.="\n" . THZ_Set($hash, @a);
  1015. }
  1016. #split _ mo-fr when [3] undefined do nothing, when mo-fr chiama gli altri
  1017. return ($msg);
  1018. }
  1019. }
  1020. ########################################################################################
  1021. #
  1022. # THZ_GetNB - NonBlocking Get parameter from heatpump
  1023. #
  1024. # Parameters: "name | command" (single string)
  1025. #
  1026. ########################################################################################
  1027. sub THZ_GetNB($){
  1028. my ($string) = @_;
  1029. my ($name, $cmd) = split("\\|", $string);
  1030. my $hash = $defs{$name};
  1031. my $dev = $hash->{DeviceName};
  1032. my $ret = DevIo_OpenDev($hash, 0, undef); #open device in child process
  1033. #($hash->{STATE}, $hash->{USBDev} , $hash->{TCPDev} , $hash->{conn} , $hash->{FD} , $selectlist{"$name.$dev"}) = split("\\|", $hash->{connection});
  1034. #($hash->{STATE}, $hash->{TCPDev} , $hash->{FD} , $selectlist{"$name.$dev"}) = split("\\|", $hash->{connection});
  1035. #$selectlist{"$name.$dev"} = $hash;
  1036. #open (MYFILE, '>>data.txt');
  1037. #print MYFILE ($hash->{connection} . "\n");
  1038. #close (MYFILE);
  1039. if (defined($ret)) {
  1040. Log3 $hash, 3, "[$name] THZ_GetNB: open device $hash->{DeviceName} error:$ret";
  1041. return ("$name|$cmd|$ret");
  1042. }
  1043. my $msg = THZ_Get($hash, $name, $cmd);
  1044. DevIo_CloseDev($hash); #close device in child process
  1045. if ($msg =~ m/\n/m) { #error message from get contains \n
  1046. return ("$name|$cmd|[ERROR]");
  1047. }
  1048. else {
  1049. return ("$name|$cmd|$msg");
  1050. }
  1051. }
  1052. ########################################################################################
  1053. #
  1054. # THZ_GetNBDone - Finish Function
  1055. #
  1056. # Parameters: "name | command | message" (single string)
  1057. #
  1058. ########################################################################################
  1059. sub THZ_GetNBDone($){
  1060. my ($string) = @_;
  1061. my ($name, $cmd, $msg) = split("\\|", $string);
  1062. my $hash = $defs{$name};
  1063. Log3 $hash, 4, "[$name] THZ_GetNBDone: $cmd - $msg";
  1064. readingsSingleUpdate($hash, $cmd, $msg, 1) if ($msg ne "[ERROR]");
  1065. delete($hash->{helper}{RUNNING_PID}) if (defined($hash->{helper}{RUNNING_PID}));
  1066. DevIo_OpenDev($hash, 1, undef); # if($hash->{STATE} ne "opened"); #reopen device for parent process
  1067. return;
  1068. }
  1069. ########################################################################################
  1070. #
  1071. # THZ_GetNBAbort - Abort Function
  1072. #
  1073. # Parameter: hash
  1074. #
  1075. ########################################################################################
  1076. sub THZ_GetNBAbort($){
  1077. my ($hash) = @_;
  1078. delete($hash->{helper}{RUNNING_PID}) if (defined($hash->{helper}{RUNNING_PID}));
  1079. DevIo_OpenDev($hash, 1, undef);# if($hash->{STATE} ne "opened"); #reopen device for parent process
  1080. Log3 $hash->{NAME}, 3, "BlockingCall for ".$hash->{NAME}." was aborted";
  1081. return;
  1082. }
  1083. ########################################################################################
  1084. #
  1085. # THZ_AvoidCollisions - prevents collisions between parent and child process is used at the beginning of THZ_Get and THZ_Set
  1086. #
  1087. # Parameter: hash
  1088. #
  1089. ########################################################################################
  1090. sub THZ_AvoidCollisions($) {
  1091. my ($hash) = @_;
  1092. # if child found, wait 0,25 second, and kill it
  1093. # maybe after 1 second child would have finished, but its THZ_GetNBDone is blocked
  1094. if (defined($hash->{helper}{RUNNING_PID})){
  1095. select(undef, undef, undef, 0.25);
  1096. BlockingKill($hash->{helper}{RUNNING_PID});
  1097. delete($hash->{helper}{RUNNING_PID});
  1098. DevIo_OpenDev($hash, 1, undef); #if($hash->{STATE} ne "opened");
  1099. #reset heatpump
  1100. THZ_Write($hash, "10");
  1101. select(undef, undef, undef, 0.1);
  1102. THZ_ReadAnswer($hash);
  1103. THZ_Write($hash, "10");
  1104. select(undef, undef, undef, 0.1);
  1105. Log3 $hash->{NAME}, 3, "Possible collision in ".$hash->{NAME}." was aborted";
  1106. }
  1107. return;
  1108. }
  1109. #####################################
  1110. #
  1111. # THZ_Get - provides a method for polling the heatpump
  1112. #
  1113. # Parameters: hash and command to be sent to the interface
  1114. #
  1115. ########################################################################################
  1116. sub THZ_Get($@) {
  1117. my ($hash, @a) = @_;
  1118. my $dev = $hash->{DeviceName};
  1119. my $name = $hash->{NAME};
  1120. return "\"get $name\" needs one parameter" if(@a != 2);
  1121. my $cmd = $a[1];
  1122. my ($err, $msg2) =("", " ");
  1123. if ($cmd eq "debug_read_raw_register_slow") {
  1124. THZ_debugread($hash);
  1125. return ("all raw registers read and saved");
  1126. }
  1127. if ($cmd eq "zBackupParameters") {
  1128. $err=THZ_backup_readings($hash);
  1129. return $err;
  1130. }
  1131. my $cmdhash = $gets{$cmd};
  1132. #return "Unknown argument $cmd, choose one of " . join(" ", sort keys %gets) if(!defined($cmdhash));
  1133. if(!defined($cmdhash)) {
  1134. my $getList;
  1135. foreach my $key (sort keys %gets) {$getList .= "$key:noArg ";}
  1136. $getList .= "zBackupParameters:noArg";
  1137. return "Unknown argument $cmd, choose one of $getList";
  1138. }
  1139. Log3 $hash->{NAME}, 5, "THZ_Get: Try to get '$cmd'";
  1140. THZ_AvoidCollisions($hash);
  1141. my $parent = $cmdhash->{parent}; #if I have a father read from it
  1142. if(defined($parent) ) {
  1143. my ($seconds, $microseconds) = gettimeofday();
  1144. $seconds= abs($seconds - time_str2num(ReadingsTimestamp($name, $parent, "1970-01-01 01:00:00")));
  1145. my $risultato=ReadingsVal($name, $parent, 0);
  1146. $risultato=THZ_Get($hash, $name, $parent) if ($seconds > 20 ); #update of the parent: if under 20sec use the current value
  1147. #$risultato=THZ_Parse1($hash,"B81700C800BE00A001C20190006402010000E601D602");
  1148. my $parenthash=$gets{$parent}; my $parsingrule = $parsinghash{$parenthash->{type}};
  1149. my $i=0;
  1150. for (@$parsingrule) {
  1151. last if ((@$parsingrule[$i]->[0]) =~ m/$cmd/);
  1152. $i++;}
  1153. $msg2=(split ' ', $risultato)[$i*2+1];
  1154. Log3 $hash->{NAME}, 5, "THZ_split: $msg2 --- $risultato";
  1155. }
  1156. else {
  1157. my $cmdHex2 = $cmdhash->{cmd2};
  1158. if(defined($cmdHex2) ) {
  1159. #empty
  1160. ($err, $msg2) = THZ_Get_Comunication($hash, THZ_encodecommand($cmdHex2,"get") );
  1161. if (defined($err)) {
  1162. Log3 $hash->{NAME}, 3, "THZ_Get: Error msg2: $err -- $cmdHex2 -> $msg2";
  1163. return ($msg2 ."\n msg2 " . $err);
  1164. }
  1165. $msg2 = THZ_Parse1($hash,$msg2);
  1166. }
  1167. my $cmdHex3 = $cmdhash->{cmd3};
  1168. if(defined($cmdHex3)) {
  1169. my $msg3= " ";
  1170. #empty
  1171. ($err, $msg3) = THZ_Get_Comunication($hash, THZ_encodecommand($cmdHex3,"get"));
  1172. if (defined($err)) {
  1173. Log3 $hash->{NAME}, 3, "THZ_Get: Error msg3: $err -- $cmdHex3 -> $msg3";
  1174. return ($msg3 ."\n msg3 " . $err);
  1175. }
  1176. $msg2 = THZ_Parse1($hash,$msg3) * 1000 + $msg2 ;
  1177. }
  1178. }
  1179. my $unit = $cmdhash->{unit};
  1180. $msg2 = $msg2 . $unit if(defined($unit)) ;
  1181. my $activatetrigger =1;
  1182. readingsSingleUpdate($hash, $cmd, $msg2, $activatetrigger);
  1183. return ($msg2);
  1184. }
  1185. #####################################
  1186. #
  1187. # THZ_Get_Comunication- provides a method for comunication called from THZ_Get or THZ_Set
  1188. #
  1189. # Parameter hash and CMD2 or 3
  1190. #
  1191. ########################################################################################
  1192. sub THZ_Get_Comunication($$) {
  1193. my ($hash, $cmdHex) = @_;
  1194. my ($err, $msg) =("", " ");
  1195. Log3 $hash->{NAME}, 5, "THZ_Get_Comunication: Check if port is open. State = '($hash->{STATE})'";
  1196. if (!(($hash->{STATE}) eq "opened")) { return("closed connection", "");}
  1197. select(undef, undef, undef, 0.001);
  1198. THZ_Write($hash, "02"); # step0 --> STX start of text
  1199. ($err, $msg) = THZ_ReadAnswer($hash);
  1200. #Expectedanswer0 is "10" DLE data link escape
  1201. if ($msg ne "10") {$err .= " THZ_Get_Com: error found at step0 $msg"; $err .=" NAK!!" if ($msg eq "15"); select(undef, undef, undef, 0.1); return($err, $msg) ;}
  1202. else {
  1203. THZ_Write($hash, $cmdHex); # step1 --> send request SOH start of heading -- Null -- ?? -- DLE data link escape -- EOT End of Text
  1204. ($err, $msg) = THZ_ReadAnswer($hash);
  1205. }
  1206. if ((defined($err))) { $err .= " THZ_Get_Com: error found at step1 "; select(undef, undef, undef, 0.1); return($err, $msg) ;}
  1207. # Expectedanswer1 is "1002", DLE data link escape -- STX start of text
  1208. if ($msg eq "10") { ($err, $msg) = THZ_ReadAnswer($hash);}
  1209. elsif ($msg eq "15") { $err .= " THZ_Get_Com: error found at step1 NAK!! "; select(undef, undef, undef, 0.1); return($err, $msg) ;}
  1210. if ($msg eq "1002" || $msg eq "02") {
  1211. THZ_Write($hash, "10"); # step2 send DLE data link escape
  1212. ($err, $msg) = THZ_ReadAnswer($hash); # Expectedanswer2 // read from the heatpump
  1213. THZ_Write($hash, "10");
  1214. }
  1215. if ((defined($err))) { $err .= " THZ_Get_Com: error found at step2"; select(undef, undef, undef, 0.1);}
  1216. else {($err, $msg) = THZ_decode($msg);} #clean up and remove footer and header
  1217. return($err, $msg) ;
  1218. }
  1219. #####################################
  1220. #
  1221. # THZ_ReadAnswer- provides a method for simple read
  1222. #
  1223. # Parameter hash and command to be sent to the interface
  1224. #
  1225. ########################################################################################
  1226. sub THZ_ReadAnswer($) {
  1227. my ($hash) = @_;
  1228. my $name = $hash->{NAME};
  1229. Log3 $hash->{NAME}, 5, "$name start Function THZ_ReadAnswer";
  1230. select(undef, undef, undef, 0.025) if( $^O =~ /Win/ ); ###delay of 25 ms for windows-OS, because SimpleReadWithTimeout does not wait
  1231. my $rtimeout = (AttrVal($name, "simpleReadTimeout", "0.5")) / 2; #added for Andre he would like to have 8/2 second.
  1232. $rtimeout = 0.5 if (AttrVal($name, "nonblocking", "0") eq 0); # set to 0.5s is nonblocking disabled
  1233. my $buf = DevIo_SimpleReadWithTimeout($hash, $rtimeout);
  1234. $buf = DevIo_SimpleReadWithTimeout($hash, $rtimeout) if(!defined($buf)) ; #added for karl msg468515
  1235. return ("THZ_ReadAnswer: InterfaceNotRespondig. Maybe too slow", "") if(!defined($buf)) ;
  1236. my $data = uc(unpack('H*', $buf));
  1237. my $count =1;
  1238. my $countmax = 60;
  1239. while (( (length($data) == 1) or (($data =~ m/^01/) and ($data !~ m/1003$/m ))) and ($count <= $countmax)){
  1240. select(undef, undef, undef, 0.005) if( $^O =~ /Win/ ); ###delay of 5 ms for windows-OS, because SimpleReadWithTimeout does not wait
  1241. my $buf1 = DevIo_SimpleReadWithTimeout($hash, 0.02);
  1242. Log3($hash->{NAME}, 5, "double read $count activated $data");
  1243. if(defined($buf1)) {
  1244. $buf .= $buf1 ;
  1245. $data = uc(unpack('H*', $buf));
  1246. Log3($hash->{NAME}, 5, "double read $count result with buf1 $data");
  1247. $count ++;
  1248. }
  1249. else{ $count += 5; }
  1250. }
  1251. return ("THZ_ReadAnswer: Interface max repeat limited to $countmax ", $data) if ($count == ($countmax +1));
  1252. Log3 $hash->{NAME}, 5, "THZ_ReadAnswer: uc unpack: '$data'";
  1253. return (undef, $data);
  1254. }
  1255. #####################################
  1256. #
  1257. # THZ_checksum - takes a string, removes the footer (4bytes) and computes checksum (without checksum of course)
  1258. #
  1259. # Parameter string
  1260. # returns the checksum 2bytes
  1261. #
  1262. ########################################################################################
  1263. sub THZ_checksum($) {
  1264. my ($stringa) = @_;
  1265. my $ml = length($stringa) - 4;
  1266. my $checksum = 0;
  1267. for(my $i = 0; $i < $ml; $i += 2) {
  1268. ($checksum= $checksum + hex(substr($stringa, $i, 2))) if ($i != 4);
  1269. }
  1270. return (sprintf("%02X", ($checksum %256)));
  1271. }
  1272. #####################################
  1273. #
  1274. # hex2int - convert from hex to int with sign 16bit
  1275. #
  1276. ########################################################################################
  1277. sub hex2int($) {
  1278. my ($num) = @_;
  1279. $num = unpack('s', pack('S', hex($num)));
  1280. return $num;
  1281. }
  1282. ####################################
  1283. #
  1284. # quaters2time - convert from hex to time; specific to the week programm registers
  1285. #
  1286. # parameter 1 byte representing number of quarter from midnight
  1287. # returns string representing time
  1288. #
  1289. # example: value 1E is converted to decimal 30 and then to a time 7:30
  1290. ########################################################################################
  1291. sub quaters2time($) {
  1292. my ($num) = @_;
  1293. return("n.a.") if($num eq "80");
  1294. my $quarters= hex($num) %4;
  1295. my $hour= (hex($num) - $quarters)/4 ;
  1296. my $time = sprintf("%02u", ($hour)) . ":" . sprintf("%02u", ($quarters*15));
  1297. return $time;
  1298. }
  1299. ####################################
  1300. #
  1301. # time2quarters - convert from time to quarters in hex; specific to the week programm registers
  1302. #
  1303. # parameter: string representing time
  1304. # returns: 1 byte representing number of quarter from midnight
  1305. #
  1306. # example: a time 7:30 is converted to decimal 30
  1307. ########################################################################################
  1308. sub time2quaters($) {
  1309. my ($stringa) = @_;
  1310. return("128") if($stringa eq "n.a.");
  1311. my ($h,$m) = split(":", $stringa);
  1312. $m = 0 if(!$m);
  1313. $h = 0 if(!$h);
  1314. my $num = $h*4 + int($m/15);
  1315. return ($num);
  1316. }
  1317. ####################################
  1318. #
  1319. # bitmap2string - convert from bitmap to concatenated string
  1320. #
  1321. # parameter: bitmap representing yes/no, hashref to stringmapping
  1322. # returns: concatenated string
  1323. #
  1324. ########################################################################################
  1325. sub bitmap2string($$) {
  1326. my($bitmap, $href) = @_;
  1327. my $idx = 1;
  1328. my $res = "";
  1329. foreach my $bit (split //, $bitmap) {
  1330. $res .= $href->{$idx} if ($bit);
  1331. $idx++;
  1332. }
  1333. return $res;
  1334. }
  1335. ####################################
  1336. #
  1337. # THZ_replacebytes - replaces bytes in string
  1338. #
  1339. # parameters: string, bytes to be searched, replacing bytes
  1340. # retunrns changed string
  1341. #
  1342. ########################################################################################
  1343. sub THZ_replacebytes($$$) {
  1344. my ($stringa, $find, $replace) = @_;
  1345. my $leng_str = length($stringa);
  1346. my $leng_find = length($find);
  1347. my $new_stringa ="";
  1348. for(my $i = 0; $i < $leng_str; $i += 2) {
  1349. if (substr($stringa, $i, $leng_find) eq $find){
  1350. $new_stringa=$new_stringa . $replace;
  1351. if ($leng_find == 4) {$i += 2;}
  1352. }
  1353. else {$new_stringa=$new_stringa . substr($stringa, $i, 2);};
  1354. }
  1355. return ($new_stringa);
  1356. }
  1357. ## usage THZ_overwritechecksum("0100XX". $cmd."1003"); not needed anymore
  1358. sub THZ_overwritechecksum($) {
  1359. my ($stringa) = @_;
  1360. my $checksumadded=substr($stringa,0,4) . THZ_checksum($stringa) . substr($stringa,6);
  1361. return($checksumadded);
  1362. }
  1363. ####################################
  1364. #
  1365. # THZ_encodecommand - creates a telegram for the heatpump with a given command
  1366. #
  1367. # usage THZ_encodecommand($cmd,"get") or THZ_encodecommand($cmd,"set");
  1368. # parameter string,
  1369. # retunrns encoded string
  1370. #
  1371. ########################################################################################
  1372. sub THZ_encodecommand($$) {
  1373. my ($cmd,$getorset) = @_;
  1374. my $header = "0100";
  1375. $header = "0180" if ($getorset eq "set"); # "set" and "get" have differnt header
  1376. my $footer ="1003";
  1377. my $checksumadded=THZ_checksum($header . "XX" . $cmd . $footer) . $cmd;
  1378. # each 2B byte must be completed by byte 18
  1379. # each 10 byte must be repeated (duplicated)
  1380. my $find = "10";
  1381. my $replace = "1010";
  1382. #$checksumadded =~ s/$find/$replace/g; #problems in 1% of the cases, in middle of a byte
  1383. $checksumadded=THZ_replacebytes($checksumadded, $find, $replace);
  1384. $find = "2B";
  1385. $replace = "2B18";
  1386. #$checksumadded =~ s/$find/$replace/g;
  1387. $checksumadded=THZ_replacebytes($checksumadded, $find, $replace);
  1388. return($header. $checksumadded .$footer);
  1389. }
  1390. ####################################
  1391. #
  1392. # THZ_decode - decodes a telegram from the heatpump -- no parsing here
  1393. #
  1394. # Each response has the same structure as request - header (four bytes), optional data and footer:
  1395. # Header: 01
  1396. # Read/Write: 00 for Read (get) response, 80 for Write (set) response; when some error occured, then device stores error code here; actually, I know only meaning of error 03 = unknown command
  1397. # Checksum: ? 1 byte - the same algorithm as for request
  1398. # Command: ? 1 byte - should match Request.Command
  1399. # Data: ? only when Read, length depends on data type
  1400. # Footer: 10 03
  1401. #
  1402. ########################################################################################
  1403. sub THZ_decode($) {
  1404. my ($message_orig) = @_;
  1405. # raw data received from device have to be de-escaped before header evaluation and data use:
  1406. my $find = "1010"; # - each sequece 10 10 must be replaced with single byte 10
  1407. my $replace = "10";
  1408. $message_orig=THZ_replacebytes($message_orig, $find, $replace);
  1409. $find = "2B18"; # - each sequece 2B 18 must be replaced with single byte 2B
  1410. $replace = "2B";
  1411. $message_orig=THZ_replacebytes($message_orig, $find, $replace);
  1412. #Check if answer is NAK
  1413. if (length($message_orig) == 2 && $message_orig eq "15") {
  1414. return("decode: NAK received from device",$message_orig);
  1415. }
  1416. #check header and if ok 0100, check checksum and return the decoded msg
  1417. my $header = substr($message_orig,0,4);
  1418. if ($header eq "0100") {
  1419. if (THZ_checksum($message_orig) eq substr($message_orig,4,2)) {
  1420. $message_orig =~ /0100(.*)1003/;
  1421. my $message = $1;
  1422. return (undef, $message);
  1423. }
  1424. else {return(THZ_checksum($message_orig) . "decode: crc_error in answer", $message_orig)};
  1425. }
  1426. if ($header eq "0101") { return ("decode: timing issue", $message_orig);}
  1427. if ($header eq "0103") { return ("decode: command not known", $message_orig);}
  1428. if ($header eq "0102") { return("decode: CRC error in request", $message_orig);}
  1429. if ($header eq "0104") { return("decode: UNKNOWN Register REQUEST", $message_orig);}
  1430. if ($header eq "0180") { return(undef, $message_orig);}
  1431. return("decode: new unknown answer " , $message_orig);
  1432. }
  1433. ###############################
  1434. #added by jakob do not know if needed
  1435. #
  1436. ###############################
  1437. local $SIG{__WARN__} = sub {
  1438. my $message = shift;
  1439. if (!defined($internalHash)) {
  1440. Log3 "Mythz", 3, "EXCEPTION in THZ: '$message'";
  1441. }
  1442. else
  1443. {
  1444. Log3 $internalHash->{NAME},3, "EXCEPTION in THZ: '$message'";
  1445. }
  1446. };
  1447. #######################################
  1448. #THZ_Parse1($) could be used in order to test an external config file; I do not know if I want it
  1449. #e.g. {THZ_Parse1(undef,"F70B000500E6")}
  1450. #######################################
  1451. sub THZ_Parse1($$) {
  1452. my ($hash,$message) = @_;
  1453. Log3 $hash->{NAME}, 5, "Parse message: $message";
  1454. my $length = length($message);
  1455. Log3 $hash->{NAME}, 5, "Message length: $length";
  1456. my $parsingcmd = substr($message,2,2);
  1457. $parsingcmd = substr($message,2,6) if (($parsingcmd =~ m/(0A|0B|0C)/) and (AttrVal($hash->{NAME}, "firmware" , "4.39") !~ /^2/) );
  1458. my $msgtype;
  1459. my $parsingrule;
  1460. my $parsingelement;
  1461. # search for the type in %gets
  1462. foreach my $cmdhash (values %gets) {
  1463. if (defined ($cmdhash->{cmd2}) and ($cmdhash->{cmd2} eq $parsingcmd))
  1464. {$msgtype = $cmdhash->{type} ;
  1465. last
  1466. }
  1467. elsif (defined ($cmdhash->{cmd3}))
  1468. { if ($cmdhash->{cmd3} eq $parsingcmd)
  1469. {$msgtype = $cmdhash->{type} ;
  1470. last
  1471. }
  1472. }
  1473. }
  1474. $parsingrule = $parsinghash{$msgtype} if(defined($msgtype));
  1475. my $ParsedMsg = $message;
  1476. if(defined($parsingrule)) {
  1477. $ParsedMsg = "";
  1478. for $parsingelement (@$parsingrule) {
  1479. my $parsingtitle = $parsingelement->[0];
  1480. my $positionInMsg = $parsingelement->[1];
  1481. my $lengthInMsg = $parsingelement->[2];
  1482. my $Type = $parsingelement->[3];
  1483. my $divisor = $parsingelement->[4];
  1484. #check if parsing out of message, and fill with zeros; the other possibility is to skip the step.
  1485. if (length($message) < ($positionInMsg + $lengthInMsg)) {
  1486. Log3 $hash->{NAME}, 3, "THZ_Parsing: offset($positionInMsg) + length($lengthInMsg) is longer then message : '$message'";
  1487. $message.= '0' x ($positionInMsg + $lengthInMsg - length($message)); # fill up with 0s to the end if needed
  1488. #Log3 $hash->{NAME},3, "after: '$message'";
  1489. }
  1490. my $value = substr($message, $positionInMsg, $lengthInMsg);
  1491. if ($Type eq "hex") {$value= hex($value);}
  1492. elsif ($Type eq "year") {$value= hex($value)+2000;}
  1493. elsif ($Type eq "hex2int") {$value= hex2int($value);}
  1494. elsif ($Type eq "turnhexdate") {$value= substr($value, 2,2) . substr($value, 0,2); $value= sprintf("%02u.%02u", hex($value)/100, hex($value)%100); }
  1495. elsif ($Type eq "hexdate") {$value= sprintf("%02u.%02u", hex($value)/100, hex($value)%100) ;}
  1496. #elsif ($Type eq "turnhex2time") {$value= sprintf(join(':', split("\\.", hex(substr($value, 2,2) . substr($value, 0,2))/100))) ;}
  1497. #elsif ($Type eq "hex2time") {$value= sprintf(join(':', split("\\.", hex(substr($value, 0,2) . substr($value, 2,2))/100))) ;}
  1498. elsif ($Type eq "turnhex2time") {$value= substr($value, 2,2) . substr($value, 0,2); $value= sprintf("%02u:%02u", hex($value)/100, hex($value)%100); }
  1499. elsif ($Type eq "hex2time") {$value= sprintf("%02u:%02u", hex($value)/100, hex($value)%100) ;}
  1500. elsif ($Type eq "swver") {$value= sprintf("%01u.%02u", hex(substr($value, 0,2)), hex(substr($value, 2,2)));}
  1501. elsif ($Type eq "hex2ascii") {$value= uc(pack('H*', $value));}
  1502. elsif ($Type eq "opmode") {$value= $OpMode{hex($value)};}
  1503. elsif ($Type eq "opmodehc") {$value= $OpModeHC{hex($value)};}
  1504. elsif ($Type eq "esp_mant") {$value= sprintf("%.3f", unpack('f', pack( 'L', reverse(hex($value)))));}
  1505. elsif ($Type eq "somwinmode") {$value= $SomWinMode{($value)};}
  1506. elsif ($Type eq "hex2wday") {$value= bitmap2string(unpack('b7', pack('H*',$value)), \%weekdaymap);}
  1507. elsif ($Type eq "hex2error") {$value= bitmap2string(unpack('b32', pack('H*',$value)), \%faultmap);}
  1508. elsif ($Type eq "weekday") {$value= $weekday{($value)};}
  1509. elsif ($Type eq "faultmap") {$value= $faultmap{(hex($value))};}
  1510. elsif ($Type eq "quater") {$value= quaters2time($value);}
  1511. elsif ($Type eq "bit0") {$value= (hex($value) & 0b0001) / 0b0001;}
  1512. elsif ($Type eq "bit1") {$value= (hex($value) & 0b0010) / 0b0010;}
  1513. elsif ($Type eq "bit2") {$value= (hex($value) & 0b0100) / 0b0100;}
  1514. elsif ($Type eq "bit3") {$value= (hex($value) & 0b1000) / 0b1000;}
  1515. elsif ($Type eq "nbit0") {$value= 1-((hex($value) & 0b0001) / 0b0001);}
  1516. elsif ($Type eq "nbit1") {$value= 1-((hex($value) & 0b0010) / 0b0010);}
  1517. elsif ($Type eq "n.a.") {$value= "n.a.";}
  1518. $value = $value/$divisor if ($divisor != 1);
  1519. $ParsedMsg .= $parsingtitle . $value;
  1520. }
  1521. }
  1522. return (undef, $ParsedMsg);
  1523. }
  1524. ########################################################################################
  1525. # only for debug
  1526. #
  1527. ########################################################################################
  1528. sub THZ_debugread($){
  1529. my ($hash) = @_;
  1530. my ($err, $msg) =("", " ");
  1531. my @numbers=('01', '09', '16', 'D1', 'D2', 'E8', 'E9', 'F2', 'F3', 'F4', 'F5', 'F6', 'F8', 'FB', 'FC', 'FD', 'FE', 'FF');
  1532. #my @numbers=('FB', 'FB', 'FB', 'FB', 'FB', 'FB', 'FB', '0A05B3', '0A05B4', '0B0264', '0B0287', '0B0582', '0B0583', '0B0584', '0A0126','0A0265', '0A0597', '0A0598', '0A0599', '0A059C','0A05AD', '0A05B0', '0A05DD', '0A05DE', '0A0BA3');
  1533. #my @numbers=(1, 3, 4, 5, 8, 12, 13, 14, 15, 17, 18, 19, 20, 22, 26, 39, 40, 82, 83, 86, 87, 96, 117, 128, 239, 265, 268, 269, 270, 271, 274, 275, 278, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 297, 299, 317, 320, 354, 384, 410, 428, 440, 442, 443, 444, 445, 446, 603, 607, 612, 613, 634, 647, 650, 961, 1385, 1386, 1387, 1388, 1389, 1391, 1392, 1393, 1394, 1395, 1396, 1397, 1398, 1399, 1400, 1401, 1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409, 1410, 1411, 1412, 830, 1414, 1415, 1416, 1417, 1418, 1419, 1420, 1421, 1422, 1423, 1424, 1425, 1426, 1427, 1428, 1429, 1430, 1431, 1432, 1433, 1434, 1435, 1436, 1437, 1438, 1439, 1440, 1441, 1442, 1443, 1444, 1445, 1446, 1447, 1448, 1449, 1450, 1451, 1452, 1453, 1454, 1455, 1456, 1457, 1458, 1459, 1460, 1461, 1462, 1463, 1464, 1465, 1466, 1467, 1468, 1469, 1470, 1471, 1472, 1473, 1474, 1475, 1476, 1477, 1478, 1479, 1480, 1481, 2970, 2971, 2974, 2975, 2976, 2977, 2978, 2979, 1413, 1426, 1427, 474, 1499, 757, 758, 952, 955, 1501, 1502, 374, 1553, 1554, 1555, 272, 1489, 1490, 1491, 1492, 1631, 933, 934, 1634, 928, 718, 64990, 64991, 64992, 64993, 2372, 2016, 936, 937, 938, 939, 1632, 2350, 2351, 2352, 2353, 2346, 2347, 2348, 2349, 2334, 2335, 2336, 2337, 2330, 2331, 2332, 2333, 2344, 2345, 2340, 2341, 942, 943, 944, 945, 328, 2029, 2030, 2031, 2032, 2033);
  1534. #my @numbers=(1, 3, 12, 13, 14, 15, 19, 20, 22, 26, 39, 82, 83, 86, 87, 96, 239, 265, 268, 274, 278, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 320, 354, 384, 410, 428, 440, 442, 443, 444, 445, 446, 613, 634, 961, 1388, 1389, 1391, 1392, 1393, 1394, 1395, 1396, 1397, 1398, 1399, 1400, 1401, 1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409, 1414, 1415, 1416, 1417, 1418, 1419, 1420, 1421, 1422, 1423, 1430, 1431, 1432, 1433, 1434, 1435, 1436, 1439, 1440, 1441, 1442, 1443, 1444, 1445, 1446, 1447, 1448, 1449, 1450, 1451, 1452, 1453, 1454, 1455, 1456, 1457, 1458, 1459, 1460, 1461, 1462, 1463, 1464, 1465, 1466, 1467, 1468, 1470, 1471, 1472, 1473, 1474, 1475, 1476, 1477, 1478, 1479, 2970, 2971, 2975, 2976, 2977, 2978, 2979, 474, 1499, 757, 758, 952, 955, 1501, 1502, 374, 1553, 1554, 272, 1489, 1491, 1492, 1631, 718, 64990, 64991, 64992, 64993, 2372, 2016, 936, 937, 938, 939, 1632, 2350, 2351, 2352, 2353, 2346, 2347, 2348, 2349, 2334, 2335, 2336, 2337, 2330, 2331, 2332, 2333, 2344, 2345, 2340, 2341, 942, 943, 944, 945, 328, );
  1535. # my @numbers=(239, 410, 603, 607, 634, 830, 1424, 1425, 1426, 1427, 1428, 1429, 1430, 1431, 1432, 1433, 1434, 1435, 1444, 1445, 1446, 1447, 1448, 1449, 1450, 1451, 1452, 1453, 1454, 1455, 1456, 1457, 1467, 1468, 1469, 1478, 1479, 1480, 1481, 2970, 2971, 2974, 2975, 2976, 2977, 2978, 2979, 1413, 1426, 1427, 474, 1501, 1502, 374, 1631, 718, 2372, 328);
  1536. #my @numbers = (1..256);
  1537. #my @numbers = (1..65535);
  1538. # my @numbers = (1..3179);
  1539. my $indice= "FF";
  1540. unlink("data.txt"); #delete debuglog
  1541. #my $i=0;
  1542. foreach $indice(@numbers) {
  1543. # $i=$i+1;
  1544. #my $cmd = sprintf("%02X", $indice);
  1545. # my $cmd = sprintf("%04X", $indice);
  1546. #my $cmd = "0A" . sprintf("%04X", $indice);
  1547. my $cmd = $indice;
  1548. my $cmdHex2 = THZ_encodecommand($cmd,"get");
  1549. #($err, $msg) = THZ_Get_Comunication($hash, $cmdHex2);
  1550. #STX start of text
  1551. THZ_Write($hash, "02");
  1552. ($err, $msg) = THZ_ReadAnswer($hash);
  1553. #select(undef, undef, undef, (0.05*$i));
  1554. #if you wait here more than 600ms connection dropped
  1555. # send request
  1556. THZ_Write($hash, $cmdHex2);
  1557. #select(undef, undef, undef, (0.05*$i));
  1558. ($err, $msg) = THZ_ReadAnswer($hash);
  1559. #expected 1002; if not following if takes care
  1560. if ($msg eq "10") {
  1561. select(undef, undef, undef, 0.01);
  1562. ($err, $msg) = THZ_ReadAnswer($hash);
  1563. }
  1564. # ack datatranfer and read from the heatpump
  1565. select(undef, undef, undef, 0.015);
  1566. THZ_Write($hash, "10");
  1567. select(undef, undef, undef, 0.001);
  1568. ($err, $msg) = THZ_ReadAnswer($hash);
  1569. THZ_Write($hash, "10");
  1570. if (defined($err)) {return ($msg ."\n" . $err);}
  1571. else { #clean up and remove footer and header
  1572. ($err, $msg) = THZ_decode($msg);
  1573. if (defined($err)) {
  1574. $msg = THZ_Parse1($hash,$msg);
  1575. $msg=$cmdHex2 ."-". $msg ."-". $err;}
  1576. my $activatetrigger =1;
  1577. # readingsSingleUpdate($hash, $cmd, $msg, $activatetrigger);
  1578. open (MYFILE, '>>data.txt');
  1579. print MYFILE ($cmdHex2 ."-". $cmd . "-" . $msg . "\n");
  1580. close (MYFILE);
  1581. #Log3 $hash->{NAME}, 3, "$cmd - $msg";
  1582. }
  1583. select(undef, undef, undef, 0.2);
  1584. }
  1585. }
  1586. #######################################
  1587. #THZ_Attr($)
  1588. #in case of change of attribute starting with interval_ refresh all
  1589. ########################################################################################
  1590. sub THZ_Attr(@) {
  1591. my ($cmd, $name, $attrName, $attrVal) = @_;
  1592. my $hash = $defs{$name};
  1593. $attrVal = "4.39" if ($cmd eq "del");
  1594. if ( $attrName eq "firmware" ) {
  1595. if ($attrVal eq "2.06") {
  1596. THZ_RemoveInternalTimer("THZ_GetRefresh");
  1597. %sets = %sets206;
  1598. %gets = (%getsonly2xx, %getsonly206, %sets);
  1599. THZ_Refresh_all_gets($hash);
  1600. }
  1601. elsif ($attrVal eq "2.14") {
  1602. THZ_RemoveInternalTimer("THZ_GetRefresh");
  1603. %sets = (%sets206, %setsonly214);
  1604. %gets = (%getsonly2xx, %getsonly214, %sets206);
  1605. THZ_Refresh_all_gets($hash);
  1606. }
  1607. elsif ($attrVal eq "5.39") {
  1608. THZ_RemoveInternalTimer("THZ_GetRefresh");
  1609. %sets=(%sets439539common, %sets539only);
  1610. %gets=(%getsonly539, %sets);
  1611. THZ_Refresh_all_gets($hash);
  1612. }
  1613. elsif ($attrVal eq "4.39technician") {
  1614. THZ_RemoveInternalTimer("THZ_GetRefresh");
  1615. %sets=(%sets439539common, %sets439only, %sets439technician);
  1616. %gets=(%getsonly439, %sets);
  1617. THZ_Refresh_all_gets($hash);
  1618. }
  1619. else { #in all other cases I assume $attrVal eq "4.39" cambiato nella v0140
  1620. THZ_RemoveInternalTimer("THZ_GetRefresh");
  1621. %sets=(%sets439539common, %sets439only);
  1622. %gets=(%getsonly439, %sets);
  1623. THZ_Refresh_all_gets($hash);
  1624. }
  1625. }
  1626. if( $attrName =~ /^interval_/ ) {
  1627. #DevIo_CloseDev($hash);
  1628. THZ_RemoveInternalTimer("THZ_GetRefresh");
  1629. #sleep 1;
  1630. #DevIo_OpenDev($hash, 1, "THZ_Refresh_all_gets");
  1631. THZ_Refresh_all_gets($hash);
  1632. }
  1633. return undef;
  1634. }
  1635. #####################################
  1636. sub THZ_Undef($$) {
  1637. my ($hash, $arg) = @_;
  1638. my $name = $hash->{NAME};
  1639. THZ_RemoveInternalTimer("THZ_GetRefresh");
  1640. foreach my $d (sort keys %defs) {
  1641. if(defined($defs{$d}) &&
  1642. defined($defs{$d}{IODev}) &&
  1643. $defs{$d}{IODev} == $hash)
  1644. {
  1645. my $lev = ($reread_active ? 4 : 2);
  1646. Log3 $hash->{NAME}, $lev, "deleting port for $d";
  1647. delete $defs{$d}{IODev};
  1648. }
  1649. }
  1650. BlockingKill($hash->{helper}{RUNNING_PID}) if(defined($hash->{helper}{RUNNING_PID}));
  1651. DevIo_CloseDev($hash);
  1652. return undef;
  1653. }
  1654. ##########################################
  1655. # nearest rounds to the nearrest value multiple of the first argumen
  1656. # nearest_ceil(10, 45); --> 50
  1657. # nearest_floor(10, 45); --> 40
  1658. # for all other values outside the middlevalues they take he nearest
  1659. # modified takes as an argument the function to be called, not the argument
  1660. ########################################################################################
  1661. sub nearest_ceil($$) {
  1662. my $targ = abs(shift);
  1663. my $Math1 = 0.5000000000003;
  1664. my @res = map { $targ * POSIX::floor(($_ + $Math1 * $targ) / $targ) } @_;
  1665. return wantarray ? @res : $res[0];
  1666. }
  1667. sub nearest_floor($$) {
  1668. my $targ = abs(shift);
  1669. my $Math1 = 0.5000000000003;
  1670. my @res = map { $targ * POSIX::ceil(($_ - $Math1 * $targ) / $targ) } @_;
  1671. return wantarray ? @res : $res[0];
  1672. }
  1673. ##########################################
  1674. # THZ_RemoveInternalTimer($)
  1675. # modified takes as an argument the function to be called, not the argument
  1676. ########################################################################################
  1677. sub THZ_RemoveInternalTimer($){
  1678. my ($callingfun) = @_;
  1679. foreach my $a (keys %intAt) {
  1680. delete($intAt{$a}) if($intAt{$a}{FN} eq $callingfun);
  1681. }
  1682. }
  1683. ################################
  1684. #
  1685. sub function_heatSetTemp($$) {
  1686. my ($start, $stop) = @_;
  1687. my ($p13GradientHC1, $p14LowEndHC1, $p15RoomInfluenceHC1);
  1688. my $pOpMode = " ";
  1689. my $devname; #normally Mythz but could be defined differently
  1690. foreach (keys %defs) {
  1691. $devname=$_;
  1692. last if(($defs{$_}{TYPE}) =~ "THZ");
  1693. }
  1694. if (AttrVal($devname, "firmware" , "4.39") =~ /^2/ ) {
  1695. ($p13GradientHC1, $p14LowEndHC1, $p15RoomInfluenceHC1) = (split ' ',ReadingsVal($devname,"pHeat1",0))[1,3,5];
  1696. }
  1697. else {
  1698. $pOpMode = ReadingsVal($devname,"pOpMode"," ");
  1699. $p13GradientHC1 = ReadingsVal($devname,"p13GradientHC1",0.4);
  1700. $p15RoomInfluenceHC1 = (split ' ',ReadingsVal($devname,"p15RoomInfluenceHC1",0))[0];
  1701. $p14LowEndHC1 = (split ' ',ReadingsVal($devname,"p14LowEndHC1",0))[0];
  1702. }
  1703. my ($heatSetTemp, $roomSetTemp, $insideTemp) = (split ' ',ReadingsVal($devname,"sHC1",0))[11,21,27];
  1704. my $outside_tempFiltered =(split ' ',ReadingsVal($devname,"sGlobal",0))[65];
  1705. if (!defined($roomSetTemp)) {
  1706. $insideTemp=23.8 ; $roomSetTemp = 19.5; $p13GradientHC1 = 0.31; $heatSetTemp = 15; $p15RoomInfluenceHC1 = 80;
  1707. $pOpMode ="DEMO: no data";
  1708. $outside_tempFiltered = 0; $p14LowEndHC1 =0.5;
  1709. }
  1710. my $a= 0.7 + ($roomSetTemp * (1 + $p13GradientHC1 * 0.87)) + $p14LowEndHC1 + ($p15RoomInfluenceHC1 * $p13GradientHC1 * ($roomSetTemp - $insideTemp) /10);
  1711. my $a1= 0.7 + ($roomSetTemp * (1 + $p13GradientHC1 * 0.87)) + $p14LowEndHC1;
  1712. my $b= -14 * $p13GradientHC1 / $roomSetTemp;
  1713. my $c= -1 * $p13GradientHC1 /75;
  1714. my $Simul_heatSetTemp; my $Simul_heatSetTemp_simplified; my @ret;
  1715. foreach ($start..$stop) {
  1716. my $tmp =$_ * $_ * $c + $_ * $b;
  1717. $Simul_heatSetTemp = sprintf("%.1f", maxNum(5,( $tmp + $a)));
  1718. #$Simul_heatSetTemp = 8 if ($pOpMode eq "DHWmode"); # DHWmode is always at 8 grad C
  1719. $Simul_heatSetTemp_simplified = sprintf("%.1f", maxNum(5,($tmp + $a1)));
  1720. push(@ret, [$_, $Simul_heatSetTemp, $Simul_heatSetTemp_simplified]);
  1721. }
  1722. my $titlestring = 'roomSetTemp=' . $roomSetTemp . '°C p13GradientHC1=' . $p13GradientHC1 . ' p14LowEndHC1=' . $p14LowEndHC1 . 'K p15RoomInfluenceHC1=' . $p15RoomInfluenceHC1 . "% insideTemp=" . $insideTemp .'°C';
  1723. return (\@ret, $titlestring, $heatSetTemp, $outside_tempFiltered, $pOpMode);
  1724. }
  1725. #####################################
  1726. # sub THZ_PrintcurveSVG
  1727. # plots heat curve
  1728. #define wl_hr weblink htmlCode {THZ_PrintcurveSVG}
  1729. # da mettere dentro lo style per funzionare sopra svg { height:200px; width:800px;}
  1730. #define wl_hr2 weblink htmlCode <div class="SVGplot"><embed src="/fhem/THZ_PrintcurveSVG/" type="image/svg+xml" width="800" height="160" name="wl_7"/></div> <a href="/fhem?detail=wl_hr2">wl_hr2</a><br>
  1731. #####################################
  1732. sub THZ_PrintcurveSVG {
  1733. my ($ycurvevalues, $titlestring, $heatSetTemp, $outside_tempFiltered, $pOpMode) = function_heatSetTemp(-15,20);
  1734. my $v0min = minNum(15, ($ycurvevalues->[33][1]), ($ycurvevalues->[33][2]), $heatSetTemp); #lower offset than 15, if out of scale
  1735. $v0min = maxNum(5, nearest_ceil(5, $v0min)); #start only from a multiple of 5, but do not go below 5
  1736. my $vstep= 5;
  1737. $vstep= 10 if ((($ycurvevalues->[0][1])>($v0min+4*$vstep)) or (($ycurvevalues->[0][2])>($v0min+4*$vstep))); #increase step, if out of scale
  1738. my $v1=$v0min+$vstep; my $v2=$v1+$vstep; my $v3=$v2+$vstep; my $v4=$v3+$vstep;
  1739. my $ret = <<'END';
  1740. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE svg> <svg width="800" height="164" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
  1741. <style type="text/css"><![CDATA[
  1742. text { font-family:Times; font-size:12px; }
  1743. text.title { font-size:14px; }
  1744. text.copy { text-decoration:underline; stroke:none; fill:blue; }
  1745. text.paste { text-decoration:underline; stroke:none; fill:blue; }
  1746. polyline { stroke:black; fill:none; }
  1747. .border { stroke:black; fill:url(#gr_bg); }
  1748. .vgrid { stroke:gray; stroke-dasharray:2,6; }
  1749. .hgrid { stroke:gray; stroke-dasharray:2,6; }
  1750. .pasted { stroke:black; stroke-dasharray:1,1; }
  1751. .l0 { stroke:red; } text.l0 { stroke:none; fill:red; }
  1752. .l1 { stroke:green; } text.l1 { stroke:none; fill:green; }
  1753. .l3 { stroke:blue; } text.l3 { stroke:none; fill:blue; }
  1754. .l0dot { stroke:red; stroke-dasharray:2,4; } text.ldot { stroke:none; fill:red; }
  1755. ]]></style>
  1756. <defs>
  1757. <linearGradient id="gr_bg" x1="0%" y1="0%" x2="0%" y2="100%">
  1758. <stop offset="0%" style="stop-color:#FFFFF7; stop-opacity:1"/>
  1759. <stop offset="100%" style="stop-color:#FFFFC7; stop-opacity:1"/>
  1760. </linearGradient>
  1761. <linearGradient id="gr_0" x1="0%" y1="0%" x2="0%" y2="100%">
  1762. <stop offset="0%" style="stop-color:#f00; stop-opacity:.6"/>
  1763. <stop offset="100%" style="stop-color:#f88; stop-opacity:.4"/>
  1764. </linearGradient>
  1765. <linearGradient id="gr_1" x1="0%" y1="0%" x2="0%" y2="100%">
  1766. <stop offset="0%" style="stop-color:#291; stop-opacity:.6"/>
  1767. <stop offset="100%" style="stop-color:#8f7; stop-opacity:.4"/>
  1768. </linearGradient>
  1769. <pattern id="gr0_stripe" width="4" height="4" patternUnits="userSpaceOnUse" patternTransform="rotate(-45 2 2)">
  1770. <path d="M -1,2 l 6,0" stroke="#f00" stroke-width="0.5"/>
  1771. </pattern>
  1772. <pattern id="gr1_stripe" width="4" height="4" patternUnits="userSpaceOnUse" patternTransform="rotate(45 2 2)">
  1773. <path d="M -1,2 l 6,0" stroke="green" stroke-width="0.5"/>
  1774. </pattern>
  1775. <linearGradient id="gr0_gyr" x1="0%" y1="0%" x2="0%" y2="100%">
  1776. <stop offset="0%" style="stop-color:#f00; stop-opacity:.6"/>
  1777. <stop offset="50%" style="stop-color:#ff0; stop-opacity:.6"/>
  1778. <stop offset="100%" style="stop-color:#0f0; stop-opacity:.6"/>
  1779. </linearGradient>
  1780. </defs>
  1781. <rect x="48" y="19.2" width="704" height="121.6" rx="8" ry="8" fill="none" class="border"/>
  1782. <text x="12" y="80" text-anchor="middle" class="ylabel" transform="rotate(270,12,80)">HC1 heat SetTemp °C</text>
  1783. <text x="399" y="163.5" class="xlabel" text-anchor="middle">outside temperature filtered °C</text>
  1784. <text x="44" y="155" class="ylabel" text-anchor="middle">-15</text>
  1785. <text x="145" y="155" class="ylabel" text-anchor="middle">-10</text> <polyline points="145,19 145,140" class="hgrid"/>
  1786. <text x="246" y="155" class="ylabel" text-anchor="middle">-5</text> <polyline points="246,19 246,140" class="hgrid"/>
  1787. <text x="347" y="155" class="ylabel" text-anchor="middle">0</text> <polyline points="347,19 347,140" class="hgrid"/>
  1788. <text x="448" y="155" class="ylabel" text-anchor="middle">5</text> <polyline points="448,19 448,140" class="hgrid"/>
  1789. <text x="549" y="155" class="ylabel" text-anchor="middle">10</text> <polyline points="549,19 549,140" class="hgrid"/>
  1790. <text x="650" y="155" class="ylabel" text-anchor="middle">15</text> <polyline points="650,19 650,140" class="hgrid"/>
  1791. <text x="751" y="155" class="ylabel" text-anchor="middle">20</text> <polyline points="751,19 751,140" class="hgrid"/>
  1792. <g>
  1793. END
  1794. $ret .= '<polyline points="44,140 49,140"/> <text x="39" y="144" class="ylabel" text-anchor="end">' . $v0min . '</text>';
  1795. $ret .= '<polyline points="44,110 49,110"/> <text x="39" y="114" class="ylabel" text-anchor="end">' . $v1 . '</text>';
  1796. $ret .= '<polyline points="44,80 49,80"/> <text x="39" y="84" class="ylabel" text-anchor="end">' . $v2 . '</text>';
  1797. $ret .= '<polyline points="44,49 49,49"/> <text x="39" y="53" class="ylabel" text-anchor="end">' . $v3 . '</text>';
  1798. $ret .= '<polyline points="44,19 49,19"/> <text x="39" y="23" class="ylabel" text-anchor="end">' . $v4 . '</text>';
  1799. $ret .= '</g> <g>';
  1800. $ret .= '<polyline points="751,140 756,140"/> <text x="760" y="144" class="ylabel">'. $v0min .'</text>';
  1801. $ret .= '<polyline points="751,110 756,110"/> <text x="760" y="114" class="ylabel">'. $v1 .'</text>';
  1802. $ret .= '<polyline points="751,80 756,80"/> <text x="760" y="84" class="ylabel">' . $v2 .'</text>';
  1803. $ret .= '<polyline points="751,49 756,49"/> <text x="760" y="53" class="ylabel">' . $v3 .'</text>';
  1804. $ret .= '<polyline points="751,19 756,19"/> <text x="760" y="23" class="ylabel">' . $v4 .'</text>';
  1805. $ret .= '</g>' ."\n";
  1806. #labels ######################
  1807. $ret .= '<text line_id="line_1" x="70" y="100" class="l1"> --- heat curve with insideTemp correction</text>' ;
  1808. $ret .= '<text line_id="line_3" x="70" y="115" class="l3"> --- heat curve simplified</text>' ;
  1809. $ret .= '<text line_id="line_0" x="70" y="130" class="l0"> --- working point: ';
  1810. $ret .= 'outside_tempFiltered=' . $outside_tempFiltered . '°C heatSetTemp=' . $heatSetTemp . '°C </text>';
  1811. $ret .= '<text line_id="line_3" x="650" y="50" class="title"> -'. $pOpMode . '- </text>' ." \n" ;
  1812. #title ######################
  1813. $ret .= '<text id="svg_title" x="400" y="14.4" class="title" text-anchor="middle">';
  1814. $ret .= $titlestring .' </text>' . "\n";
  1815. #point ######################
  1816. $ret .='<polyline id="line_0" style="stroke-width:2" class="l0" points="';
  1817. my ($px,$py) = (sprintf("%.1f", (($outside_tempFiltered+15)*(750-49)/(15+20)+49)),sprintf("%.1f", (($heatSetTemp-$v4)*(140-19)/($v0min-$v4)+19)));
  1818. $ret.= ($px-3) . "," . ($py) ." " . ($px) . "," . ($py-3) ." " . ($px+3) . "," . ($py) ." " . ($px) . "," . ($py+3) ." " . ($px-3) . "," . ($py) ." " . '"/>' . "\n";
  1819. #curve with inside temperature correction ######################
  1820. $ret .='<polyline id="line_1" title="Heat Curve with insideTemp correction" style="stroke-width:1" class="l1" points="';
  1821. foreach (@{$ycurvevalues}) {
  1822. $ret.= (sprintf("%.1f", ($_->[0]+15)*(750-49)/(15+20)+49) ). "," . sprintf("%.1f", (($_->[1]-$v4)*(140-19)/($v0min-$v4)+19)) ." ";
  1823. }
  1824. $ret .= '"/> ' . "\n";
  1825. #curve without inside temperature correction ######################
  1826. $ret .='<polyline id="line_3" title="Heat Curve simplified" style="stroke-width:1" class="l3" points="';
  1827. foreach (@{$ycurvevalues}) {
  1828. $ret.= (sprintf("%.1f", ($_->[0]+15)*(750-49)/(15+20)+49) ). "," . sprintf("%.1f", (($_->[2]-$v4)*(140-19)/($v0min-$v4)+19)) ." ";
  1829. }
  1830. $ret .= '"/> ' . "\n";
  1831. $ret .= '</svg>';
  1832. my $FW_RETTYPE = "image/svg+xml";
  1833. return ($FW_RETTYPE, $ret);
  1834. }
  1835. sub THZ_detailFn(@){
  1836. my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn.
  1837. my $hash = $defs{$d}; #$d is the name of the defined device
  1838. return '<div class="SVGplot"><embed src="/fhem/THZ_PrintcurveSVG/" type="image/svg+xml" name="wl_hr22"/></div> <br>';
  1839. }
  1840. #####################################
  1841. sub THZ_backup_readings($){
  1842. my ($hash) = @_;
  1843. return "No statefile specified" if(!$attr{global}{statefile});
  1844. my $backupfile=$attr{global}{statefile};
  1845. my $t = localtime;
  1846. my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = localtime;
  1847. $month++;
  1848. $year+=1900;
  1849. #$year+=1900 - 2000;
  1850. my $replacestr= "$hash->{NAME}-$year-$month-$mday.backup";
  1851. $backupfile=~ s/fhem.save/$replacestr/g; #saving to statefile path
  1852. if(!open(BAFH, ">$backupfile")) {
  1853. my $msg = "WriteStateFile: Cannot open $backupfile: $!";
  1854. Log3 $hash->{NAME},3, $msg;
  1855. return $msg;
  1856. }
  1857. print BAFH "#$t\n";
  1858. my $r = $hash->{READINGS};
  1859. foreach my $c (sort keys %{$r}) {
  1860. my $rd = $r->{$c};
  1861. if(($c =~ /^p[HOr0-9]/) and (defined($rd->{VAL}))) {
  1862. my $val = $rd->{VAL};
  1863. $val =~ s/;/;;/g;
  1864. $val =~ s/\n/\\\n/g;
  1865. print BAFH "set $hash->{NAME} $c $val\n";
  1866. }
  1867. }
  1868. return "$backupfile: $!" if(!close(BAFH));
  1869. return "saved Readings in $backupfile";
  1870. }
  1871. 1;
  1872. =pod
  1873. =item device
  1874. =item summary Monitors and controls Tecalor/StiebelEltron heatpumps via serial interface
  1875. =begin html
  1876. <a name="THZ"></a>
  1877. <h3>THZ</h3>
  1878. <ul>
  1879. THZ module: comunicate through serial interface RS232/USB (eg /dev/ttyxx) or through ser2net (e.g 10.0.x.x:5555) with a Tecalor/Stiebel Eltron heatpump. <br>
  1880. Tested on a THZ303/Sol (with serial speed 57600/115200@USB) and a THZ403 (with serial speed 115200) with the same Firmware 4.39. <br>
  1881. Tested on a LWZ404 (with serial speed 115200) with Firmware 5.39. <br>
  1882. Tested on fritzbox, nas-qnap, raspi and macos.<br>
  1883. Implemented: read of status parameters and read/write of configuration parameters.
  1884. A complete description can be found in the 00_THZ wiki http://www.fhemwiki.de/wiki/Tecalor_THZ_Heatpump
  1885. <br><br>
  1886. <a name="THZdefine"></a>
  1887. <b>Define</b>
  1888. <ul>
  1889. <code>define &lt;name&gt; THZ &lt;device&gt;</code> <br>
  1890. <br>
  1891. <code>device</code> can take the same parameters (@baudrate, @directio,
  1892. TCP/IP, none) like the <a href="#CULdefine">CUL</a>, e.g 57600 baud or 115200.<br>
  1893. Example:
  1894. direct connection
  1895. <ul><code>
  1896. define Mytecalor THZ /dev/ttyUSB0@115200<br>
  1897. </code></ul>
  1898. or network connection (like via ser2net)<br>
  1899. <ul><code>
  1900. define Myremotetecalor THZ 192.168.0.244:2323
  1901. </code></ul>
  1902. <br>
  1903. <ul><code>
  1904. define Mythz THZ /dev/ttyUSB0@115200 <br>
  1905. define FileLog_Mythz FileLog ./log/Mythz-%Y.log Mythz <br>
  1906. attr Mythz event-min-interval s.*:4800 <br>
  1907. attr Mythz event-on-change-reading .* <br>
  1908. attr Mythz interval_sDHW 400 <br>
  1909. attr Mythz interval_sElectrDHWDay 2400 <br>
  1910. attr Mythz interval_sElectrDHWTotal 43200 <br>
  1911. attr Mythz interval_sGlobal 400 <br>
  1912. attr Mythz interval_sHC1 400 <br>
  1913. attr Mythz interval_sHeatDHWDay 2400 <br>
  1914. attr Mythz interval_sHeatDHWTotal 43200 <br>
  1915. attr Mythz interval_sHeatRecoveredDay 2400 <br>
  1916. attr Mythz interval_sHeatRecoveredTotal 43200 <br>
  1917. attr Mythz interval_sHistory 86400 <br>
  1918. attr Mythz interval_sLast10errors 86400 <br>
  1919. attr Mythz room pompa <br>
  1920. attr FileLog_Mythz room pompa <br>
  1921. </code></ul>
  1922. <br>
  1923. If the attributes interval_XXXX are not defined (or 0 seconds), their internal polling is disabled.
  1924. <br>
  1925. This module is starting to support older firmware 2.06 or newer firmware 5.39; the following attribute adapts decoding <br>
  1926. <br>
  1927. <ul><code>
  1928. attr Mythz firmware 2.06 <br>
  1929. </code></ul>
  1930. <br>
  1931. <br>
  1932. <ul><code>
  1933. attr Mythz firmware 5.39 <br>
  1934. </code></ul>
  1935. <br>
  1936. If no attribute firmware is set, it is assumed your firmware is compatible with 4.39.
  1937. <br>
  1938. A backup function has been implemented
  1939. <ul><code>
  1940. get Mythz zBackupParameters implemented
  1941. </code></ul>
  1942. The command saves all pXXX in a backupfile with a special text format.
  1943. All (or some) parameters can be easily restored with one copy&paste from the backupfile in a telnet fhem session.
  1944. </ul>
  1945. <br>
  1946. </ul>
  1947. =end html
  1948. =begin html_DE
  1949. <a name="THZ"></a>
  1950. <h3>THZ</h3>
  1951. <ul>
  1952. THZ Modul: Kommuniziert mittels einem seriellen Interface RS232/USB (z.B. /dev/ttyxx), oder mittels ser2net (z.B. 10.0.x.x:5555) mit einer Tecalor / Stiebel
  1953. Eltron W&auml;rmepumpe. <br>
  1954. Getestet mit einer Tecalor THZ303/Sol (Serielle Geschwindigkeit 57600/115200@USB) und einer THZ403 (Serielle Geschwindigkeit 115200) mit identischer
  1955. Firmware 4.39. <br>
  1956. Getestet mit einer Stiebel LWZ404 (Serielle Geschwindigkeit 115200@USB) mit Firmware 5.39. <br>
  1957. Getestet auf FritzBox, nas-qnap, Raspberry Pi and MacOS.<br>
  1958. Dieses Modul funktioniert nicht mit &aumlterer Firmware; Gleichwohl, das "parsing" k&ouml;nnte leicht angepasst werden da die Register gut
  1959. beschrieben wurden.
  1960. https://answers.launchpad.net/heatpumpmonitor/+question/100347 <br>
  1961. Implementiert: Lesen der Statusinformation sowie Lesen und Schreiben einzelner Einstellungen.
  1962. Genauere Beschreinung des Modules --> 00_THZ wiki http://www.fhemwiki.de/wiki/Tecalor_THZ_W%C3%A4rmepumpe
  1963. <br><br>
  1964. <a name="THZdefine"></a>
  1965. <b>Define</b>
  1966. <ul>
  1967. <code>define &lt;name&gt; THZ &lt;device&gt;</code> <br>
  1968. <br>
  1969. <code>device</code> kann einige Parameter beinhalten (z.B. @baudrate, @direction,
  1970. TCP/IP, none) wie das <a href="#CULdefine">CUL</a>, z.B. 57600 baud oder 115200.<br>
  1971. Beispiel:<br>
  1972. Direkte Verbindung
  1973. <ul><code>
  1974. define Mytecalor THZ /dev/ttyUSB0@115200<br>
  1975. </code></ul>
  1976. oder vir Netzwerk (via ser2net)<br>
  1977. <ul><code>
  1978. define Myremotetecalor THZ 192.168.0.244:2323
  1979. </code></ul>
  1980. <br>
  1981. <ul><code>
  1982. define Mythz THZ /dev/ttyUSB0@115200 <br>
  1983. define FileLog_Mythz FileLog ./log/Mythz-%Y.log Mythz <br>
  1984. attr Mythz event-min-interval s.*:4800 <br>
  1985. attr Mythz event-on-change-reading .* <br>
  1986. attr Mythz interval_sDHW 400 <br>
  1987. attr Mythz interval_sElectrDHWDay 2400 <br>
  1988. attr Mythz interval_sElectrDHWTotal 43200 <br>
  1989. attr Mythz interval_sGlobal 400 <br>
  1990. attr Mythz interval_sHC1 400 <br>
  1991. attr Mythz interval_sHeatDHWDay 2400 <br>
  1992. attr Mythz interval_sHeatDHWTotal 43200 <br>
  1993. attr Mythz interval_sHeatRecoveredDay 2400 <br>
  1994. attr Mythz interval_sHeatRecoveredTotal 43200 <br>
  1995. attr Mythz interval_sHistory 86400 <br>
  1996. attr Mythz interval_sLast10errors 86400 <br>
  1997. attr Mythz room pompa <br>
  1998. attr FileLog_Mythz room pompa <br>
  1999. </code></ul>
  2000. <br>
  2001. Wenn die Attribute interval_XXXXXXX nicht definiert sind (oder 0), ist das interne Polling deaktiviert.
  2002. </ul>
  2003. <br>
  2004. </ul>
  2005. =end html_DE
  2006. =cut