73_km200.pm 116 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297
  1. # $Id: 73_km200.pm 14221 2017-05-08 10:55:47Z Sailor $
  2. ########################################################################################################################
  3. #
  4. # 73_km200.pm
  5. # Creates the possibility to access the Buderus central heating system via
  6. # Buderus KM200, KM100 or KM50 communication module. It uses HttpUtils_NonblockingGet
  7. # from Rudolf Koenig to avoid a full blockage of the fhem main system during the
  8. # polling procedure.
  9. #
  10. # Author : Matthias Deeke
  11. # Contributions : Olaf Droegehorn, Andreas Hahn, Rudolf Koenig, Markus Bloch,
  12. # Contributions (continued) : Stefan M., Furban, KaiKr, grossi33, Morkin, DLindner
  13. # e-mail : matthias.deeke(AT)deeke(PUNKT)eu
  14. # Fhem Forum : http://forum.fhem.de/index.php/topic,25540.0.html
  15. # Fhem Wiki : http://www.fhemwiki.de/wiki/Buderus_Web_Gateway
  16. #
  17. # This file is part of fhem.
  18. #
  19. # Fhem is free software: you can redistribute it and/or modify
  20. # it under the terms of the GNU General Public License as published by
  21. # the Free Software Foundation, either version 2 of the License, or
  22. # (at your option) any later version.
  23. #
  24. # Fhem is distributed in the hope that it will be useful,
  25. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. # GNU General Public License for more details.
  28. #
  29. # You should have received a copy of the GNU General Public License
  30. # along with fhem. If not, see <http://www.gnu.org/licenses/>.
  31. #
  32. # fhem.cfg: define <devicename> km200 <IPv4-address> <GatewayPassword> <PrivatePassword>
  33. #
  34. # Example 1 - Bare Passwords:
  35. # define myKm200 km200 192.168.178.200 GatewayGeheim PrivateGeheim
  36. #
  37. # Example 2 - base64 encoded passwords: Both passwords may be pre-encode with base64
  38. # define myKm200 km200 192.168.178.200 R2F0ZXdheUdlaGVpbQ== UHJpdmF0ZUdlaGVpbQ==
  39. #
  40. ########################################################################################################################
  41. ########################################################################################################################
  42. # List of open Problems:
  43. #
  44. #
  45. ########################################################################################################################
  46. package main;
  47. use strict;
  48. use warnings;
  49. use Blocking;
  50. use Time::HiRes qw(gettimeofday sleep usleep);
  51. use Digest::MD5 qw(md5 md5_hex md5_base64);
  52. use base qw( Exporter );
  53. use List::MoreUtils qw(first_index);
  54. use MIME::Base64;
  55. use LWP::UserAgent;
  56. use JSON;
  57. use Crypt::Rijndael;
  58. use HttpUtils;
  59. use Encode;
  60. use constant false => 0;
  61. use constant true => 1;
  62. sub km200_Define($$);
  63. sub km200_Undefine($$);
  64. ###START###### Initialize module ##############################################################################START####
  65. sub km200_Initialize($)
  66. {
  67. my ($hash) = @_;
  68. $hash->{STATE} = "Init";
  69. $hash->{DefFn} = "km200_Define";
  70. $hash->{UndefFn} = "km200_Undefine";
  71. $hash->{SetFn} = "km200_Set";
  72. $hash->{GetFn} = "km200_Get";
  73. $hash->{AttrFn} = "km200_Attr";
  74. $hash->{DbLog_splitFn} = "km200_DbLog_splitFn";
  75. $hash->{AttrList} = "do_not_notify:1,0 " .
  76. "header " .
  77. "disable:1,0 " .
  78. "loglevel:0,1,2,3,4,5,6 " .
  79. "IntervalDynVal " .
  80. "PollingTimeout " .
  81. "DoNotPoll " .
  82. "ReadBackDelay " .
  83. $readingFnAttributes;
  84. }
  85. ####END####### Initialize module ###############################################################################END#####
  86. ###START###### Activate module after module has been used via fhem command "define" ##########################START####
  87. sub km200_Define($$)
  88. {
  89. my ($hash, $def) = @_;
  90. my @a = split("[ \t][ \t]*", $def);
  91. my $name = $a[0];
  92. #$a[1] just contains the "km200" module name and we already know that! :-)
  93. my $url = $a[2];
  94. my $km200_gateway_password = $a[3];
  95. my $km200_private_password = $a[4];
  96. $hash->{NAME} = $name;
  97. $hash->{STATE} = "define";
  98. Log3 $name, 4, $name. " : km200 - Starting to define module";
  99. ### Stop the current timer if one exists errornous
  100. RemoveInternalTimer($hash);
  101. Log3 $name, 4, $name. " : km200 - InternalTimer has been removed.";
  102. ###START###### Define known services of gateway ###########################################################START####
  103. my @KM200_AllServices = (
  104. "/",
  105. "/dhwCircuits",
  106. "/gateway",
  107. "/heatingCircuits",
  108. "/heatSources",
  109. "/notifications",
  110. "/recordings",
  111. "/solarCircuits",
  112. "/system",
  113. "/dhwCircuits",
  114. );
  115. ####END####### Define known services of gateway ############################################################END#####
  116. ###START### Check whether all variables are available #####################################################START####
  117. if (int(@a) == 5)
  118. {
  119. ###START### Check whether IPv4 address is valid
  120. if ($url =~ m/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/)
  121. {
  122. Log3 $name, 4, $name. " : km200 - IPv4-address is valid : " . $url;
  123. }
  124. else
  125. {
  126. return $name .": Error - IPv4 address is not valid \n Please use \"define <devicename> km200 <IPv4-address> <interval/[s]> <GatewayPassword> <PrivatePassword>\" instead";
  127. }
  128. ####END#### Check whether IPv4 address is valid
  129. ###START### Check whether gateway password is base64 encoded or bare, has the right length and delete "-" if required
  130. my $PasswordEncrypted = false;
  131. my $EvalPassWord = $km200_gateway_password;
  132. $EvalPassWord =~ tr/-//d;
  133. if ( length($EvalPassWord) == 16)
  134. {
  135. $km200_gateway_password = $EvalPassWord;
  136. Log3 $name,4, $name. " : km200 - Provided GatewayPassword provided as bareword has the correct length at least.";
  137. }
  138. else # Check whether the password is eventually base64 encoded
  139. {
  140. # Remove additional encoding with base64
  141. my $decryptData = decode_base64($km200_gateway_password);
  142. $decryptData =~ tr/-//d;
  143. $decryptData =~ s/\r|\n//g;
  144. if ( length($decryptData) == 16)
  145. {
  146. $km200_gateway_password = $decryptData;
  147. $PasswordEncrypted = true;
  148. Log3 $name, 4, $name. " : km200 - Provided GatewayPassword encoded with base64 has the correct length at least.";
  149. }
  150. else
  151. {
  152. return $name .": Error - GatewayPassword does not have the correct length.\n".
  153. " Please enter gateway password in the format of \"aaaabbbbccccdddd\" or \"aaaa-bbbb-cccc-dddd\"\n".
  154. " You may encode your password with base64 first, in order to prevent bare passwords in fhem.cfg.\n".
  155. " If you choose to encrypt your gateway password with base64, you also must encrypt your private password the same way\n";
  156. Log3 $name, 3, $name. " : km200 - Provided Gateway Password does not follow the specifications";
  157. }
  158. }
  159. ####END#### Check whether gateway password has the right length and delete "-" if required
  160. ###START### Check whether private password is available and decode it with base64 if encoding is used
  161. if ($PasswordEncrypted == true)
  162. {
  163. my $decryptData = decode_base64($km200_private_password);
  164. $decryptData =~ s/\r|\n//g;
  165. if (length($decryptData) > 0)
  166. {
  167. $km200_private_password = $decryptData;
  168. Log3 $name, 4, $name. " : km200 - Provided PrivatePassword exists at least";
  169. }
  170. else
  171. {
  172. return $name .": Error - PrivatePassword does not have the minimum length.\n".
  173. " You may encode your password with base64 first, in order to prevent bare passwords in fhem.cfg.\n".
  174. " If you choose to encrypt your private password with base64, you also must encrypt your gateway password the same way\n";
  175. }
  176. }
  177. else # If private password is provided as bare word
  178. {
  179. if (length($km200_private_password) > 0)
  180. {
  181. Log3 $name, 4, $name. " : km200 - Provided PrivatePassword exists at least";
  182. }
  183. else
  184. {
  185. return $name .": Error - PrivatePassword has not been provided.\n".
  186. " You may encode your password with base64 first, in order to prevent bare passwords in fhem.cfg.\n".
  187. " If you choose to encrypt your private password with base64, you also must encrypt your gateway password the same way\n";
  188. Log3 $name, 3, $name. " : km200 - Provided Private Password does not follow the specifications";
  189. }
  190. }
  191. ####END#### Check whether private password is available and decode it with base64 if encoding is used
  192. }
  193. else
  194. {
  195. return $name .": km200 - Error - Not enough parameter provided." . "\n" . "Gateway IPv4 address, Gateway and Private Passwords must be provided" ."\n". "Please use \"define <devicename> km200 <IPv4-address> <GatewayPassword> <PrivatePassword>\" instead";
  196. }
  197. ####END#### Check whether all variables are available ######################################################END#####
  198. ###START###### Create the secret SALT of the MD5-Hash for AES-encoding ####################################START####
  199. my $Buderus_MD5Salt = pack(
  200. 'C*',
  201. 0x86, 0x78, 0x45, 0xe9, 0x7c, 0x4e, 0x29, 0xdc,
  202. 0xe5, 0x22, 0xb9, 0xa7, 0xd3, 0xa3, 0xe0, 0x7b,
  203. 0x15, 0x2b, 0xff, 0xad, 0xdd, 0xbe, 0xd7, 0xf5,
  204. 0xff, 0xd8, 0x42, 0xe9, 0x89, 0x5a, 0xd1, 0xe4
  205. );
  206. ####END####### Create the secret SALT of the MD5-Hash for AES-encoding #####################################END#####
  207. ###START###### Create keys with MD5 #######################################################################START####
  208. # Copy Salt
  209. my $km200_crypt_md5_salt = $Buderus_MD5Salt;
  210. # First half of the key: MD5 of (km200GatePassword . Salt)
  211. my $key_1 = md5($km200_gateway_password . $km200_crypt_md5_salt);
  212. # Second half of the key: - Initial: MD5 of ( Salt)
  213. my $key_2_initial = md5($km200_crypt_md5_salt);
  214. # Second half of the key: - private: MD5 of ( Salt . km200PrivatePassword)
  215. my $key_2_private = md5($km200_crypt_md5_salt . $km200_private_password);
  216. # Create keys
  217. my $km200_crypt_key_initial = ($key_1 . $key_2_initial);
  218. my $km200_crypt_key_private = ($key_1 . $key_2_private);
  219. ####END####### Create keys with MD5 #########################################################################END#####
  220. ###START###### Writing values to global hash ###############################################################START####
  221. $hash->{NAME} = $name;
  222. $hash->{URL} = $url;
  223. $hash->{INTERVALDYNVAL} = 300;
  224. $hash->{DELAYDYNVAL} = 60;
  225. $hash->{POLLINGTIMEOUT} = 5;
  226. $hash->{READBACKDELAY} = 100;
  227. $hash->{temp}{ServiceCounterInit} = 0;
  228. $hash->{temp}{ServiceCounterDyn} = 0;
  229. $hash->{temp}{ServiceDbLogSplitHash} = ();
  230. $hash->{status}{FlagInitRequest} = false;
  231. $hash->{status}{FlagGetRequest} = false;
  232. $hash->{status}{FlagSetRequest} = false;
  233. $hash->{status}{FlagDynRequest} = false;
  234. $hash->{status}{FlagStatRequest} = false;
  235. $hash->{Secret}{CRYPTKEYPRIVATE} = $km200_crypt_key_private;
  236. $hash->{Secret}{CRYPTKEYINITIAL} = $km200_crypt_key_initial;
  237. @{$hash->{Secret}{KM200ALLSERVICES}} = sort @KM200_AllServices;
  238. @{$hash->{Secret}{KM200ALLSERVICESBACKUP}} = sort @KM200_AllServices;
  239. @{$hash->{Secret}{KM200RESPONDINGSERVICES}} = ();
  240. @{$hash->{Secret}{KM200WRITEABLESERVICES}} = ();
  241. @{$hash->{Secret}{KM200DONOTPOLL}} = ();
  242. ####END####### Writing values to global hash ################################################################END#####
  243. ###START###### Reset fullResponse error message ############################################################START####
  244. readingsSingleUpdate( $hash, "fullResponse", "OK", 1);
  245. ####END####### Reset fullResponse error message #############################################################END#####
  246. ###START###### For Debugging purpose only ##################################################################START####
  247. Log3 $name, 4, $name. " : km200 - Define H : " .$hash;
  248. Log3 $name, 4, $name. " : km200 - Define D : " .$def;
  249. Log3 $name, 4, $name. " : km200 - Define A : " .@a;
  250. Log3 $name, 4, $name. " : km200 - Define Name : " .$name;
  251. Log3 $name, 4, $name. " : km200 - Define Adr : " .$url;
  252. ####END####### For Debugging purpose only ###################################################################END#####
  253. ###START###### Check whether communication to the physical unit is possible ################################START####
  254. my $Km200Info ="";
  255. $hash->{temp}{service} = "/gateway/DateTime";
  256. $Km200Info = km200_GetSingleService($hash);
  257. if ($Km200Info eq "ERROR")
  258. {
  259. $Km200Info = $hash->{temp}{TransferValue};
  260. $hash->{temp}{TransferValue} = "";
  261. ## Communication with Gateway WRONG !! ##
  262. $hash->{STATE}="Error - No Communication";
  263. return ($name .": km200 - ERROR - The communication between fhem and the Buderus KM200 failed! \n".
  264. " Please check physical connection, IP-address and passwords! \n");
  265. }
  266. elsif ($Km200Info eq "SERVICE NOT AVAILABLE") ## Communication OK but service not available ##
  267. {
  268. Log3 $name, 4, $name. " : km200 - /gateway/DateTime : NOT AVAILABLE";
  269. }
  270. else ## Communication OK and service is available ##
  271. {
  272. Log3 $name, 4, $name. " : km200 - /gateway/DateTime : AVAILABLE";
  273. }
  274. ####END####### Check whether communication to the physical unit is possible ################################END#####
  275. ###START###### Initiate the timer for first time polling of values from KM200 but wait 10s ###############START####
  276. InternalTimer(gettimeofday()+10, "km200_GetInitService", $hash, 1);
  277. Log3 $name, 4, $name. " : km200 - Internal timer for Initialisation of services started for the first time.";
  278. ####END####### Initiate the timer for first time polling of values from KM200 but wait 60s ################END#####
  279. return undef;
  280. }
  281. ####END####### Activate module after module has been used via fhem command "define" ############################END#####
  282. ###START###### To bind unit of value to DbLog entries #########################################################START####
  283. sub km200_DbLog_splitFn($$)
  284. {
  285. my ($event, $name) = @_;
  286. my ($reading, $value, $unit);
  287. my $hash = $defs{$name};
  288. my @argument = split("[ \t][ \t]*", $event);
  289. ### Delete ":" and everything behind in readings name
  290. $argument[0] =~ s/:.*//;
  291. ### Log entries for debugging
  292. Log3 $name, 5, $name. " : km200_DbLog_splitFn - Content of event : " . $event;
  293. Log3 $name, 5, $name. " : km200_DbLog_splitFn - Content of argument[0] : " . $argument[0];
  294. Log3 $name, 5, $name. " : km200_DbLog_splitFn - Content of argument[1] : " . $argument[1];
  295. ### If the service to be changed is identical to the one where the unit received from
  296. if ($argument[0] = $hash->{temp}{ServiceDbLogSplitHash}{id})
  297. {
  298. ### Get values being changed from hash
  299. $reading = $argument[0];
  300. $value = $argument[1];
  301. $unit = $hash->{temp}{ServiceDbLogSplitHash}{unitOfMeasure};
  302. }
  303. ### Delete temporary json-hash for DbLog-Split
  304. $hash->{temp}{ServiceDbLogSplitHash} = ();
  305. ### Delete temporary json-hash for DbLog-Split
  306. return ($reading, $value, $unit);
  307. }
  308. ####END####### To bind unit of value to DbLog entries ##########################################################END#####
  309. ###START###### Deactivate module module after "undefine" command by fhem ######################################START####
  310. sub km200_Undefine($$)
  311. {
  312. my ($hash, $def) = @_;
  313. my $name = $hash->{NAME};
  314. my $url = $hash->{URL};
  315. ### Stop the internal timer for this module
  316. RemoveInternalTimer($hash);
  317. Log3 $name, 3, $name. " - km200 has been undefined. The KM unit at $url will no longer polled.";
  318. return undef;
  319. }
  320. ####END####### Deactivate module module after "undefine" command by fhem #######################################END#####
  321. ###START###### Handle attributes after changes via fhem GUI ###################################################START####
  322. sub km200_Attr(@)
  323. {
  324. my @a = @_;
  325. my $name = $a[1];
  326. my $hash = $defs{$name};
  327. my $IntervalDynVal = $hash->{INTERVALDYNVAL};
  328. my $DelayDynVal = $hash->{DELAYDYNVAL};
  329. my $ReadBackDelay = $hash->{READBACKDELAY};
  330. ### Check whether disable attribute has been provided
  331. if ($a[2] eq "disable")
  332. {
  333. ###START### Check whether device shall be disabled
  334. if ($a[3] == 1)
  335. {
  336. ### Set new status
  337. $hash->{STATE} = "Disabled";
  338. ### Stop the current timer
  339. RemoveInternalTimer($hash);
  340. Log3 $name, 4, $name. " : km200 - InternalTimer has been removed.";
  341. ### Delete all Readings
  342. fhem( "deletereading $name .*" );
  343. ### Recover list of root services
  344. @{$hash->{Secret}{KM200ALLSERVICES}}= @{$hash->{Secret}{KM200ALLSERVICESBACKUP}};
  345. Log3 $name, 3, $name. " : km200 - Device disabled as per attribute.";
  346. }
  347. else
  348. {
  349. ### Initiate the timer for first time polling of values from KM200 but wait 10s
  350. InternalTimer(gettimeofday()+10, "km200_GetInitService", $hash, 1);
  351. Log3 $name, 4, $name. " : km200 - Internal timer for Initialisation of services re-started.";
  352. ### Set new status
  353. $hash->{STATE} = "Initiating Sounding...";
  354. Log3 $name, 4, $name. " : km200 - Device enabled as per attribute.";
  355. }
  356. ####END#### Check whether device shall be disabled
  357. }
  358. ### Check whether dynamic interval attribute has been provided
  359. elsif ($a[2] eq "IntervalDynVal")
  360. {
  361. $IntervalDynVal = $a[3];
  362. ###START### Check whether polling interval is not too short
  363. if ($IntervalDynVal > 19)
  364. {
  365. $hash->{INTERVALDYNVAL} = $IntervalDynVal;
  366. Log3 $name, 4, $name. " : km200 - IntervalDynVal set to attribute value:" . $IntervalDynVal ." s";
  367. }
  368. else
  369. {
  370. return $name .": Error - Gateway interval for IntervalDynVal too small - server response time longer than defined interval, please use something >=20, default is 90";
  371. }
  372. ####END#### Check whether polling interval is not too short
  373. }
  374. ### Check whether polling timeout attribute has been provided
  375. elsif($a[2] eq "PollingTimeout")
  376. {
  377. ###START### Check whether timeout is not too short
  378. if ($a[3] >= 5)
  379. {
  380. $hash->{POLLINGTIMEOUT} = $a[3];
  381. Log3 $name, 4, $name. " : km200 - Polling timeout set to attribute value:" . $a[3] ." s";
  382. }
  383. else
  384. {
  385. Log3 $name, 4, $name. " : km200 - Error - Gateway polling timeout attribute too small: " . $a[3] ." s";
  386. return $name .": Error - Gateway polling timeout attribute is too small - server response time is 5s minimum, default is 5";
  387. }
  388. ####END#### Check whether timeout is not too short
  389. }
  390. ### Check whether DoNotPoll attribute have been provided
  391. elsif($a[2] eq "DoNotPoll")
  392. {
  393. my @KM200_DONOTPOLL = ();
  394. my @temp = @a;
  395. ### Stop the current timer
  396. RemoveInternalTimer($hash);
  397. Log3 $name, 4, $name. " : km200 - InternalTimer has been removed.";
  398. ### Delete the first 3 items of the array
  399. splice @temp, 0, 3;
  400. ### Insert empty field as minimum entry
  401. push @temp, "";
  402. ### Transform string entries seperated by blank into array
  403. @KM200_DONOTPOLL = split(/\s+/, $temp[0]);
  404. ### Remove trailing slash of each item if available
  405. ### For each item found in this empty parent directory
  406. foreach my $item (@KM200_DONOTPOLL)
  407. {
  408. ### Delete trailing slash
  409. $item =~ s/\/$//;
  410. }
  411. ### Save list of services not to be polled into hash
  412. @{$hash->{Secret}{KM200DONOTPOLL}} = @KM200_DONOTPOLL;
  413. ### Get original list of root services back
  414. @{$hash->{Secret}{KM200ALLSERVICES}} = @{$hash->{Secret}{KM200ALLSERVICESBACKUP}};
  415. ### For every blacklisted service
  416. foreach my $SearchWord(@KM200_DONOTPOLL)
  417. {
  418. ### Filter all blocked root services out of services to be polled
  419. my $FoundPosition = first_index{ $_ eq $SearchWord }@{$hash->{Secret}{KM200ALLSERVICES}};
  420. if ($FoundPosition >= 0)
  421. {
  422. splice(@{$hash->{Secret}{KM200ALLSERVICES}}, $FoundPosition, 1);
  423. }
  424. }
  425. ### Message for debugging purposes
  426. Log3 $name, 5, $name. "km200 module is only polling the following services! \n @{$hash->{Secret}{KM200ALLSERVICES}}";
  427. Log3 $name, 5, $name. "km200 module is NOT polling the following services! \n @{$hash->{Secret}{KM200DONOTPOLL}}";
  428. Log3 $name, 4, $name. " : km200 - The following services will not be polled: ". $a[3];
  429. ### Interrupting all currently running Polling
  430. @{$hash->{Secret}{KM200DYNSERVICES}} = "";
  431. $hash->{temp}{ServiceCounterDyn} = 0;
  432. ### Delete all Readings
  433. fhem( "deletereading $name .*" );
  434. ### Re-start the sounding of values from KM200 but wait the period of $hash->{POLLINGTIMEOUT} + 10s
  435. InternalTimer(gettimeofday()+$hash->{POLLINGTIMEOUT}+10, "km200_GetInitService", $hash, 1);
  436. Log3 $name, 4, $name. " : km200 - Sounding of services re-started after change of DoNotPoll attribute";
  437. }
  438. ### Check whether time-out for Read-Back has been provided
  439. if($a[2] eq "ReadBackDelay")
  440. {
  441. $ReadBackDelay = $a[3];
  442. ###START### Check whether ReadBackDelay is valid
  443. if ($ReadBackDelay >= 0)
  444. {
  445. $hash->{READBACKDELAY} = $ReadBackDelay;
  446. Log3 $name, 4, $name. " : km200 - ReadBackDelay set to attribute value:" . $ReadBackDelay ." s";
  447. }
  448. else
  449. {
  450. return $name .": Error - Read-Back delay time must be positive. Default is 0us";
  451. }
  452. ####END#### Check whether ReadBackDelay is valid
  453. }
  454. ### If no attributes of the above known ones have been selected
  455. else
  456. {
  457. # Do nothing
  458. }
  459. return undef;
  460. }
  461. ####END####### Handle attributes after changes via fhem GUI ####################################################END#####
  462. ###START###### Obtain value after "get" command by fhem #######################################################START####
  463. sub km200_Get($@)
  464. {
  465. my ( $hash, @a ) = @_;
  466. ### If not enough arguments have been provided
  467. if ( @a < 2 )
  468. {
  469. return "\"get km200\" needs at least one argument";
  470. }
  471. my $name = shift @a;
  472. my $service = shift @a;
  473. my $option = shift @a;
  474. my %km200_gets;
  475. my $ReturnValue;
  476. my $ReturnMessage;
  477. ### Get the list of possible services and create a hash out of it
  478. my @GetServices = @{$hash->{Secret}{KM200ALLSERVICES}};
  479. foreach my $item(@GetServices)
  480. {
  481. $km200_gets{$item} = ("1");
  482. }
  483. ### Remove trailing slash if available
  484. $service = $1 if($service=~/(.*)\/$/);
  485. ### If service chosen in GUI does not exist
  486. if(!$km200_gets{$service})
  487. {
  488. my @cList = keys %km200_gets;
  489. return "Unknown argument $service, choose one of " . join(" ", @cList);
  490. }
  491. ### Check whether the initialisation process has been finished
  492. if ($hash->{temp}{ServiceCounterInit} == false)
  493. {
  494. ### Save chosen service into hash
  495. $hash->{temp}{service} = $service;
  496. ### Read service-hash
  497. $ReturnValue = km200_GetSingleService($hash);
  498. ### If the "get" - option has been set to "Json" for the return of the raw Json-string
  499. if ($option =~ m/json/i)
  500. {
  501. $ReturnMessage = $hash->{temp}{JsonRaw};
  502. }
  503. ### If no option has been chosen, just return the result of the value.
  504. else
  505. {
  506. ### If type is a floatvalue then format decimals
  507. if ($ReturnValue->{type} eq "floatValue")
  508. {
  509. $ReturnMessage = sprintf("%.1f", $ReturnValue->{value});
  510. }
  511. ### If type is something else just pass throught
  512. else
  513. {
  514. $ReturnMessage = $ReturnValue->{value};
  515. }
  516. }
  517. }
  518. ### If the initialisation process has NOT been finished
  519. else
  520. {
  521. $ReturnMessage = "The initialisation process is still ongoing. Please wait for the STATE changing to \"Standby\"";
  522. }
  523. ### Delete temporary values
  524. $hash->{temp}{service} = "";
  525. $hash->{temp}{JsonRaw} = "";
  526. ### Return value
  527. return($ReturnMessage);
  528. }
  529. ####END####### Obtain value after "get" command by fhem ########################################################END#####
  530. ###START###### Manipulate service after "set" command by fhem #################################################START####
  531. sub km200_Set($@)
  532. {
  533. my ( $hash, @a ) = @_;
  534. ### If not enough arguments have been provided
  535. if ( @a < 2 )
  536. {
  537. return "\"set km200\" needs at least one argument";
  538. }
  539. my $name = shift @a;
  540. my $service = shift @a;
  541. my $value = join(" ", @a);
  542. my %km200_sets;
  543. my $ReturnMessage;
  544. ### Get the list of possible services and create a hash out of it
  545. my @WriteableServices = @{$hash->{Secret}{KM200WRITEABLESERVICES}};
  546. foreach my $item(@WriteableServices)
  547. {
  548. $km200_sets{$item} = ("1");
  549. }
  550. ### If service chosen in GUI does not exist
  551. if(!$km200_sets{$service})
  552. {
  553. my @cList = keys %km200_sets;
  554. return "Unknown argument $service, choose one of " . join(" ", @cList);
  555. }
  556. ### Check whether the initialisation process has been finished
  557. if ($hash->{temp}{ServiceCounterInit} == false)
  558. {
  559. ### Save chosen service into hash
  560. $hash->{temp}{service} = $service;
  561. $hash->{temp}{postdata} = $value;
  562. ### Call set sub
  563. $ReturnMessage = km200_PostSingleService($hash);
  564. }
  565. ### If the initialisation process has NOT been finished
  566. else
  567. {
  568. $ReturnMessage = "The initialisation process is still ongoing. Please wait for the STATE changing to \"Standby\"";
  569. }
  570. ### Delete temporary hash values
  571. $hash->{temp}{postdata} = "";
  572. $hash->{temp}{service} = "";
  573. return($ReturnMessage);
  574. }
  575. ####END####### Manipulate service after "Set" command by fhem ##################################################END#####
  576. ###START####### Repeats "string" for "count" times ############################################################START####
  577. sub str_repeat($$)
  578. {
  579. my $string = $_[0];
  580. my $count = $_[1];
  581. return(${string}x${count});
  582. }
  583. ####END######## Repeats "string" for "count" times #############################################################END#####
  584. ###START###### Subroutine Encrypt Data ########################################################################START####
  585. sub km200_Encrypt($)
  586. {
  587. my ($hash, $def) = @_;
  588. my $km200_crypt_key_private = $hash->{Secret}{CRYPTKEYPRIVATE};
  589. my $name = $hash->{NAME};
  590. my $encryptData = $hash->{temp}{jsoncontent};
  591. # Create Rijndael encryption object
  592. my $cipher = Crypt::Rijndael->new($km200_crypt_key_private, Crypt::Rijndael::MODE_ECB() );
  593. # Get blocksize and add PKCS #7 padding
  594. my $blocksize = $cipher->blocksize();
  595. my $encrypt_padchar = $blocksize - ( length( $encryptData ) % $blocksize );
  596. $encryptData .= str_repeat( chr( $encrypt_padchar ), $encrypt_padchar );
  597. # Do the encryption
  598. my $ciphertext = $cipher->encrypt( $encryptData );
  599. # Do additional encoding with base64
  600. $ciphertext = encode_base64($ciphertext);
  601. # Return the encoded text
  602. return($ciphertext);
  603. }
  604. ####END####### Subroutine Encrypt Data #########################################################################END#####
  605. ###START###### Subroutine Decrypt Data ########################################################################START####
  606. sub km200_Decrypt($)
  607. {
  608. my ($hash, $def) = @_;
  609. my $km200_crypt_key_private = $hash->{Secret}{CRYPTKEYPRIVATE};
  610. my $name = $hash->{NAME};
  611. my $decryptData = $hash->{temp}{decodedcontent};
  612. ### Log entries for debugging purposes
  613. #Log3 $name, 5, $name. " : km200 - decryptData2 - decryptData : " .$decryptData;
  614. # Remove additional encoding with base64
  615. $decryptData = decode_base64($decryptData);
  616. ### Log entries for debugging purposes
  617. #Log3 $name, 5, $name. " : km200 - decryptData2 - base64decode : " .$decryptData;
  618. # Check whether the length of the decryptData is NOT multiplies of 16
  619. if ((length($decryptData)&0xF) != 0)
  620. {
  621. # Return nothing which will end this subroutine
  622. return "";
  623. }
  624. # Create Rijndael decryption object and do the decryption
  625. my $cipher = Crypt::Rijndael->new($km200_crypt_key_private, Crypt::Rijndael::MODE_ECB() );
  626. my $deciphertext = $cipher->decrypt( $decryptData );
  627. # Remove zero padding
  628. $deciphertext =~ s/\x00+$//;
  629. # Remove PKCS #7 padding
  630. my $decipher_len = length($deciphertext);
  631. my $decipher_padchar = ord(substr($deciphertext,($decipher_len - 1),1));
  632. my $i = 0;
  633. for ( $i = 0; $i < $decipher_padchar ; $i++ )
  634. {
  635. if ( $decipher_padchar != ord( substr($deciphertext,($decipher_len - $i - 1),1)))
  636. {
  637. last;
  638. }
  639. }
  640. # Return decrypted text
  641. if ( $i != $decipher_padchar )
  642. {
  643. ### Log entries for debugging purposes
  644. Log3 $name, 5, $name. " : km200 - decryptData1 - decipher_len : " .$decipher_len;
  645. $deciphertext =~ s/\x00+$//;
  646. Log3 $name, 5, $name. " : km200 - decryptData1 - deciphertext : " .$deciphertext;
  647. ### Log entries for debugging purposes
  648. return $deciphertext;
  649. }
  650. else
  651. {
  652. $deciphertext = substr($deciphertext,0,$decipher_len - $decipher_padchar);
  653. ### Log entries for debugging purposes
  654. Log3 $name, 5, $name. " : km200 - decryptData2 - decipher_len : " .$decipher_len;
  655. $deciphertext =~ s/\x00+$//;
  656. Log3 $name, 5, $name. " : km200 - decryptData2 - deciphertext : " .$deciphertext;
  657. ### Log entries for debugging purposes
  658. return $deciphertext;
  659. }
  660. }
  661. ####END####### Subroutine Decrypt Data #########################################################################END#####
  662. ###START###### Subroutine set individual data value ###########################################################START####
  663. sub km200_PostSingleService($)
  664. {
  665. my ($hash, $def) = @_;
  666. my $Service = $hash->{temp}{service};
  667. my $km200_gateway_host = $hash->{URL} ;
  668. my $name = $hash->{NAME} ;
  669. my $PollingTimeout = $hash->{POLLINGTIMEOUT};
  670. my $err;
  671. my $data;
  672. my $jsonSend;
  673. my $jsonRead;
  674. my $JsonContent;
  675. ### Log file entry for debugging
  676. Log3 $name, 5, $name. ("km200_Set - Writing value: " . $hash->{temp}{postdata} . " to the service : ". $Service . "\n");
  677. ### Read the current json string
  678. $jsonRead = km200_GetSingleService($hash);
  679. #### If the get-command returns an error due to an unknown Service requested
  680. if ($jsonRead -> {type} eq "ERROR")
  681. {
  682. ### Rescue original Service request
  683. my $WriteService = $Service;
  684. ### Try to replace the Post-String with nothing
  685. $Service =~ s/\/1-Mo//i;
  686. $Service =~ s/\/2-Tu//i;
  687. $Service =~ s/\/3-We//i;
  688. $Service =~ s/\/4-Th//i;
  689. $Service =~ s/\/5-Fr//i;
  690. $Service =~ s/\/6-Sa//i;
  691. $Service =~ s/\/7-Su//i;
  692. ### Save corrected string in hash
  693. $hash->{temp}{service} = $Service;
  694. ### Log file entry for debugging
  695. Log3 $name, 5, $name. "km200_Set - Trying to re-read Service - Assuming its a switchProgram list";
  696. ### Try again to read the current json string again with the corrected service
  697. $jsonRead = km200_GetSingleService($hash);
  698. ### Check whether the type is an switchProgram.
  699. ### If true, the requested service was a particular week of the switchProgram
  700. if ($jsonRead -> {type} eq "switchProgram")
  701. {
  702. ### Log file entry for debugging
  703. Log3 $name, 5, $name. "km200_Set - It is a switchProgram list!";
  704. ### For each weekday, get current readings, delete all unnecessary blanks and transform to array
  705. my $TempReadingVal;
  706. $TempReadingVal = ReadingsVal($name,($Service . "/1-Mo"),"");
  707. $TempReadingVal =~ s/\s+/ /g;
  708. $TempReadingVal =~ s/\s+$//g;
  709. my @TempReadingMo = split(/\s+/, $TempReadingVal,0);
  710. $TempReadingVal = ReadingsVal($name,($Service . "/2-Tu"),"");
  711. $TempReadingVal =~ s/\s+/ /g;
  712. $TempReadingVal =~ s/\s+$//g;
  713. my @TempReadingTu = split(/\s+/, $TempReadingVal,0);
  714. $TempReadingVal = ReadingsVal($name,($Service . "/3-We"),"");
  715. $TempReadingVal =~ s/\s+/ /g;
  716. $TempReadingVal =~ s/\s+$//g;
  717. my @TempReadingWe = split(/\s+/, $TempReadingVal,0);
  718. $TempReadingVal = ReadingsVal($name,($Service . "/4-Th"),"");
  719. $TempReadingVal =~ s/\s+/ /g;
  720. $TempReadingVal =~ s/\s+$//g;
  721. my @TempReadingTh = split(/\s+/, $TempReadingVal,0);
  722. $TempReadingVal = ReadingsVal($name,($Service . "/5-Fr"),"");
  723. $TempReadingVal =~ s/\s+/ /g;
  724. $TempReadingVal =~ s/\s+$//g;
  725. my @TempReadingFr = split(/\s+/, $TempReadingVal,0);
  726. $TempReadingVal = ReadingsVal($name,($Service . "/6-Sa"),"");
  727. $TempReadingVal =~ s/\s+/ /g;
  728. $TempReadingVal =~ s/\s+$//g;
  729. my @TempReadingSa = split(/\s+/, $TempReadingVal,0);
  730. $TempReadingVal = ReadingsVal($name,($Service . "/7-Su"),"");
  731. $TempReadingVal =~ s/\s+/ /g;
  732. $TempReadingVal =~ s/\s+$//g;
  733. my @TempReadingSu = split(/\s+/, $TempReadingVal,0);
  734. ### For value to be written, delete all unnecessary blanks and transform to array and get length of array
  735. my $ReturnString = $hash->{temp}{postdata};
  736. $ReturnString =~ s/\s+/ /g;
  737. $ReturnString =~ s/\s+$//g;
  738. my @TempReading = split(/\s+/, $ReturnString);
  739. my $TempReadingLength = @TempReading;
  740. ### Obtain the allowed terminology for setpoints
  741. $hash->{temp}{service} = $jsonRead -> {setpointProperty}{id};
  742. my $TempSetpointsJson = km200_GetSingleService($hash);
  743. my @TempSetpointNames =();
  744. ### For each item found in this empty parent directory
  745. foreach my $item (@{ $TempSetpointsJson->{references} })
  746. {
  747. my $TempSetPoint = substr($item->{id}, (rindex($item->{id}, "/") - length($item->{id}) +1));
  748. ### Add service, which is one of the allowed terminologies at the same time, to the list of all known services
  749. push (@TempSetpointNames, $TempSetPoint);
  750. }
  751. ### Restore the original service
  752. $hash->{temp}{service} = $Service;
  753. ### If number of switchpoints exceeds maximum allowed
  754. if (($TempReadingLength / 2) > $jsonRead -> {maxNbOfSwitchPointsPerDay})
  755. {
  756. return ("ERROR - Too much Switchpoints for weeklist inserted. \n Do not add more than " . $jsonRead -> {maxNbOfSwitchPointsPerDay} . " SwitchPoints per day!\n");
  757. }
  758. ### If content of array is not even
  759. if (($TempReadingLength % 2) != 0)
  760. {
  761. return "ERROR - At least one Switchtime or Switchpoint is missing. \n Make sure you always have couples of Switchtime and Switchpoint!\n";
  762. }
  763. ### Check whether description of setpoints is the same as referenced and the data is in the right order
  764. for (my $i=0;$i<$TempReadingLength;$i+=2)
  765. {
  766. ### If the even element behind the uneven index [1, 3, 5, ...] is not one of the pre-defined setpoints
  767. if (! grep /($TempReading[$i+1])/,@TempSetpointNames)
  768. {
  769. return "ERROR - At least for one Switchpoint the wrong terminology has been used. Only use one of the following items: " . join(' , ',@TempSetpointNames) ."\n";;
  770. }
  771. ### If the uneven element behind the even index [0, 2, 4, ...]is not a number, hand back an error message
  772. if ($TempReading[$i] !~ /^[0-9.-]+$/)
  773. {
  774. return "ERROR - At least for one Switchtime a number is expected at that position. \n Ensure the correct syntax of time and switchpoint. (E.g. 0600 eco)\n";
  775. }
  776. ### Convert timepoint into raster of defined switchPointTimeRaster
  777. my $TempHours = substr($TempReading[$i], 0, length($TempReading[$i])-2);
  778. if ($TempHours > 23)
  779. {
  780. $TempHours = 23;
  781. }
  782. my $TempMinutes = substr($TempReading[$i], -2);
  783. if ($TempMinutes > 59)
  784. {
  785. $TempMinutes = 59;
  786. }
  787. $TempMinutes = $TempMinutes / ($jsonRead -> {switchPointTimeRaster});
  788. $TempMinutes =~ s/^(.*?)\..*$/$1/;
  789. $TempMinutes = $TempMinutes * ($jsonRead -> {switchPointTimeRaster});
  790. $TempMinutes = sprintf ('%02d', $TempMinutes);
  791. $TempReading[$i] = ($TempHours . $TempMinutes);
  792. }
  793. $hash->{temp}{postdata} = join(" ", @TempReading);
  794. ### For the requested day to be changed, save new value
  795. if ($WriteService =~ m/1-Mo/i)
  796. {
  797. @TempReadingMo = @TempReading;
  798. }
  799. elsif ($WriteService =~ m/2-Tu/i)
  800. {
  801. @TempReadingTu = @TempReading;
  802. }
  803. elsif ($WriteService =~ m/3-We/i)
  804. {
  805. @TempReadingWe = @TempReading;
  806. }
  807. elsif ($WriteService =~ m/4-Th/i)
  808. {
  809. @TempReadingTh = @TempReading;
  810. }
  811. elsif ($WriteService =~ m/5-Fr/i)
  812. {
  813. @TempReadingFr = @TempReading;
  814. }
  815. elsif ($WriteService =~ m/6-Sa/i)
  816. {
  817. @TempReadingSa = @TempReading;
  818. }
  819. elsif ($WriteService =~ m/7-Su/i)
  820. {
  821. @TempReadingSu = @TempReading;
  822. }
  823. ### For every weekday create setpoint hash and push it to array of hashes of switchpoints to be send
  824. my @SwitchPointsSend =();
  825. for (my $i=0;$i<$#TempReadingMo;$i+=2)
  826. {
  827. my $TempHashSend;
  828. $TempHashSend->{"dayOfWeek"} = "Mo";
  829. my $TempHours = substr($TempReadingMo[$i], 0, length($TempReadingMo[$i])-2);
  830. my $TempMinutes = substr($TempReadingMo[$i], -2);
  831. $TempHashSend->{"time"} = ($TempHours * 60 ) + $TempMinutes;
  832. $TempHashSend->{"setpoint"} = $TempReadingMo[$i+1];
  833. push @SwitchPointsSend, $TempHashSend;
  834. }
  835. for (my $i=0;$i<$#TempReadingTu;$i+=2)
  836. {
  837. my $TempHashSend;
  838. $TempHashSend->{"dayOfWeek"} = "Tu";
  839. my $TempHours = substr($TempReadingTu[$i], 0, length($TempReadingTu[$i])-2);
  840. my $TempMinutes = substr($TempReadingTu[$i], -2);
  841. $TempHashSend->{"time"} = ($TempHours * 60 ) + $TempMinutes;
  842. $TempHashSend->{"setpoint"} = $TempReadingTu[$i+1];
  843. push @SwitchPointsSend, $TempHashSend;
  844. }
  845. for (my $i=0;$i<$#TempReadingWe;$i+=2)
  846. {
  847. my $TempHashSend;
  848. $TempHashSend->{"dayOfWeek"} = "We";
  849. my $TempHours = substr($TempReadingWe[$i], 0, length($TempReadingWe[$i])-2);
  850. my $TempMinutes = substr($TempReadingWe[$i], -2);
  851. $TempHashSend->{"time"} = ($TempHours * 60 ) + $TempMinutes;
  852. $TempHashSend->{"setpoint"} = $TempReadingWe[$i+1];
  853. push @SwitchPointsSend, $TempHashSend;
  854. }
  855. for (my $i=0;$i<$#TempReadingTh;$i+=2)
  856. {
  857. my $TempHashSend;
  858. $TempHashSend->{"dayOfWeek"} = "Th";
  859. my $TempHours = substr($TempReadingTh[$i], 0, length($TempReadingTh[$i])-2);
  860. my $TempMinutes = substr($TempReadingTh[$i], -2);
  861. $TempHashSend->{"time"} = ($TempHours * 60 ) + $TempMinutes;
  862. $TempHashSend->{"setpoint"} = $TempReadingTh[$i+1];
  863. push @SwitchPointsSend, $TempHashSend;
  864. }
  865. for (my $i=0;$i<$#TempReadingFr;$i+=2)
  866. {
  867. my $TempHashSend;
  868. $TempHashSend->{"dayOfWeek"} = "Fr";
  869. my $TempHours = substr($TempReadingFr[$i], 0, length($TempReadingFr[$i])-2);
  870. my $TempMinutes = substr($TempReadingFr[$i], -2);
  871. $TempHashSend->{"time"} = ($TempHours * 60 ) + $TempMinutes;
  872. $TempHashSend->{"setpoint"} = $TempReadingFr[$i+1];
  873. push @SwitchPointsSend, $TempHashSend;
  874. }
  875. for (my $i=0;$i<$#TempReadingSa;$i+=2)
  876. {
  877. my $TempHashSend;
  878. $TempHashSend->{"dayOfWeek"} = "Sa";
  879. my $TempHours = substr($TempReadingSa[$i], 0, length($TempReadingSa[$i])-2);
  880. my $TempMinutes = substr($TempReadingSa[$i], -2);
  881. $TempHashSend->{"time"} = ($TempHours * 60 ) + $TempMinutes;
  882. $TempHashSend->{"setpoint"} = $TempReadingSa[$i+1];
  883. push @SwitchPointsSend, $TempHashSend;
  884. }
  885. for (my $i=0;$i<$#TempReadingSu;$i+=2)
  886. {
  887. my $TempHashSend;
  888. $TempHashSend->{"dayOfWeek"} = "Su";
  889. my $TempHours = substr($TempReadingSu[$i], 0, length($TempReadingSu[$i])-2);
  890. my $TempMinutes = substr($TempReadingSu[$i], -2);
  891. $TempHashSend->{"time"} = ($TempHours * 60 ) + $TempMinutes;
  892. $TempHashSend->{"setpoint"} = $TempReadingSu[$i+1];
  893. push @SwitchPointsSend, $TempHashSend;
  894. }
  895. ### Save array of hashes of switchpoints into json hash to be send
  896. @{$jsonSend->{switchPoints}} = @SwitchPointsSend;
  897. ### Create full URL of the current Service to be written
  898. my $url ="http://" . $km200_gateway_host . $Service;
  899. ### Encode as json
  900. $JsonContent = encode_json($jsonSend);
  901. ### Delete the name of hash, "{" and "}" out of json String. No idea why but result of Try-and-Error method
  902. $JsonContent =~ s/{"switchPoints"://;
  903. $JsonContent =~ s/]}/]/g;
  904. ### Encrypt
  905. $hash->{temp}{jsoncontent} = $JsonContent;
  906. $data = km200_Encrypt($hash);
  907. ### Log file entry for debugging
  908. Log3 $name, 5, $name. "km200_Set - Trying to push switchPoint list to KM-Unit";
  909. ### Create parameter set for HttpUtils_BlockingGet
  910. my $param = {
  911. url => $url,
  912. timeout => $PollingTimeout * 5,
  913. data => $data,
  914. method => "POST",
  915. header => "agent: TeleHeater/2.2.3\r\nUser-Agent: TeleHeater/2.2.3\r\nAccept: application/json",
  916. };
  917. ### Block other scheduled and unscheduled routines
  918. $hash->{status}{FlagSetRequest} = true;
  919. ### Write value with HttpUtils_BlockingGet
  920. ($err, $data) = HttpUtils_BlockingGet($param);
  921. ### Reset flag
  922. $hash->{status}{FlagSetRequest} = false;
  923. ### If error message has been returned
  924. if($err ne "")
  925. {
  926. Log3 $name, 2, $name . " - ERROR: $err";
  927. return $err;
  928. }
  929. Log3 $name, 5, $name. ("Waiting for processing time (READBACKDELAY / [ms]) : " . $hash->{READBACKDELAY} . " \n");
  930. ### Make a pause before ReadBack
  931. usleep ($hash->{READBACKDELAY}*1000);
  932. ### Read service-hash and format it so it is compareable to the sent content
  933. my $ReReadContent = km200_GetSingleService($hash);
  934. $ReReadContent = $ReReadContent->{switchPoints};
  935. $ReReadContent = encode_json($ReReadContent);
  936. $ReReadContent =~ s/{"switchPoints"://;
  937. $ReReadContent =~ s/]}/]/g;
  938. ### Transform back into array of hashes
  939. eval
  940. {
  941. $ReReadContent = decode_json(encode_utf8($ReReadContent));
  942. $JsonContent = decode_json(encode_utf8($JsonContent));
  943. 1;
  944. }
  945. or do
  946. {
  947. };
  948. ### Set Counter for found items in SwitchPrograms
  949. my $FoundJsonItem = 0;
  950. ### For every item of the array of SwitchPrograms to be send
  951. foreach my $ReReadItem (@{$ReReadContent})
  952. {
  953. ### Set Counter for found items of ReRead values
  954. my $FoundReReadItem = 0;
  955. ### For every item of the array of SwitchPrograms after Re-Reading
  956. foreach my $JsonItem (@{$JsonContent})
  957. {
  958. ### If the current Switchprogram - hash does not have the same amount of keys
  959. if (%$ReReadItem ne %$JsonItem)
  960. {
  961. ### Do nothing
  962. #print "they don't have the same number of keys\n";
  963. }
  964. ### If the current Switchprogram - hash do have the same amount of keys
  965. else
  966. {
  967. ### Compare key names and values
  968. my %cmp = map { $_ => 1 } keys %$ReReadItem;
  969. for my $key (keys %$JsonItem)
  970. {
  971. last unless exists $cmp{$key};
  972. last unless $$ReReadItem{$key} eq $$JsonItem{$key};
  973. delete $cmp{$key};
  974. }
  975. if (%cmp)
  976. {
  977. ### Do nothing
  978. #print "they don't have the same keys or values\n";
  979. }
  980. else
  981. {
  982. ### Inkrement Counter
  983. $FoundReReadItem = 1;
  984. #print "they have the same keys and values\n";
  985. }
  986. }
  987. }
  988. ### If item has been found
  989. if ($FoundReReadItem == 1)
  990. {
  991. ### Inkrement Counter for found identical SwitchPoints
  992. $FoundJsonItem++;
  993. }
  994. }
  995. my $ReturnValue;
  996. if ($FoundJsonItem == @{$ReReadContent})
  997. {
  998. $ReturnValue = "The service " . $Service . " has been changed succesfully!";
  999. Log3 $name, 5, $name. "Writing $Service succesfully \n";
  1000. }
  1001. else
  1002. {
  1003. $ReturnValue = "ERROR - The service " . $Service . " could not changed! \n";
  1004. }
  1005. ### Return the status message
  1006. return $ReturnValue;
  1007. }
  1008. }
  1009. ### Check whether the type is an switchProgram.
  1010. ### If true, the requested service is referring to the entire week but not a particular week.
  1011. if ($jsonRead -> {type} eq "switchProgram")
  1012. {
  1013. ### Create full URL of the current Service to be written
  1014. my $url ="http://" . $km200_gateway_host . $Service;
  1015. ### Get the string to be send
  1016. $JsonContent = $hash->{temp}{postdata};
  1017. ### Encrypt
  1018. $hash->{temp}{jsoncontent} = $JsonContent;
  1019. $data = km200_Encrypt($hash);
  1020. ### Create parameter set for HttpUtils_BlockingGet
  1021. my $param = {
  1022. url => $url,
  1023. timeout => $PollingTimeout * 5,
  1024. data => $data,
  1025. method => "POST",
  1026. header => "agent: TeleHeater/2.2.3\r\nUser-Agent: TeleHeater/2.2.3\r\nAccept: application/json",
  1027. };
  1028. ### Block other scheduled and unscheduled routines
  1029. $hash->{status}{FlagSetRequest} = true;
  1030. ### Write value with HttpUtils_BlockingGet
  1031. ($err, $data) = HttpUtils_BlockingGet($param);
  1032. ### Reset flag
  1033. $hash->{status}{FlagSetRequest} = false;
  1034. ### If error message has been returned
  1035. if($err ne "")
  1036. {
  1037. Log3 $name, 2, $name . " - ERROR: $err";
  1038. return $err;
  1039. }
  1040. Log3 $name, 5, $name. ("Waiting for processing time (READBACKDELAY / [ms]) : " . $hash->{READBACKDELAY} . " \n");
  1041. ### Make a pause before ReadBack
  1042. usleep ($hash->{READBACKDELAY}*1000);
  1043. ### Read service-hash and format it so it is compareable to the sent content
  1044. my $ReReadContent = km200_GetSingleService($hash);
  1045. $ReReadContent = $ReReadContent->{switchPoints};
  1046. $ReReadContent = encode_json($ReReadContent);
  1047. $ReReadContent =~ s/{"switchPoints"://;
  1048. $ReReadContent =~ s/]}/]/g;
  1049. ### Transform back into array of hashes
  1050. eval
  1051. {
  1052. $ReReadContent = decode_json(encode_utf8($ReReadContent));
  1053. $JsonContent = decode_json(encode_utf8($JsonContent));
  1054. 1;
  1055. }
  1056. or do
  1057. {
  1058. };
  1059. ### Set Counter for found items in SwitchPrograms
  1060. my $FoundJsonItem = 0;
  1061. ### For every item of the array of SwitchPrograms to be send
  1062. foreach my $ReReadItem (@{$ReReadContent})
  1063. {
  1064. ### Set Counter for found items of ReRead values
  1065. my $FoundReReadItem = 0;
  1066. ### For every item of the array of SwitchPrograms after Re-Reading
  1067. foreach my $JsonItem (@{$JsonContent})
  1068. {
  1069. ### If the current Switchprogram - hash does not have the same amount of keys
  1070. if (%$ReReadItem != %$JsonItem)
  1071. {
  1072. ### Do nothing
  1073. #print "they don't have the same number of keys\n";
  1074. }
  1075. ### If the current Switchprogram - hash do have the same amount of keys
  1076. else
  1077. {
  1078. ### Compare key names and values
  1079. my %cmp = map { $_ => 1 } keys %$ReReadItem;
  1080. for my $key (keys %$JsonItem)
  1081. {
  1082. last unless exists $cmp{$key};
  1083. last unless $$ReReadItem{$key} eq $$JsonItem{$key};
  1084. delete $cmp{$key};
  1085. }
  1086. if (%cmp)
  1087. {
  1088. ### Do nothing
  1089. #print "they don't have the same keys or values\n";
  1090. }
  1091. else
  1092. {
  1093. ### Inkrement Counter
  1094. $FoundReReadItem = 1;
  1095. #print "they have the same keys and values\n";
  1096. }
  1097. }
  1098. }
  1099. ### If item has been found
  1100. if ($FoundReReadItem == 1)
  1101. {
  1102. ### Inkrement Counter for found identical SwitchPoints
  1103. $FoundJsonItem++;
  1104. }
  1105. }
  1106. my $ReturnValue;
  1107. if ($FoundJsonItem == @{$ReReadContent})
  1108. {
  1109. $ReturnValue = "The service " . $Service . " has been changed succesfully!";
  1110. Log3 $name, 5, $name. "The service $Service has been changed succesfully!";
  1111. }
  1112. else
  1113. {
  1114. $ReturnValue = "ERROR - The service " . $Service . " could not changed! \n";
  1115. Log3 $name, 5, $name. "Writing $Service was NOT succesfully";
  1116. }
  1117. ### Return the status message
  1118. return $ReturnValue;
  1119. }
  1120. ## Check whether the type is a single value containing a string
  1121. elsif($jsonRead->{type} eq "stringValue")
  1122. {
  1123. ### Save chosen value into hash to be send
  1124. $jsonSend->{value} = $hash->{temp}{postdata};
  1125. ### Log file entry for debugging
  1126. Log3 $name, 5, $name. "km200_Set - String value";
  1127. ### Create full URL of the current Service to be written
  1128. my $url ="http://" . $km200_gateway_host . $Service;
  1129. ### Encode as json
  1130. $JsonContent = encode_json($jsonSend);
  1131. ### Encrypt
  1132. $hash->{temp}{jsoncontent} = $JsonContent;
  1133. $data = km200_Encrypt($hash);
  1134. ### Create parameter set for HttpUtils_BlockingGet
  1135. my $param = {
  1136. url => $url,
  1137. timeout => $PollingTimeout,
  1138. data => $data,
  1139. method => "POST",
  1140. header => "agent: TeleHeater/2.2.3\r\nUser-Agent: TeleHeater/2.2.3\r\nAccept: application/json",
  1141. };
  1142. ### Block other scheduled and unscheduled routines
  1143. $hash->{status}{FlagSetRequest} = true;
  1144. ### Write value with HttpUtils_BlockingGet
  1145. ($err, $data) = HttpUtils_BlockingGet($param);
  1146. ### Reset flag
  1147. $hash->{status}{FlagSetRequest} = false;
  1148. ### If error message has been returned
  1149. if($err ne "")
  1150. {
  1151. Log3 $name, 2, $name . " - ERROR: $err";
  1152. return $err;
  1153. }
  1154. ### Make a pause before ReadBack
  1155. usleep ($hash->{READBACKDELAY}*1000);
  1156. ### Read service-hash
  1157. my $ReadValue = km200_GetSingleService($hash);
  1158. ### Return value
  1159. my $ReturnValue = "";
  1160. if ($ReadValue->{value} eq $hash->{temp}{postdata})
  1161. {
  1162. $ReturnValue = "The service " . $Service . " has been changed to: " . $ReadValue->{value};
  1163. Log3 $name, 5, $name. "km200_Set - Writing " . $Service . " succesfully with value: " . $hash->{temp}{postdata};
  1164. }
  1165. else
  1166. {
  1167. $ReturnValue = "ERROR - The service " . $Service . " could not changed.";
  1168. Log3 $name, 5, $name. "km200_Set - Writing " . $Service . " was NOT successful";
  1169. }
  1170. ### Return the status message
  1171. return $ReturnValue;
  1172. }
  1173. ## Check whether the type is a single value containing a float value
  1174. elsif($jsonRead -> {type} eq "floatValue")
  1175. {
  1176. ### Check whether value to be sent is numeric
  1177. if ($hash->{temp}{postdata} =~ /^[0-9.-]+$/)
  1178. {
  1179. ### Save chosen value into hash to be send
  1180. $jsonSend->{value} = ($hash->{temp}{postdata}) * 1;
  1181. ### Log file entry for debugging
  1182. Log3 $name, 5, $name. "km200_Set - Numeric value";
  1183. ### Create full URL of the current Service to be written
  1184. my $url ="http://" . $km200_gateway_host . $Service;
  1185. ### Encode as json
  1186. $JsonContent = encode_json($jsonSend);
  1187. ### Encrypt
  1188. $hash->{temp}{jsoncontent} = $JsonContent;
  1189. $data = km200_Encrypt($hash);
  1190. ### Create parameter set for HttpUtils_BlockingGet
  1191. my $param = {
  1192. url => $url,
  1193. timeout => $PollingTimeout,
  1194. data => $data,
  1195. method => "POST",
  1196. header => "agent: TeleHeater/2.2.3\r\nUser-Agent: TeleHeater/2.2.3\r\nAccept: application/json",
  1197. };
  1198. ### Block other scheduled and unscheduled routines
  1199. $hash->{status}{FlagSetRequest} = true;
  1200. ### Write value with HttpUtils_BlockingGet
  1201. ($err, $data) = HttpUtils_BlockingGet($param);
  1202. ### Reset flag
  1203. $hash->{status}{FlagSetRequest} = false;
  1204. ### If error messsage has been returned
  1205. if($err ne "")
  1206. {
  1207. Log3 $name, 2, $name . " - ERROR: $err";
  1208. return $err;
  1209. }
  1210. ### Make a pause before ReadBack
  1211. usleep ($hash->{READBACKDELAY}*1000);
  1212. ### Read service-hash
  1213. my $ReadValue = km200_GetSingleService($hash);
  1214. ### Return value
  1215. my $ReturnValue = "";
  1216. if ($ReadValue->{value} eq $hash->{temp}{postdata})
  1217. {
  1218. $ReturnValue = "The service " . $Service . " has been changed to: " . $ReadValue->{value} . "\n";
  1219. Log3 $name, 5, $name. "km200_Set - Writing " . $Service . " succesfully with value: " . $hash->{temp}{postdata};
  1220. }
  1221. elsif ($jsonRead -> {value} == $ReadValue->{value})
  1222. {
  1223. $ReturnValue = "ERROR - The service " . $Service . " could not changed to: " . $hash->{temp}{postdata} . "\n The value is: " . $ReadValue->{value} . "\n";
  1224. Log3 $name, 5, $name. "km200_Set - Writing " . $Service . " was NOT successful";
  1225. }
  1226. else
  1227. {
  1228. $ReturnValue = "The service " . $Service . " has been rounded to: " . $ReadValue->{value} . "\n";
  1229. Log3 $name, 5, $name. "km200_Set - Writing " . $Service . " was rounded and changed successful";
  1230. }
  1231. ### Return the status message
  1232. return $ReturnValue;
  1233. }
  1234. ### If the value to be sent is NOT numeric
  1235. else
  1236. {
  1237. ### Log file entry for debugging
  1238. Log3 $name, 5, $name. "km200_Set - ERROR - Float value expected!";
  1239. return ("km200_Set - ERROR - Float value expected!\n");
  1240. }
  1241. }
  1242. ## If the type is unknown
  1243. else
  1244. {
  1245. ### Log entries for debugging purposes
  1246. Log3 $name, 4, $name. " : km200_SetSingleService - type unknown for : " .$Service;
  1247. }
  1248. }
  1249. ####END####### Subroutine set individual data value ############################################################END#####
  1250. ###START###### Subroutine get individual data value ###########################################################START####
  1251. sub km200_GetSingleService($)
  1252. {
  1253. my ($hash, $def) = @_;
  1254. my $Service = $hash->{temp}{service};
  1255. my $km200_gateway_host = $hash->{URL};
  1256. my $name = $hash->{NAME};
  1257. my $PollingTimeout = $hash->{POLLINGTIMEOUT};
  1258. my $json -> {type} = "";
  1259. $json -> {value} = "";
  1260. my $err;
  1261. my $data;
  1262. ### Log entries for debugging purposes
  1263. Log3 $name, 5, $name. " : km200 - GetSingleService - service : " .$Service;
  1264. ### Create full URL of the current Service to be read
  1265. my $url ="http://" . $km200_gateway_host . $Service;
  1266. ### Log entries for debugging purposes
  1267. Log3 $name, 5, $name. " : km200 - GetSingleService - url : " .$url;
  1268. ### Create parameter set for HttpUtils_BlockingGet
  1269. my $param = {
  1270. url => $url,
  1271. timeout => $PollingTimeout,
  1272. method => "GET",
  1273. header => "agent: TeleHeater/2.2.3\r\nUser-Agent: TeleHeater/2.2.3\r\nAccept: application/json",
  1274. };
  1275. ### Block other scheduled and unscheduled routines
  1276. $hash->{status}{FlagGetRequest} = true;
  1277. ### Retrieve data from km200
  1278. ($err, $data) = HttpUtils_BlockingGet($param);
  1279. ### Log entries for debugging purposes
  1280. Log3 $name, 5, $name. " : km200 - GetSingleService - err : " .$err;
  1281. Log3 $name, 5, $name. " : km200 - GetSingleService - data : " .$data;
  1282. ### Block other scheduled and unscheduled routines
  1283. $hash->{status}{FlagGetRequest} = false;
  1284. ### If error message has been reported
  1285. if($err ne "")
  1286. {
  1287. Log3 $name, 2, $name . " : ERROR: Service: ".$Service. ": No proper Communication with Gateway: " .$err;
  1288. my $ReturnMessage ="ERROR";
  1289. $json -> {type} = $ReturnMessage;
  1290. $json -> {value} = $ReturnMessage;
  1291. return $json;
  1292. }
  1293. ### If NO error message has been reported
  1294. else
  1295. {
  1296. $hash->{temp}{decodedcontent} = $data;
  1297. my $decodedContent = km200_Decrypt($hash);
  1298. if ($decodedContent ne "")
  1299. {
  1300. eval
  1301. {
  1302. $json = decode_json(encode_utf8($decodedContent));
  1303. 1;
  1304. }
  1305. or do
  1306. {
  1307. Log3 $name, 5, $name. " : km200_GetSingleService - Data cannot be parsed by JSON on km200 for http://" . $param->{url};
  1308. };
  1309. ### Check whether the type is a single value containing a string or float value
  1310. if(($json -> {type} eq "stringValue") || ($json -> {type} eq "floatValue"))
  1311. {
  1312. my $JsonId = $json->{id};
  1313. my $JsonType = $json->{type};
  1314. my $JsonValue = $json->{value};
  1315. ### Save json-hash for DbLog-Split
  1316. $hash->{temp}{ServiceDbLogSplitHash} = $json;
  1317. $hash->{temp}{JsonRaw} = $decodedContent;
  1318. ### Write reading for fhem
  1319. readingsSingleUpdate( $hash, $JsonId, $JsonValue, 1);
  1320. return $json
  1321. }
  1322. ### Check whether the type is an switchProgram
  1323. elsif ($json -> {type} eq "switchProgram")
  1324. {
  1325. my $JsonId = $json->{id};
  1326. my $JsonType = $json->{type};
  1327. ### Log entries for debugging purposes
  1328. Log3 $name, 4, $name. " : km200_GetSingleService - value found for : " .$Service;
  1329. Log3 $name, 5, $name. " : km200_GetSingleService - id : " .$JsonId;
  1330. Log3 $name, 5, $name. " : km200_GetSingleService - type : " .$JsonType;
  1331. ### Set up variables
  1332. my $TempReturnVal = "";
  1333. my $TempReadingMo = "";
  1334. my $TempReadingTu = "";
  1335. my $TempReadingWe = "";
  1336. my $TempReadingTh = "";
  1337. my $TempReadingFr = "";
  1338. my $TempReadingSa = "";
  1339. my $TempReadingSu = "";
  1340. foreach my $item (@{ $json->{switchPoints} })
  1341. {
  1342. ### Create string for time and switchpoint in fixed format and write part of Reading String
  1343. my $time = $item->{time};
  1344. my $temptime = $time / 60;
  1345. my $temptimeHH = int($temptime);
  1346. my $temptimeMM = ($time - ($temptimeHH * 60));
  1347. $temptimeHH = sprintf ('%02d', $temptimeHH);
  1348. $temptimeMM = sprintf ('%02d', $temptimeMM);
  1349. $temptime = $temptimeHH . $temptimeMM;
  1350. my $tempsetpoint = $item->{setpoint};
  1351. $tempsetpoint =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(8-length($1)))/e;
  1352. my $TempReading = $temptime . " " . $tempsetpoint;
  1353. ### Create ValueString for this day
  1354. if ($item->{dayOfWeek} eq "Mo")
  1355. {
  1356. ### If it is the first entry for this day
  1357. if ($TempReadingMo eq "")
  1358. {
  1359. ### Write the first entry
  1360. $TempReadingMo = $TempReading;
  1361. }
  1362. ### If it is NOT the first entry for this day
  1363. else
  1364. {
  1365. ### Add the next entry
  1366. $TempReadingMo = $TempReadingMo . " " . $TempReading;
  1367. }
  1368. }
  1369. elsif ($item->{dayOfWeek} eq "Tu")
  1370. {
  1371. ### If it is the first entry for this day
  1372. if ($TempReadingTu eq "")
  1373. {
  1374. ### Write the first entry
  1375. $TempReadingTu = $TempReading;
  1376. }
  1377. ### If it is NOT the first entry for this day
  1378. else
  1379. {
  1380. ### Add the next entry
  1381. $TempReadingTu = $TempReadingTu . " " . $TempReading;
  1382. }
  1383. }
  1384. elsif ($item->{dayOfWeek} eq "We")
  1385. {
  1386. ### If it is the first entry for this day
  1387. if ($TempReadingWe eq "")
  1388. {
  1389. ### Write the first entry
  1390. $TempReadingWe = $TempReading;
  1391. }
  1392. ### If it is NOT the first entry for this day
  1393. else
  1394. {
  1395. ### Add the next entry
  1396. $TempReadingWe = $TempReadingWe . " " . $TempReading;
  1397. }
  1398. }
  1399. elsif ($item->{dayOfWeek} eq "Th")
  1400. {
  1401. ### If it is the first entry for this day
  1402. if ($TempReadingTh eq "")
  1403. {
  1404. ### Write the first entry
  1405. $TempReadingTh = $TempReading;
  1406. }
  1407. ### If it is NOT the first entry for this day
  1408. else
  1409. {
  1410. ### Add the next entry
  1411. $TempReadingTh = $TempReadingTh . " " . $TempReading;
  1412. }
  1413. }
  1414. elsif ($item->{dayOfWeek} eq "Fr")
  1415. {
  1416. ### If it is the first entry for this day
  1417. if ($TempReadingFr eq "")
  1418. {
  1419. ### Write the first entry
  1420. $TempReadingFr = $TempReading;
  1421. }
  1422. ### If it is NOT the first entry for this day
  1423. else
  1424. {
  1425. ### Add the next entry
  1426. $TempReadingFr = $TempReadingFr . " " . $TempReading;
  1427. }
  1428. }
  1429. elsif ($item->{dayOfWeek} eq "Sa")
  1430. {
  1431. ### If it is the first entry for this day
  1432. if ($TempReadingSa eq "")
  1433. {
  1434. ### Write the first entry
  1435. $TempReadingSa = $TempReading;
  1436. }
  1437. ### If it is NOT the first entry for this day
  1438. else
  1439. {
  1440. ### Add the next entry
  1441. $TempReadingSa = $TempReadingSa . " " . $TempReading;
  1442. }
  1443. }
  1444. elsif ($item->{dayOfWeek} eq "Su")
  1445. {
  1446. ### If it is the first entry for this day
  1447. if ($TempReadingSu eq "")
  1448. {
  1449. ### Write the first entry
  1450. $TempReadingSu = $TempReading;
  1451. }
  1452. ### If it is NOT the first entry for this day
  1453. else
  1454. {
  1455. ### Add the next entry
  1456. $TempReadingSu = $TempReadingSu . " " . $TempReading;
  1457. }
  1458. }
  1459. else
  1460. {
  1461. Log3 $name, 5, $name. "dayOfWeek of unknow day: " . $item->{dayOfWeek};
  1462. }
  1463. }
  1464. ### Create new Service and write reading for fhem
  1465. $TempReturnVal = "1-Mo: " . $TempReadingMo . "\n";
  1466. $TempReturnVal = $TempReturnVal . "2-Tu: " . $TempReadingTu . "\n";
  1467. $TempReturnVal = $TempReturnVal . "3-We: " . $TempReadingWe . "\n";
  1468. $TempReturnVal = $TempReturnVal . "4-Th: " . $TempReadingTh . "\n";
  1469. $TempReturnVal = $TempReturnVal . "5-Fr: " . $TempReadingFr . "\n";
  1470. $TempReturnVal = $TempReturnVal . "6-Sa: " . $TempReadingSa . "\n";
  1471. $TempReturnVal = $TempReturnVal . "7-Su: " . $TempReadingSu . "\n";
  1472. ### Save weeklist in "value"
  1473. $json->{value} = $TempReturnVal;
  1474. ### Save raw Json string
  1475. $hash->{temp}{JsonRaw} = $decodedContent;
  1476. my $TempJsonId;
  1477. ### Create new Service and write reading for fhem
  1478. $TempJsonId = $JsonId . "/" . "1-Mo";
  1479. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingMo, 1);
  1480. ### Create new Service and write reading for fhem
  1481. $TempJsonId = $JsonId . "/" . "2-Tu";
  1482. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingTu, 1);
  1483. ### Create new Service and write reading for fhem
  1484. $TempJsonId = $JsonId . "/" . "3-We";
  1485. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingWe, 1);
  1486. ### Create new Service and write reading for fhem
  1487. $TempJsonId = $JsonId . "/" . "4-Th";
  1488. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingTh, 1);
  1489. ### Create new Service and write reading for fhem
  1490. $TempJsonId = $JsonId . "/" . "5-Fr";
  1491. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingFr, 1);
  1492. ### Create new Service and write reading for fhem
  1493. $TempJsonId = $JsonId . "/" . "6-Sa";
  1494. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingSa, 1);
  1495. ### Create new Service and write reading for fhem
  1496. $TempJsonId = $JsonId . "/" . "7-Su";
  1497. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingSu, 1);
  1498. return $json
  1499. }
  1500. ### Check whether the type is an errorlist
  1501. elsif ($json -> {type} eq "errorList")
  1502. {
  1503. my $TempErrorList = "";
  1504. ### Sort list by timestamps descending
  1505. my @TempSortedErrorList = sort { $b->{t} cmp $a->{t} } @{ $json->{values} };
  1506. # my @TempSortedErrorList = @{ $json->{values} } ;
  1507. ### For every notification do
  1508. foreach my $item (@TempSortedErrorList)
  1509. {
  1510. ### Create message string with fixed blocksize
  1511. my $TempTime = $item->{t};
  1512. if ($TempTime) {$TempTime =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(20-length($1)))/e;}
  1513. my $TempErrorCode = $item->{dcd};
  1514. $TempErrorCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(3 -length($1)))/e;
  1515. my $TempAddCode = $item->{ccd};
  1516. $TempAddCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(4 -length($1)))/e;
  1517. my $TempClassCode = $item->{cat};
  1518. $TempClassCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(2- length($1)))/e;
  1519. my $TempErrorMessage = "Time: " . $TempTime . "-ErrorCode: " . $TempErrorCode . " -AddCode: " . $TempAddCode . " -Category: " . $TempClassCode;
  1520. ### Create List
  1521. $TempErrorList = $TempErrorList . $TempErrorMessage . "\n";
  1522. }
  1523. ### Save raw Json string
  1524. $hash->{temp}{JsonRaw} = $decodedContent;
  1525. ### Save errorList
  1526. $json->{value} = $TempErrorList;
  1527. return $json;
  1528. }
  1529. ### Check whether the type is an refEnum which is indicating an empty parent directory
  1530. elsif ($json -> {type} eq "refEnum")
  1531. {
  1532. ### Initialise Return Message
  1533. my $ReturnMessage = "";
  1534. ### For each item found in this empty parent directory
  1535. foreach my $item (@{ $json->{references} })
  1536. {
  1537. ### If it is the first item in the list
  1538. if ($ReturnMessage eq "")
  1539. {
  1540. $ReturnMessage = $item->{id};
  1541. }
  1542. ### If it is not the first item in the list
  1543. else
  1544. {
  1545. $ReturnMessage = $ReturnMessage . "\n" . $item->{id};
  1546. }
  1547. }
  1548. ### Return list of available directories
  1549. $json->{value} = $ReturnMessage;
  1550. ### Save raw Json string
  1551. $hash->{temp}{JsonRaw} = $decodedContent;
  1552. return $json;
  1553. }
  1554. ### Check whether the type is a systeminfo
  1555. elsif ($json -> {type} eq "systeminfo")
  1556. {
  1557. my $JsonId = $json->{id};
  1558. my $JsonType = $json->{type};
  1559. my @JsonValues = $json->{values};
  1560. ### Log entries for debugging purposes
  1561. Log3 $name, 4, $name. " : km200_GetSingleService - value found for : " .$Service;
  1562. Log3 $name, 5, $name. " : km200_GetSingleService - id : " .$JsonId;
  1563. Log3 $name, 5, $name. " : km200_GetSingleService - type : " .$JsonType;
  1564. ### Initialise Return Message
  1565. my $ReturnMessage = "";
  1566. ### Initialise ArrayCounter
  1567. my $ArrayCounter = 0;
  1568. foreach my $ArrayItem (@{ $json->{values} })
  1569. {
  1570. ### Incrementation of ArrayCounter
  1571. $ArrayCounter++;
  1572. ### Get array from scalar
  1573. my %ArrayHash = %{$ArrayItem};
  1574. while( my( $SystemInfoHashKey, $SystemInfoHashValue ) = each %ArrayHash )
  1575. {
  1576. ### Create new Service and write reading for fhem
  1577. my $TempJsonId = $JsonId . "/" . sprintf ('%02d', $ArrayCounter) . "/" . $SystemInfoHashKey;
  1578. readingsSingleUpdate( $hash, $TempJsonId, $SystemInfoHashValue, 1);
  1579. ### If it is the first item in the list
  1580. if ($ReturnMessage eq "")
  1581. {
  1582. $ReturnMessage = $TempJsonId . " = " . $SystemInfoHashValue;
  1583. }
  1584. ### If it is not the first item in the list
  1585. else
  1586. {
  1587. $ReturnMessage = $ReturnMessage . "\n" . $TempJsonId . " = " . $SystemInfoHashValue;
  1588. }
  1589. }
  1590. }
  1591. ### Return list of available directories
  1592. $json->{value} = $ReturnMessage;
  1593. ### Save raw Json string
  1594. $hash->{temp}{JsonRaw} = $decodedContent;
  1595. return $json;
  1596. }
  1597. ### If the type is unknown
  1598. else
  1599. {
  1600. ### Log entries for debugging purposes
  1601. Log3 $name, 4, $name. " : km200_GetSingleService - type unknown for : " .$Service;
  1602. ### Log entries for debugging purposes
  1603. }
  1604. }
  1605. else
  1606. {
  1607. Log3 $name, 4, $name. " : km200_GetSingleService: ". $Service . " NOT available";
  1608. my $ReturnMessage = "ERROR";
  1609. $json -> {type} = $ReturnMessage;
  1610. $json -> {value} = $ReturnMessage;
  1611. return $json;
  1612. }
  1613. }
  1614. }
  1615. ####END####### Subroutine get individual data value ############################################################END#####
  1616. ###START###### Subroutine initial contact of services via HttpUtils ###########################################START####
  1617. sub km200_GetInitService($)
  1618. {
  1619. my ($hash, $def) = @_;
  1620. my $km200_gateway_host = $hash->{URL} ;
  1621. my $name = $hash->{NAME} ;
  1622. $hash->{status}{FlagInitRequest} = true;
  1623. my @KM200_InitServices = @{$hash->{Secret}{KM200ALLSERVICES}};
  1624. my $ServiceCounterInit = $hash->{temp}{ServiceCounterInit};
  1625. my $PollingTimeout = $hash->{POLLINGTIMEOUT};
  1626. my $Service = $KM200_InitServices[$ServiceCounterInit];
  1627. ### Stop the current timer
  1628. RemoveInternalTimer($hash);
  1629. ### If this this loop is accessed for the first time, stop the timer and set status
  1630. if ($ServiceCounterInit == 0)
  1631. {
  1632. ### Log file entry for debugging
  1633. Log3 $name, 5, $name. "Sounding and importing of services started";
  1634. ### Set status of km200 fhem module
  1635. $hash->{STATE} = "Sounding...";
  1636. }
  1637. ### Get the values
  1638. my $url ="http://" . $km200_gateway_host . $Service;
  1639. my $param = {
  1640. url => $url,
  1641. timeout => $PollingTimeout,
  1642. hash => $hash,
  1643. method => "GET",
  1644. header => "agent: TeleHeater/2.2.3\r\nUser-Agent: TeleHeater/2.2.3\r\nAccept: application/json",
  1645. callback => \&km200_ParseHttpResponseInit
  1646. };
  1647. ### Set flag for initialisation
  1648. $hash->{status}{FlagInitRequest} = true;
  1649. ### Get the value
  1650. HttpUtils_NonblockingGet($param);
  1651. }
  1652. ####END####### Subroutine initial contact of services via HttpUtils ############################################END#####
  1653. ###START###### Subroutine to download complete initial data set from gateway ##################################START####
  1654. # For all known, but not excluded services by attribute "DoNotPoll", try reading the respective values from gateway
  1655. sub km200_ParseHttpResponseInit($)
  1656. {
  1657. my ($param, $err, $data) = @_;
  1658. my $hash = $param->{hash};
  1659. my $name = $hash ->{NAME};
  1660. my $ServiceCounterInit = $hash ->{temp}{ServiceCounterInit};
  1661. my @KM200_RespondingServices = @{$hash ->{Secret}{KM200RESPONDINGSERVICES}};
  1662. my @KM200_WriteableServices = @{$hash ->{Secret}{KM200WRITEABLESERVICES}};
  1663. my @KM200_InitServices = @{$hash ->{Secret}{KM200ALLSERVICES}};
  1664. my $NumberInitServices = "";
  1665. my $Service = $KM200_InitServices[$ServiceCounterInit];
  1666. my $type;
  1667. my $json ->{type} = "";
  1668. if($err ne "")
  1669. {
  1670. ### Create Log entry
  1671. Log3 $name, 2, $name . " : km200_ParseHttpResponseInit - ERROR : ".$Service. ": No proper Communication with Gateway: " .$err;
  1672. ### Set status of km200 fhem module
  1673. $hash->{STATE} = "ERROR - Initial Connection failed... Try to re-connect in 10s";
  1674. ### Start the timer for polling again but wait 10s
  1675. InternalTimer(gettimeofday()+10, "km200_GetInitService", $hash, 1);
  1676. ### Create Log entry
  1677. Log3 $name, 2, $name . " : km200_ParseHttpResponseInit - ERROR : Timer restarted to try again in 10s";
  1678. Log3 $name, 5, $name . "______________________________________________________________________________________________________________________";
  1679. return "ERROR";
  1680. }
  1681. $hash->{temp}{decodedcontent} = $data;
  1682. my $decodedContent = km200_Decrypt($hash);
  1683. ### Check whether the decoded content is not empty and therefore available
  1684. if ($decodedContent ne "")
  1685. {
  1686. eval
  1687. {
  1688. $json = decode_json(encode_utf8($decodedContent));
  1689. 1;
  1690. }
  1691. or do
  1692. {
  1693. Log3 $name, 4, $name. " : km200_ParseHttpResponseInit - CANNOT be parsed : ". $Service;
  1694. };
  1695. ### Check whether the type is a single value containing a string or float value
  1696. if(($json -> {type} eq "stringValue") || ($json -> {type} eq "floatValue"))
  1697. {
  1698. my $JsonId = $json->{id};
  1699. my $JsonType = $json->{type};
  1700. my $JsonValue = $json->{value};
  1701. ### Log entries for debugging purposes
  1702. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value found for : " .$Service;
  1703. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - id : " .$JsonId;
  1704. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - type : " .$JsonType;
  1705. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value : " .$JsonValue;
  1706. ### Add service to the list of responding services
  1707. push (@KM200_RespondingServices, $Service);
  1708. ### Delete double entries in the list of responding services and sort in alphabetical order
  1709. my %FilteredKM200RespondingServices;
  1710. $FilteredKM200RespondingServices{$_}=0 for @KM200_RespondingServices;
  1711. @KM200_RespondingServices = (keys %FilteredKM200RespondingServices);
  1712. @KM200_RespondingServices = sort @KM200_RespondingServices;
  1713. ### Save json-hash for DbLog-Split
  1714. $hash->{temp}{ServiceDbLogSplitHash} = $json;
  1715. ### Write reading for fhem
  1716. readingsSingleUpdate( $hash, $JsonId, $JsonValue, 1);
  1717. ### Log file entry for debugging
  1718. my $LogMessage = " : The following Service can be read";
  1719. ### Check whether service is writeable and write name of service in array
  1720. if ($json->{writeable} == 1)
  1721. {
  1722. $LogMessage = $LogMessage . " and is writeable";
  1723. push (@KM200_WriteableServices, $Service);
  1724. }
  1725. else
  1726. {
  1727. # Do nothing
  1728. $LogMessage = $LogMessage . " ";
  1729. }
  1730. ### Log file entry for debugging
  1731. $LogMessage = $LogMessage . " : " . $JsonId;
  1732. Log3 $name, 4, $name. $LogMessage;
  1733. }
  1734. ### Check whether the type is an switchProgram
  1735. elsif ($json -> {type} eq "switchProgram")
  1736. {
  1737. my $JsonId = $json->{id};
  1738. my $JsonType = $json->{type};
  1739. my @JsonValues = $json->{switchPoints};
  1740. ### Log entries for debugging purposes
  1741. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value found for : " .$Service;
  1742. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - id : " .$JsonId;
  1743. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - type : " .$JsonType;
  1744. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value : " .@JsonValues;
  1745. ### Add service to the list of responding services
  1746. push (@KM200_RespondingServices, $Service);
  1747. ### Delete double entries in the list of responding services and sort in alphabetical order
  1748. my %FilteredKM200RespondingServices;
  1749. $FilteredKM200RespondingServices{$_}=0 for @KM200_RespondingServices;
  1750. @KM200_RespondingServices = (keys %FilteredKM200RespondingServices);
  1751. @KM200_RespondingServices = sort @KM200_RespondingServices;
  1752. ### Log file entry for debugging
  1753. my $LogMessage = " : The following Service can be read";
  1754. ### Check whether service is writeable and write name of service in array
  1755. if ($json->{writeable} == 1)
  1756. {
  1757. $LogMessage = $LogMessage . " and is writeable";
  1758. push (@KM200_WriteableServices, $Service);
  1759. }
  1760. else
  1761. {
  1762. # Do nothing
  1763. $LogMessage = $LogMessage . " ";
  1764. }
  1765. $LogMessage = $LogMessage . " : " .$JsonId;
  1766. Log3 $name, 4, $name . $LogMessage;
  1767. ### Set up variables
  1768. my $TempJsonId = "";
  1769. my $TempReadingMo = "";
  1770. my $TempReadingTu = "";
  1771. my $TempReadingWe = "";
  1772. my $TempReadingTh = "";
  1773. my $TempReadingFr = "";
  1774. my $TempReadingSa = "";
  1775. my $TempReadingSu = "";
  1776. foreach my $item (@{ $json->{switchPoints} })
  1777. {
  1778. ### Create string for time and switchpoint in fixed format and write part of Reading String
  1779. my $time = $item->{time};
  1780. my $temptime = $time / 60;
  1781. my $temptimeHH = int($temptime);
  1782. my $temptimeMM = ($time - ($temptimeHH * 60));
  1783. $temptimeHH = sprintf ('%02d', $temptimeHH);
  1784. $temptimeMM = sprintf ('%02d', $temptimeMM);
  1785. $temptime = $temptimeHH . $temptimeMM;
  1786. my $tempsetpoint = $item->{setpoint};
  1787. $tempsetpoint =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(8-length($1)))/e;
  1788. my $TempReading = $temptime . " " . $tempsetpoint;
  1789. ### Create ValueString for this day
  1790. if ($item->{dayOfWeek} eq "Mo")
  1791. {
  1792. ### If it is the first entry for this day
  1793. if ($TempReadingMo eq "")
  1794. {
  1795. ### Write the first entry
  1796. $TempReadingMo = $TempReading;
  1797. }
  1798. ### If it is NOT the first entry for this day
  1799. else
  1800. {
  1801. ### Add the next entry
  1802. $TempReadingMo = $TempReadingMo . " " . $TempReading;
  1803. }
  1804. }
  1805. elsif ($item->{dayOfWeek} eq "Tu")
  1806. {
  1807. ### If it is the first entry for this day
  1808. if ($TempReadingTu eq "")
  1809. {
  1810. ### Write the first entry
  1811. $TempReadingTu = $TempReading;
  1812. }
  1813. ### If it is NOT the first entry for this day
  1814. else
  1815. {
  1816. ### Add the next entry
  1817. $TempReadingTu = $TempReadingTu . " " . $TempReading;
  1818. }
  1819. }
  1820. elsif ($item->{dayOfWeek} eq "We")
  1821. {
  1822. ### If it is the first entry for this day
  1823. if ($TempReadingWe eq "")
  1824. {
  1825. ### Write the first entry
  1826. $TempReadingWe = $TempReading;
  1827. }
  1828. ### If it is NOT the first entry for this day
  1829. else
  1830. {
  1831. ### Add the next entry
  1832. $TempReadingWe = $TempReadingWe . " " . $TempReading;
  1833. }
  1834. }
  1835. elsif ($item->{dayOfWeek} eq "Th")
  1836. {
  1837. ### If it is the first entry for this day
  1838. if ($TempReadingTh eq "")
  1839. {
  1840. ### Write the first entry
  1841. $TempReadingTh = $TempReading;
  1842. }
  1843. ### If it is NOT the first entry for this day
  1844. else
  1845. {
  1846. ### Add the next entry
  1847. $TempReadingTh = $TempReadingTh . " " . $TempReading;
  1848. }
  1849. }
  1850. elsif ($item->{dayOfWeek} eq "Fr")
  1851. {
  1852. ### If it is the first entry for this day
  1853. if ($TempReadingFr eq "")
  1854. {
  1855. ### Write the first entry
  1856. $TempReadingFr = $TempReading;
  1857. }
  1858. ### If it is NOT the first entry for this day
  1859. else
  1860. {
  1861. ### Add the next entry
  1862. $TempReadingFr = $TempReadingFr . " " . $TempReading;
  1863. }
  1864. }
  1865. elsif ($item->{dayOfWeek} eq "Sa")
  1866. {
  1867. ### If it is the first entry for this day
  1868. if ($TempReadingSa eq "")
  1869. {
  1870. ### Write the first entry
  1871. $TempReadingSa = $TempReading;
  1872. }
  1873. ### If it is NOT the first entry for this day
  1874. else
  1875. {
  1876. ### Add the next entry
  1877. $TempReadingSa = $TempReadingSa . " " . $TempReading;
  1878. }
  1879. }
  1880. elsif ($item->{dayOfWeek} eq "Su")
  1881. {
  1882. ### If it is the first entry for this day
  1883. if ($TempReadingSu eq "")
  1884. {
  1885. ### Write the first entry
  1886. $TempReadingSu = $TempReading;
  1887. }
  1888. ### If it is NOT the first entry for this day
  1889. else
  1890. {
  1891. ### Add the next entry
  1892. $TempReadingSu = $TempReadingSu . " " . $TempReading;
  1893. }
  1894. }
  1895. else
  1896. {
  1897. Log3 $name, 5, $name. "dayOfWeek of unknow day: " . $item->{dayOfWeek};
  1898. }
  1899. }
  1900. ### Create new Service and write reading for fhem
  1901. $TempJsonId = $JsonId . "/" . "1-Mo";
  1902. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingMo, 1);
  1903. ### Log file entry for debugging
  1904. Log3 $name, 5, $name. " : The following Service can be read and is writeable : " . $TempJsonId;
  1905. ### Add service to the list of writeable services
  1906. push (@KM200_WriteableServices, $TempJsonId);
  1907. ### Create new Service and write reading for fhem
  1908. $TempJsonId = $JsonId . "/" . "2-Tu";
  1909. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingTu, 1);
  1910. ### Log file entry for debugging
  1911. Log3 $name, 5, $name. " : The following Service can be read and is writeable : " . $TempJsonId;
  1912. ### Add service to the list of writeable services
  1913. push (@KM200_WriteableServices, $TempJsonId);
  1914. ### Create new Service and write reading for fhem
  1915. $TempJsonId = $JsonId . "/" . "3-We";
  1916. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingWe, 1);
  1917. ### Log file entry for debugging
  1918. Log3 $name, 5, $name. " : The following Service can be read and is writeable : " . $TempJsonId;
  1919. ### Add service to the list of writeable services
  1920. push (@KM200_WriteableServices, $TempJsonId);
  1921. ### Create new Service and write reading for fhem
  1922. $TempJsonId = $JsonId . "/" . "4-Th";
  1923. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingTh, 1);
  1924. ### Log file entry for debugging
  1925. Log3 $name, 5, $name. " : The following Service can be read and is writeable : " . $TempJsonId;
  1926. ### Add service to the list of writeable services
  1927. push (@KM200_WriteableServices, $TempJsonId);
  1928. ### Create new Service and write reading for fhem
  1929. $TempJsonId = $JsonId . "/" . "5-Fr";
  1930. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingFr, 1);
  1931. ### Log file entry for debugging
  1932. Log3 $name, 5, $name. " : The following Service can be read and is writeable : " . $TempJsonId;
  1933. ### Add service to the list of writeable services
  1934. push (@KM200_WriteableServices, $TempJsonId);
  1935. ### Create new Service and write reading for fhem
  1936. $TempJsonId = $JsonId . "/" . "6-Sa";
  1937. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingSa, 1);
  1938. ### Log file entry for debugging
  1939. Log3 $name, 5, $name. " : The following Service can be read and is writeable : " . $TempJsonId;
  1940. ### Add service to the list of writeable services
  1941. push (@KM200_WriteableServices, $TempJsonId);
  1942. ### Create new Service and write reading for fhem
  1943. $TempJsonId = $JsonId . "/" . "7-Su";
  1944. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingSu, 1);
  1945. ### Log file entry for debugging
  1946. Log3 $name, 5, $name. " : The following Service can be read and is writeable : " . $TempJsonId;
  1947. ### Add service to the list of writeable services
  1948. push (@KM200_WriteableServices, $TempJsonId);
  1949. }
  1950. ### Check whether the type is an errorlist
  1951. elsif ($json -> {type} eq "errorList")
  1952. {
  1953. my $JsonId = $json->{id};
  1954. my $JsonType = $json->{type};
  1955. ### Log entries for debugging purposes
  1956. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value found for : " .$Service;
  1957. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - id : " .$JsonId;
  1958. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - type : " .$JsonType;
  1959. ### Add service to the list of responding services
  1960. push (@KM200_RespondingServices, $Service);
  1961. ### Delete double entries in the list of responding services and sort in alphabetical order
  1962. my %FilteredKM200RespondingServices;
  1963. $FilteredKM200RespondingServices{$_}=0 for @KM200_RespondingServices;
  1964. @KM200_RespondingServices = (keys %FilteredKM200RespondingServices);
  1965. @KM200_RespondingServices = sort @KM200_RespondingServices;
  1966. ### Log file entry for debugging
  1967. my $LogMessage = " : The following Service can be read";
  1968. ### Check whether service is writeable and write name of service in array
  1969. if ($json->{writeable} == 1)
  1970. {
  1971. $LogMessage = $LogMessage . " and is writeable ";
  1972. push (@KM200_WriteableServices, $Service);
  1973. }
  1974. else
  1975. {
  1976. # Do nothing
  1977. $LogMessage = $LogMessage . " ";
  1978. }
  1979. ### Log file entry for debugging
  1980. $LogMessage = $LogMessage . " : " . $JsonId;
  1981. Log3 $name, 4, $name . $LogMessage;
  1982. ### Sort list by timestamps descending
  1983. my $TempServiceIndex = 0;
  1984. my @TempSortedErrorList = sort { $b->{t} cmp $a->{t} } @{ $json->{values} };
  1985. # my @TempSortedErrorList = @{ $json->{values} };
  1986. foreach my $item (@TempSortedErrorList)
  1987. {
  1988. ### Increment Service-Index
  1989. $TempServiceIndex++;
  1990. ### Create message string with fixed blocksize
  1991. my $TempTime = $item->{t};
  1992. if ($TempTime) {$TempTime =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(20-length($1)))/e;}
  1993. my $TempErrorCode = $item->{dcd};
  1994. $TempErrorCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(3 -length($1)))/e;
  1995. my $TempAddCode = $item->{ccd};
  1996. $TempAddCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(4 -length($1)))/e;
  1997. my $TempClassCode = $item->{cat};
  1998. $TempClassCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(2- length($1)))/e;
  1999. my $TempErrorMessage = "Time: " . $TempTime . "-ErrorCode: " . $TempErrorCode . " -AddCode: " . $TempAddCode . " -Category: " . $TempClassCode;
  2000. ### Create Service with Increment
  2001. my $TempServiceString = $Service . "/Error-" . (sprintf("%02d", $TempServiceIndex));
  2002. ### Write Reading
  2003. readingsSingleUpdate( $hash, $TempServiceString, $TempErrorMessage, 1);
  2004. ### Log file entry for debugging
  2005. Log3 $name, 5, $name. " : The following Service can be read : " .$TempServiceString;
  2006. }
  2007. }
  2008. ### Check whether the type is an refEnum which is indicating an empty parent directory
  2009. elsif ($json -> {type} eq "refEnum")
  2010. {
  2011. my $JsonId = $json->{id};
  2012. my $JsonType = $json->{type};
  2013. my @JsonReferences = $json->{references};
  2014. ### Log file entry for debugging
  2015. Log3 $name, 5, $name. " : The following Service is an empty parent directory : " . $JsonId;
  2016. ### For each item found in this empty parent directory
  2017. foreach my $item (@{ $json->{references} })
  2018. {
  2019. my $SearchWord = $item->{id};
  2020. ### If the Service found is listed as blocked service
  2021. if ((grep {$_ eq $SearchWord} @{$hash->{Secret}{KM200DONOTPOLL}}) == 1)
  2022. {
  2023. ### Do nothing
  2024. ### Log file entry for debugging
  2025. Log3 $name, 5, $name. "The following Service has been found but is blacklisted: " . $item->{id};
  2026. }
  2027. ### If the Service found is NOT listed as blocked service
  2028. else
  2029. {
  2030. ### Add service to the list of all known services
  2031. push (@{$hash ->{Secret}{KM200ALLSERVICES}}, $item->{id});
  2032. }
  2033. }
  2034. ### Sort the list of all services alphabetically
  2035. @{$hash ->{Secret}{KM200ALLSERVICES}} = sort @{$hash ->{Secret}{KM200ALLSERVICES}};
  2036. }
  2037. ### Check whether the type is a systeminfo
  2038. elsif ($json -> {type} eq "systeminfo")
  2039. {
  2040. my $JsonId = $json->{id};
  2041. my $JsonType = $json->{type};
  2042. my @JsonValues = $json->{values};
  2043. ### Log entries for debugging purposes
  2044. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value found for : " .$Service;
  2045. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - id : " .$JsonId;
  2046. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - type : " .$JsonType;
  2047. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value : " .@JsonValues;
  2048. ### Add service to the list of responding services
  2049. push (@KM200_RespondingServices, $Service);
  2050. ### Delete double entries in the list of responding services and sort in alphabetical order
  2051. my %FilteredKM200RespondingServices;
  2052. $FilteredKM200RespondingServices{$_}=0 for @KM200_RespondingServices;
  2053. @KM200_RespondingServices = (keys %FilteredKM200RespondingServices);
  2054. @KM200_RespondingServices = sort @KM200_RespondingServices;
  2055. ### Log file entry for debugging
  2056. Log3 $name, 4, $name . " : The following Service can be read : " .$JsonId;
  2057. ### Initialise ArrayCounter
  2058. my $ArrayCounter = 0;
  2059. foreach my $ArrayItem (@{ $json->{values} })
  2060. {
  2061. ### Incrementation of ArrayCounter
  2062. $ArrayCounter++;
  2063. ### Log file entry for debugging
  2064. Log3 $name, 5, $name . " : The ArrayItem is : " . $ArrayItem ;
  2065. Log3 $name, 5, $name . " : The keys ArrayItem is : " . (keys %{$ArrayItem}) ;
  2066. ### Get array from scalar
  2067. my %ArrayHash = %{$ArrayItem};
  2068. while( my( $SystemInfoHashKey, $SystemInfoHashValue ) = each %ArrayHash )
  2069. {
  2070. ### Log file entry for debugging
  2071. Log3 $name, 5, $name . " : The ArrayHashKey is : " . $SystemInfoHashKey;
  2072. Log3 $name, 5, $name . " : The ArrayHashValue is : " . $SystemInfoHashValue;
  2073. ### Create new Service and write reading for fhem
  2074. my $TempJsonId = $JsonId . "/" . sprintf ('%02d', $ArrayCounter) . "/" . $SystemInfoHashKey;
  2075. readingsSingleUpdate( $hash, $TempJsonId, $SystemInfoHashValue, 1);
  2076. ### Log file entry for debugging
  2077. Log3 $name, 5, $name . " : The following Service can be read : " . $TempJsonId;
  2078. }
  2079. }
  2080. }
  2081. ### Check whether the type is unknown
  2082. else
  2083. {
  2084. ### Log entries for debugging purposes
  2085. Log3 $name, 4, $name. " : km200_ParseHttpResponseInit - type unknown for : " .$Service;
  2086. }
  2087. }
  2088. ### Check whether the decoded content is empty and therefore NOT available
  2089. else
  2090. {
  2091. ### Log entries for debugging purposes
  2092. Log3 $name, 4, $name. " : km200_ParseHttpResponseInit - NOT available : ". $Service;
  2093. }
  2094. ### Log entries for debugging purposes
  2095. #Log3 $name, 5, $name. " : km200_ParseHttpResponseInit : response : " .$data;
  2096. Log3 $name, 5, $name . "______________________________________________________________________________________________________________________";
  2097. ### Get the size of the array
  2098. @KM200_InitServices = @{$hash ->{Secret}{KM200ALLSERVICES}};
  2099. $NumberInitServices = @KM200_InitServices;
  2100. ### If the list of KM200ALLSERVICES has not been finished yet
  2101. if ($ServiceCounterInit < ($NumberInitServices-1))
  2102. {
  2103. ++$ServiceCounterInit;
  2104. $hash->{temp}{ServiceCounterInit} = $ServiceCounterInit;
  2105. @{$hash->{Secret}{KM200RESPONDINGSERVICES}} = @KM200_RespondingServices;
  2106. @{$hash->{Secret}{KM200WRITEABLESERVICES}} = @KM200_WriteableServices;
  2107. km200_GetInitService($hash);
  2108. }
  2109. ### If the list of KM200ALLSERVICES is finished
  2110. else
  2111. {
  2112. my @KM200_DynServices = @KM200_RespondingServices;
  2113. ### Save arrays of services in hash
  2114. @{$hash->{Secret}{KM200RESPONDINGSERVICES}} = @KM200_RespondingServices;
  2115. @{$hash->{Secret}{KM200WRITEABLESERVICES}} = @KM200_WriteableServices;
  2116. @{$hash->{Secret}{KM200DYNSERVICES}} = @KM200_DynServices;
  2117. ### Reset flag for initialisation
  2118. $hash->{status}{FlagInitRequest} = false;
  2119. ###START###### Initiate the timer for continuous polling of dynamical values from KM200 ###################START####
  2120. InternalTimer(gettimeofday()+($hash->{INTERVALDYNVAL}), "km200_GetDynService", $hash, 1);
  2121. Log3 $name, 4, $name. " : km200 - Define: InternalTimer for dynamic values started with interval of: ".($hash->{INTERVALDYNVAL});
  2122. ####END####### Initiate the timer for continuous polling of dynamical values from KM200 ####################END#####
  2123. ### Reset fullResponse error message
  2124. readingsSingleUpdate( $hash, "fullResponse", "OK", 1);
  2125. ### Log file entry for debugging
  2126. Log3 $name, 5, $name. "Sounding and importing of services is completed";
  2127. ### Set status of km200 fhem module
  2128. $hash->{STATE} = "Standby";
  2129. ### Disable flag
  2130. $hash->{temp}{ServiceCounterInit} = false;
  2131. }
  2132. ### If the Initialisation process has been interuppted with an error message
  2133. if (ReadingsVal($name,"fullResponse",0) eq "ERROR")
  2134. {
  2135. ### Reset fullResponse error message
  2136. readingsSingleUpdate( $hash, "fullResponse", "Restarted after ERROR", 1);
  2137. ### Reset timer for init procedure and start over again until it works
  2138. InternalTimer(gettimeofday()+5, "km200_GetInitService", $hash, 1);
  2139. Log3 $name, 5, $name. " : km200 - Internal timer for Initialisation of services restarted after fullResponse - error.";
  2140. }
  2141. ### Clear up temporary variables
  2142. $hash->{temp}{decodedcontent} = "";
  2143. return;
  2144. }
  2145. ####END####### Subroutine to download complete initial data set from gateway ###################################END#####
  2146. ###START###### Subroutine obtaining dynamic services via HttpUtils ############################################START####
  2147. sub km200_GetDynService($)
  2148. {
  2149. my ($hash, $def) = @_;
  2150. my $km200_gateway_host = $hash->{URL};
  2151. my $name = $hash->{NAME};
  2152. $hash->{STATE} = "Polling";
  2153. my @KM200_DynServices = @{$hash->{Secret}{KM200DYNSERVICES}};
  2154. my $ServiceCounterDyn = $hash->{temp}{ServiceCounterDyn};
  2155. my $PollingTimeout = $hash->{POLLINGTIMEOUT};
  2156. ### Stop the current timer
  2157. RemoveInternalTimer($hash);
  2158. ### If at least one service to be polled is available
  2159. if (@KM200_DynServices != 0)
  2160. {
  2161. my $Service = $KM200_DynServices[$ServiceCounterDyn];
  2162. ### Log file entry for debugging
  2163. if ($ServiceCounterDyn == 0)
  2164. {
  2165. Log3 $name, 5, $name. "Starting download of dynamic services";
  2166. }
  2167. ### Log file entry for debugging
  2168. Log3 $name, 5, $name . " - km200_GetDynService - Polling : " . $Service;
  2169. my $url = "http://" . $km200_gateway_host . $Service;
  2170. my $param = {
  2171. url => $url,
  2172. timeout => $PollingTimeout,
  2173. hash => $hash,
  2174. method => "GET",
  2175. header => "agent: TeleHeater/2.2.3\r\nUser-Agent: TeleHeater/2.2.3\r\nAccept: application/json",
  2176. callback => \&km200_ParseHttpResponseDyn
  2177. };
  2178. ### Set Status Flag in order state running dynamic request
  2179. $hash->{status}{FlagDynRequest} = true;
  2180. ### Get data
  2181. HttpUtils_NonblockingGet($param);
  2182. }
  2183. ### If no service to be polled is available
  2184. else
  2185. {
  2186. Log3 $name, 5, $name . " : No dynamic values available to be read. Skipping download.";
  2187. }
  2188. }
  2189. ####END####### Subroutine get dynamic data value ###############################################################END#####
  2190. ###START###### Subroutine to download complete dynamic data set from gateway ##################################START####
  2191. # For all responding dynamic services read the respective values from gateway
  2192. sub km200_ParseHttpResponseDyn($)
  2193. {
  2194. my ($param, $err, $data) = @_;
  2195. my $hash = $param->{hash};
  2196. my $name = $hash ->{NAME};
  2197. my $ServiceCounterDyn = $hash ->{temp}{ServiceCounterDyn};
  2198. my @KM200_DynServices = @{$hash ->{Secret}{KM200DYNSERVICES}};
  2199. my $NumberDynServices = @KM200_DynServices;
  2200. my $Service = $KM200_DynServices[$ServiceCounterDyn];
  2201. my $type;
  2202. my $json ->{type} = "";
  2203. Log3 $name, 5, $name. " : Parsing response of dynamic service received for : " . $Service;
  2204. ### Reset Status Flag
  2205. $hash->{status}{FlagDynRequest} = false;
  2206. if($err ne "")
  2207. {
  2208. Log3 $name, 2, $name . " : ERROR: Service: ".$Service. ": No proper Communication with Gateway: " .$err;
  2209. readingsSingleUpdate($hash, "fullResponse", "ERROR", 1);
  2210. }
  2211. $hash->{temp}{decodedcontent} = $data;
  2212. my $decodedContent = km200_Decrypt($hash);
  2213. if ($decodedContent ne "")
  2214. {
  2215. eval
  2216. {
  2217. $json = decode_json(encode_utf8($decodedContent));
  2218. 1;
  2219. }
  2220. or do
  2221. {
  2222. Log3 $name, 5, $name. " - km200_parseHttpResponseDyn : Data cannot be parsed by JSON on km200 for http://" . $param->{url};
  2223. };
  2224. ### Check whether the type is a single value containing a string or float value
  2225. if(($json -> {type} eq "stringValue") || ($json -> {type} eq "floatValue"))
  2226. {
  2227. my $JsonId = $json->{id};
  2228. my $JsonType = $json->{type};
  2229. my $JsonValue = $json->{value};
  2230. ### Log entries for debugging purposes
  2231. Log3 $name, 4, $name. " : km200_parseHttpResponseDyn - value found for : " .$Service;
  2232. Log3 $name, 5, $name. " : km200_parseHttpResponseDyn - id : " .$JsonId;
  2233. Log3 $name, 5, $name. " : km200_parseHttpResponseDyn - type : " .$JsonType;
  2234. Log3 $name, 5, $name. " : km200_parseHttpResponseDyn - value : " .$JsonValue;
  2235. ### Log entries for debugging purposes
  2236. ### Save json-hash for DbLog-Split
  2237. $hash->{temp}{ServiceDbLogSplitHash} = $json;
  2238. ### Save json-hash for DbLog-Split
  2239. ### Write reading
  2240. readingsSingleUpdate( $hash, $JsonId, $JsonValue, 1);
  2241. ### Write reading
  2242. }
  2243. ### Check whether the type is an switchProgram
  2244. elsif ($json -> {type} eq "switchProgram")
  2245. {
  2246. my $JsonId = $json->{id};
  2247. my $JsonType = $json->{type};
  2248. ### Log entries for debugging purposes
  2249. Log3 $name, 4, $name. " : km200_parseHttpResponseDyn - value found for : " .$Service;
  2250. Log3 $name, 5, $name. " : km200_parseHttpResponseDyn - id : " .$JsonId;
  2251. Log3 $name, 5, $name. " : km200_parseHttpResponseDyn - type : " .$JsonType;
  2252. ### Set up variables
  2253. my $TempJsonId = "";
  2254. my $TempReadingMo = "";
  2255. my $TempReadingTu = "";
  2256. my $TempReadingWe = "";
  2257. my $TempReadingTh = "";
  2258. my $TempReadingFr = "";
  2259. my $TempReadingSa = "";
  2260. my $TempReadingSu = "";
  2261. foreach my $item (@{ $json->{switchPoints} })
  2262. {
  2263. ### Create string for time and switchpoint in fixed format and write part of Reading String
  2264. my $time = $item->{time};
  2265. my $temptime = $time / 60;
  2266. my $temptimeHH = int($temptime);
  2267. my $temptimeMM = ($time - ($temptimeHH * 60));
  2268. $temptimeHH = sprintf ('%02d', $temptimeHH);
  2269. $temptimeMM = sprintf ('%02d', $temptimeMM);
  2270. $temptime = $temptimeHH . $temptimeMM;
  2271. my $tempsetpoint = $item->{setpoint};
  2272. $tempsetpoint =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(8-length($1)))/e;
  2273. my $TempReading = $temptime . " " . $tempsetpoint;
  2274. ### Create ValueString for this day
  2275. if ($item->{dayOfWeek} eq "Mo")
  2276. {
  2277. ### If it is the first entry for this day
  2278. if ($TempReadingMo eq "")
  2279. {
  2280. ### Write the first entry
  2281. $TempReadingMo = $TempReading;
  2282. }
  2283. ### If it is NOT the first entry for this day
  2284. else
  2285. {
  2286. ### Add the next entry
  2287. $TempReadingMo = $TempReadingMo . " " . $TempReading;
  2288. }
  2289. }
  2290. elsif ($item->{dayOfWeek} eq "Tu")
  2291. {
  2292. ### If it is the first entry for this day
  2293. if ($TempReadingTu eq "")
  2294. {
  2295. ### Write the first entry
  2296. $TempReadingTu = $TempReading;
  2297. }
  2298. ### If it is NOT the first entry for this day
  2299. else
  2300. {
  2301. ### Add the next entry
  2302. $TempReadingTu = $TempReadingTu . " " . $TempReading;
  2303. }
  2304. }
  2305. elsif ($item->{dayOfWeek} eq "We")
  2306. {
  2307. ### If it is the first entry for this day
  2308. if ($TempReadingWe eq "")
  2309. {
  2310. ### Write the first entry
  2311. $TempReadingWe = $TempReading;
  2312. }
  2313. ### If it is NOT the first entry for this day
  2314. else
  2315. {
  2316. ### Add the next entry
  2317. $TempReadingWe = $TempReadingWe . " " . $TempReading;
  2318. }
  2319. }
  2320. elsif ($item->{dayOfWeek} eq "Th")
  2321. {
  2322. ### If it is the first entry for this day
  2323. if ($TempReadingTh eq "")
  2324. {
  2325. ### Write the first entry
  2326. $TempReadingTh = $TempReading;
  2327. }
  2328. ### If it is NOT the first entry for this day
  2329. else
  2330. {
  2331. ### Add the next entry
  2332. $TempReadingTh = $TempReadingTh . " " . $TempReading;
  2333. }
  2334. }
  2335. elsif ($item->{dayOfWeek} eq "Fr")
  2336. {
  2337. ### If it is the first entry for this day
  2338. if ($TempReadingFr eq "")
  2339. {
  2340. ### Write the first entry
  2341. $TempReadingFr = $TempReading;
  2342. }
  2343. ### If it is NOT the first entry for this day
  2344. else
  2345. {
  2346. ### Add the next entry
  2347. $TempReadingFr = $TempReadingFr . " " . $TempReading;
  2348. }
  2349. }
  2350. elsif ($item->{dayOfWeek} eq "Sa")
  2351. {
  2352. ### If it is the first entry for this day
  2353. if ($TempReadingSa eq "")
  2354. {
  2355. ### Write the first entry
  2356. $TempReadingSa = $TempReading;
  2357. }
  2358. ### If it is NOT the first entry for this day
  2359. else
  2360. {
  2361. ### Add the next entry
  2362. $TempReadingSa = $TempReadingSa . " " . $TempReading;
  2363. }
  2364. }
  2365. elsif ($item->{dayOfWeek} eq "Su")
  2366. {
  2367. ### If it is the first entry for this day
  2368. if ($TempReadingSu eq "")
  2369. {
  2370. ### Write the first entry
  2371. $TempReadingSu = $TempReading;
  2372. }
  2373. ### If it is NOT the first entry for this day
  2374. else
  2375. {
  2376. ### Add the next entry
  2377. $TempReadingSu = $TempReadingSu . " " . $TempReading;
  2378. }
  2379. }
  2380. else
  2381. {
  2382. Log3 $name, 5, $name. "dayOfWeek of unknow day: " . $item->{dayOfWeek};
  2383. }
  2384. }
  2385. ### Create new Service and write reading for fhem
  2386. $TempJsonId = $JsonId . "/" . "1-Mo";
  2387. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingMo, 1);
  2388. ### Create new Service and write reading for fhem
  2389. $TempJsonId = $JsonId . "/" . "2-Tu";
  2390. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingTu, 1);
  2391. ### Create new Service and write reading for fhem
  2392. $TempJsonId = $JsonId . "/" . "3-We";
  2393. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingWe, 1);
  2394. ### Create new Service and write reading for fhem
  2395. $TempJsonId = $JsonId . "/" . "4-Th";
  2396. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingTh, 1);
  2397. ### Create new Service and write reading for fhem
  2398. $TempJsonId = $JsonId . "/" . "5-Fr";
  2399. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingFr, 1);
  2400. ### Create new Service and write reading for fhem
  2401. $TempJsonId = $JsonId . "/" . "6-Sa";
  2402. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingSa, 1);
  2403. ### Create new Service and write reading for fhem
  2404. $TempJsonId = $JsonId . "/" . "7-Su";
  2405. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingSu, 1);
  2406. }
  2407. ### Check whether the type is an errorlist
  2408. elsif ($json -> {type} eq "errorList")
  2409. {
  2410. my $JsonId = $json->{id};
  2411. my $JsonType = $json->{type};
  2412. my $TempServiceIndex = 0;
  2413. ### Sort list by timestamps descending
  2414. my @TempSortedErrorList = sort { $b->{t} cmp $a->{t} } @{ $json->{values} };
  2415. # my @TempSortedErrorList = @{ $json->{values} } ;
  2416. ### For every notification do
  2417. foreach my $item (@TempSortedErrorList)
  2418. {
  2419. ### Increment Service-Index
  2420. $TempServiceIndex++;
  2421. ### Create message string with fixed blocksize
  2422. my $TempTime = $item->{t};
  2423. if ($TempTime) {$TempTime =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(20-length($1)))/e;}
  2424. my $TempErrorCode = $item->{dcd};
  2425. $TempErrorCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(3 -length($1)))/e;
  2426. my $TempAddCode = $item->{ccd};
  2427. $TempAddCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(4 -length($1)))/e;
  2428. my $TempClassCode = $item->{cat};
  2429. $TempClassCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(2- length($1)))/e;
  2430. my $TempErrorMessage = "Time: " . $TempTime . "-ErrorCode: " . $TempErrorCode . " -AddCode: " . $TempAddCode . " -Category: " . $TempClassCode;
  2431. ### Create Service with Increment and leading 0
  2432. my $TempServiceString = $Service . "/Error-" . (sprintf("%02d", $TempServiceIndex));
  2433. ### Write Reading
  2434. readingsSingleUpdate( $hash, $TempServiceString, $TempErrorMessage, 1);
  2435. }
  2436. }
  2437. ### Check whether the type is a systeminfo
  2438. elsif ($json -> {type} eq "systeminfo")
  2439. {
  2440. my $JsonId = $json->{id};
  2441. my $JsonType = $json->{type};
  2442. my @JsonValues = $json->{values};
  2443. ### Log entries for debugging purposes
  2444. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value found for : " .$Service;
  2445. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - id : " .$JsonId;
  2446. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - type : " .$JsonType;
  2447. ### Initialise ArrayCounter
  2448. my $ArrayCounter = 0;
  2449. foreach my $ArrayItem (@{ $json->{values} })
  2450. {
  2451. ### Incrementation of ArrayCounter
  2452. $ArrayCounter++;
  2453. ### Get array from scalar
  2454. my %ArrayHash = %{$ArrayItem};
  2455. while( my( $SystemInfoHashKey, $SystemInfoHashValue ) = each %ArrayHash )
  2456. {
  2457. ### Create new Service and write reading for fhem
  2458. my $TempJsonId = $JsonId . "/" . sprintf ('%02d', $ArrayCounter) . "/" . $SystemInfoHashKey;
  2459. readingsSingleUpdate( $hash, $TempJsonId, $SystemInfoHashValue, 1);
  2460. }
  2461. }
  2462. }
  2463. ### Check whether the type is unknown
  2464. else
  2465. {
  2466. ### Log entries for debugging purposes
  2467. Log3 $name, 4, $name. " : km200_parseHttpResponseDyn - type unknown for : " .$Service;
  2468. }
  2469. }
  2470. else
  2471. {
  2472. Log3 $name, 5, $name. " : km200_parseHttpResponseDyn - Data not available on km200 for http://" . $param->{url};
  2473. }
  2474. Log3 $name, 5, $name . "______________________________________________________________________________________________________________________";
  2475. ### Clear up temporary variables
  2476. $hash->{temp}{decodedcontent} = "";
  2477. $hash->{temp}{service} = "";
  2478. ### Clear up temporary variables
  2479. ### If list is not complete yet
  2480. if ($ServiceCounterDyn < ($NumberDynServices-1))
  2481. {
  2482. ++$ServiceCounterDyn;
  2483. $hash->{temp}{ServiceCounterDyn} = $ServiceCounterDyn;
  2484. km200_GetDynService($hash);
  2485. }
  2486. ### If list is complete
  2487. else
  2488. {
  2489. $hash->{STATE} = "Standby";
  2490. $hash->{temp}{ServiceCounterDyn} = 0;
  2491. ###START###### Re-Start the timer #####################################START####
  2492. InternalTimer(gettimeofday()+$hash->{INTERVALDYNVAL}, "km200_GetDynService", $hash, 1);
  2493. ####END####### Re-Start the timer ######################################END#####
  2494. ### Update fullResponse Reading
  2495. readingsSingleUpdate( $hash, "fullResponse", "OK", 1);
  2496. $hash->{status}{FlagDynRequest} = false;
  2497. Log3 $name, 5, $name . "______________________________________________________________________________________________________________________";
  2498. }
  2499. return undef;
  2500. }
  2501. ####END####### Subroutine to download complete dynamic data set from gateway ###################################END#####
  2502. 1;
  2503. ###START###### Description for fhem commandref ################################################################START####
  2504. =pod
  2505. =item device
  2506. =item summary Connects fhem to Buderus KM300, KM200, KM100, KM50
  2507. =item summary_DE Verbindet fhem mit Buderus KM300, KM200, KM100, KM50
  2508. =begin html
  2509. <a name="km200"></a>
  2510. <h3>KM200</h3>
  2511. <ul>
  2512. <table>
  2513. <tr>
  2514. <td>
  2515. The Buderus <a href="https://www.buderus.de/de/produkte/catalogue/alle-produkte/7719_Gateway-Logamatic-web-KM200-KM100-KM50">KM200, KM100 or KM50 (hereafter described as KMxxx)</a> is a communication device to establish a connection between the Buderus central heating control unit and the internet.<BR>
  2516. It has been designed in order to allow the inhabitants accessing their heating system via his Buderus App <a href="http://www.buderus.de/Online_Anwendungen/Apps/fuer_den_Endverbrauch
  2517. er/EasyControl-4848514.html"> EasyControl</a>.<BR>
  2518. Furthermore it allows the maintenance companies to access the central heating control system to read and change settings.<BR>
  2519. The km200 fhem-module enables read/write access to these parameters.<BR>
  2520. <BR>
  2521. In order to use the KMxxx with fhem, you must define the private password with the Buderus App <a href="http://www.buderus.de/Online_Anwendungen/Apps/fuer_den_Endverbraucher/EasyControl-4848514.html"> EasyControl</a> first.<BR>
  2522. <BR>
  2523. <b><u>Remark:</u></b><BR>
  2524. Despite the instruction of the Buderus KMxxx Installation guide, the ports 5222 and 5223 should not be opened and allow access to the KMxxx module from outside.<BR>
  2525. You should configure (or leave) your internet router with the respective settings.<BR>
  2526. If you want to read or change settings on the heating system, you should access the central heating control system via your fhem system only.<BR>
  2527. <BR>
  2528. As soon the module has been defined within the fhem.cfg, the module is trying to obtain all known/possible services. <BR>
  2529. After this initial contact, the module differs between a set of continuous (dynamically) changing values (e.g.: temperatures) and not changing static values (e.g.: Firmware version).<BR>
  2530. This two different set of values can be bound to an individual polling interval. Refer to <a href="#KM200Attr">Attributes</a><BR>
  2531. <BR>
  2532. </td>
  2533. </tr>
  2534. </table>
  2535. <table>
  2536. <tr><td><a name="KM200define"></a><b>Define</b></td></tr>
  2537. </table>
  2538. <table><tr><td><ul><code>define &lt;name&gt; km200 &lt;IPv4-address&gt; &lt;GatewayPassword&gt; &lt;PrivatePassword&gt;</code></ul></td></tr></table>
  2539. <ul><ul>
  2540. <table>
  2541. <tr><td><code>&lt;name&gt;</code> : </td><td>The name of the device. Recommendation: "myKm200".</td></tr>
  2542. <tr><td><code>&lt;IPv4-address&gt;</code> : </td><td>A valid IPv4 address of the KMxxx. You might look into your router which DHCP address has been given to the KMxxx.</td></tr>
  2543. <tr><td><code>&lt;GatewayPassword&gt;</code> : </td><td>The gateway password which is provided on the type sign of the KMxxx.</td></tr>
  2544. <tr><td><code>&lt;PrivatePassword&gt;</code> : </td><td>The private password which has been defined by the user via <a href="http://www.buderus.de/Online_Anwendungen/Apps/fuer_den_Endverbraucher/EasyControl-4848514.html"> EasyControl</a>.</td></tr>
  2545. </table>
  2546. </ul></ul>
  2547. <BR>
  2548. <table>
  2549. <tr><td><a name="KM200Set"></a><b>Set</b></td></tr>
  2550. <tr><td>
  2551. <ul>
  2552. The set function is able to change a value of a service which has the "writeable" - tag within the KMxxx service structure.<BR>
  2553. Most of those values have an additional list of allowed values which are the only ones to be set.<BR>
  2554. Other floatable type values can be changed only within their range of minimum and maximum value.<BR>
  2555. </ul>
  2556. </td></tr>
  2557. </table>
  2558. <table><tr><td><ul><code>set &lt;service&gt; &lt;value&gt;</code></ul></td></tr></table>
  2559. <ul><ul>
  2560. <table>
  2561. <tr><td><code>&lt;service&gt;</code> : </td><td>The name of the service which value shall be set. E.g.: "<code>/heatingCircuits/hc1/operationMode</code>"<BR></td></tr>
  2562. <tr><td><code>&lt;value&gt;</code> : </td><td>A valid value for this service.<BR></td></tr>
  2563. </table>
  2564. </ul></ul>
  2565. <BR>
  2566. <table>
  2567. <tr><td><a name="KM200Get"></a><b>Get</b></td></tr>
  2568. <tr><td>
  2569. <ul>
  2570. The get function is able to obtain a value of a service within the KMxxx service structure.<BR>
  2571. The additional list of allowed values or their range of minimum and maximum value will not be handed back.<BR>
  2572. </ul>
  2573. </td></tr>
  2574. </table>
  2575. <table><tr><td><ul><code>get &lt;service&gt; &lt;option&gt;</code></ul></td></tr></table>
  2576. <ul><ul>
  2577. <table>
  2578. <tr>
  2579. <td><code>&lt;service&gt;</code> : </td><td>The name of the service which value shall be obtained. E.g.: "<code>/heatingCircuits/hc1/operationMode</code>"<BR>
  2580. &nbsp;&nbsp;It returns only the value but not the unit or the range or list of allowed values possible.<BR>
  2581. </td>
  2582. </tr>
  2583. </table>
  2584. </ul></ul>
  2585. <ul><ul>
  2586. <table>
  2587. <tr>
  2588. <td><code>&lt;option&gt;</code> : </td><td>The optional Argument for the result of the get-command e.g.: "<code>json</code>"<BR>
  2589. &nbsp;&nbsp;The following options are available:<BR>
  2590. &nbsp;&nbsp;json - Returns the raw json-answer from the KMxxx as string.
  2591. </td>
  2592. </tr>
  2593. </table>
  2594. </ul></ul>
  2595. <BR>
  2596. <table>
  2597. <tr><td><a name="KM200Attr"></a><b>Attributes</b></td></tr>
  2598. <tr><td>
  2599. <ul>
  2600. The following user attributes can be used with the km200 module in addition to the global ones e.g. <a href="#room">room</a>.<BR>
  2601. </ul>
  2602. </td></tr>
  2603. </table>
  2604. <ul><ul>
  2605. <table>
  2606. <tr>
  2607. <td>
  2608. <tr><td><li><code>IntervalDynVal</code> : </li></td><td>A valid polling interval for the dynamically changing values of the KMxxx. The value must be >=20s to allow the km200 module to perform a full polling procedure. <BR>
  2609. The default value is 300s.<BR>
  2610. </td></tr>
  2611. </td>
  2612. </tr>
  2613. </table>
  2614. </ul></ul>
  2615. <ul><ul>
  2616. <table>
  2617. <tr>
  2618. <td>
  2619. <tr><td><li><code>PollingTimeout</code> : </li></td><td>A valid time in order to allow the module to wait for a response of the KMxxx. Usually this value does not need to be changed but might in case of slow network or slow response.<BR>
  2620. The default and minimum value is 5s.<BR>
  2621. </td></tr>
  2622. </td>
  2623. </tr>
  2624. </table>
  2625. </ul></ul>
  2626. <ul><ul>
  2627. <table>
  2628. <tr>
  2629. <td>
  2630. <tr><td><li><code>DoNotPoll</code> : </li></td><td>A list of services separated by blanks which shall not be downloaded due to repeatable crashes or irrelevant values.<BR>
  2631. The list can be filled with the name of the top - hierarchy service, which means everything below that service will also be ignored.<BR>
  2632. The default value (empty) therefore nothing will be ignored.<BR>
  2633. </td></tr>
  2634. </td>
  2635. </tr>
  2636. </table>
  2637. </ul></ul>
  2638. <ul><ul>
  2639. <table>
  2640. <tr>
  2641. <td>
  2642. <tr><td><li><code>ReadBackDelay</code> : </li></td><td>A valid time in milliseconds [ms] for the delay between writing and re-reading of values after using the "set" - command. The value must be >=0ms.<BR>
  2643. The default value is 100 = 100ms = 0,1s.<BR>
  2644. </td></tr>
  2645. </td>
  2646. </tr>
  2647. </table>
  2648. </ul></ul>
  2649. <ul><ul>
  2650. <table>
  2651. <tr>
  2652. <td>
  2653. <tr><td><li><code>disable</code> : </li></td><td>Stops the device from further pollings and deletes the existing readings.<BR>
  2654. The default value is 0 = activated<BR>
  2655. </td></tr>
  2656. </td>
  2657. </tr>
  2658. </table>
  2659. </ul></ul>
  2660. </ul>
  2661. =end html
  2662. =begin html_DE
  2663. <a name="km200"></a>
  2664. <h3>KM200</h3>
  2665. <ul>
  2666. <table>
  2667. <tr>
  2668. <td>
  2669. Das Buderus <a href="https://www.buderus.de/de/produkte/catalogue/alle-produkte/7719_Gateway-Logamatic-web-KM200-KM100-KM50">KM200, KM100 or KM50 (ab hier als KMxxx beschrieben)</a> ist eine Schnittstelle zwischen der Buderus Zentralheizungssteuerung un dem Internet.<BR>
  2670. Es wurde entwickelt um den Bewohnern den Zugang zu Ihrem Heizungssystem durch die Buderus App <a href="http://www.buderus.de/Online_Anwendungen/Apps/fuer_den_Endverbraucher/EasyControl-4848514.html"> EasyControl zu erlauben.</a>.<BR>
  2671. Dar&uuml;ber hinaus erlaubt es nach vorheriger Freigabe dem Heizungs- bzw. Wartungsbetrieb die Heizungsanlage von aussen zu warten und Werte zu ver&auml;ndern.<BR>
  2672. Das km200 fhem-Modul erlaubt den Lese-/Schreibzugriff dieser Parameter durch fhem.<BR>
  2673. <BR>
  2674. Um das KMxxx Ger&auml;t mit fhem nutzen zu k&ouml;nnen, mu&szlig; zun&auml;chst ein privates Passwort mit der Buderus Buderus App <a href="http://www.buderus.de/Online_Anwendungen/Apps/fuer_den_Endverbraucher/EasyControl-4848514.html"> EasyControl</a> - App gesetzt werden.<BR>
  2675. <BR>
  2676. <b><u>Anmerkung:</u></b><BR>
  2677. Unabh&auml;ngig der Installationsanleitung des Buderus KMxxx Ger&auml;ts, sollten die Ports 5222 und 5223 am Router geschlossen bleiben um keinen Zugriff von au&szlig;en auf das Ger&auml;t zu erlauben.<BR>
  2678. Der Router sollte entsprechend Konfiguriert bzw. so belassen werden.<BR>
  2679. Wenn der Lese-/Schreibzugriff von aussen gew&uuml;nscht ist, so sollte man ausschlie&szlig;lich &uuml;ber das fhem-System auf die Zentralheizung zugreifen.<BR>
  2680. <BR>
  2681. Sobald das Modul in der fhem.cfg definiert ist, wird das Modul versuchen alle bekannten Services abzuklopfen ob diese in der angeschlossenen Konstellation &uuml;berhaupt vorhanden sind.<BR>
  2682. Nach diesem Initial-Kontakt unterscheidet das Modul zwisachen einem Satz an Services die sich st&auml;ndig (dynamisch) &auml;ndern (z.B.: Vorlauftemperatur) sowie sich nicht st&auml;ndig (statisch) &auml;ndernden Werten (z.B.: Firmware Version).<BR>
  2683. Diese beiden S&auml;tze an Services k&ouml;nnen mir einem individuellen Abfrageintervall versehen werden. Siehe <a href="#KM200Attr">Attributes</a><BR>
  2684. <BR>
  2685. </td>
  2686. </tr>
  2687. </table>
  2688. <table>
  2689. <tr><td><a name="KM200define"></a><b>Define</b></td></tr>
  2690. </table>
  2691. <table><tr><td><ul><code>define &lt;name&gt; km200 &lt;IPv4-address&gt; &lt;GatewayPassword&gt; &lt;PrivatePassword&gt;</code></ul></td></tr></table>
  2692. <ul><ul>
  2693. <table>
  2694. <tr><td><code>&lt;name&gt;</code> : </td><td>Der Name des Ger&auml;tes. Empfehlung: "myKm200".</td></tr>
  2695. <tr><td><code>&lt;IPv4-address&gt;</code> : </td><td>Eine g&uuml;ltige IPv4 Adresse des KM200. Eventuell im Router nachschauen welche DHCP - Addresse dem KM200/KM50 vergeben wurde.</td></tr>
  2696. <tr><td><code>&lt;GatewayPassword&gt;</code> : </td><td>Das gateway Passwort, welches auf dem Typenschild des KM200/KM50 zu finden ist.</td></tr>
  2697. <tr><td><code>&lt;PrivatePassword&gt;</code> : </td><td>Das private Passwort, welches durch den User mit Hilfe der <a href="http://www.buderus.de/Online_Anwendungen/Apps/fuer_den_Endverbraucher/EasyControl-4848514.html"> EasyControl</a> - App vergeben wurde.</td></tr>
  2698. </table>
  2699. </ul></ul>
  2700. <BR>
  2701. <table>
  2702. <tr><td><a name="KM200Set"></a><b>Set</b></td></tr>
  2703. <tr><td>
  2704. <ul>
  2705. Die set Funktion &auml;ndert die Werte der Services welche das Flag "schreibbar" innerhalb der KMxxx Service Struktur besitzen.<BR>
  2706. Die meisten dieser beschreibbaren Werte haben eine exklusive Liste von m&ouml;glichen Werten innerhalb dessen sich der neue Wert bewegen muss.<BR>
  2707. Andere Flie&szlig;komma Werte haben einen maximum und minumum Wert, in dessen sich der neue Wert bewegen mu&szlig;.<BR>
  2708. </ul>
  2709. </td></tr>
  2710. </table>
  2711. <table><tr><td><ul><code>set &lt;service&gt; &lt;value&gt;</code></ul></td></tr></table>
  2712. <ul><ul>
  2713. <table>
  2714. <tr><td><code>&lt;service&gt;</code> : </td><td>Der Name des Service welcher gesetzt werden soll. Z.B.: "<code>/heatingCircuits/hc1/operationMode</code>"<BR></td></tr>
  2715. <tr><td><code>&lt;value&gt;</code> : </td><td>Ein g&uuml;ltiger Wert f&uuml;r diesen Service.<BR></td></tr>
  2716. </table>
  2717. </ul></ul>
  2718. <BR>
  2719. <table>
  2720. <tr><td><a name="KM200Get"></a><b>Get</b></td></tr>
  2721. <tr><td>
  2722. <ul>
  2723. Die get-Funktion ist in der Lage einen Wert eines Service innerhalb der KMxxx Service Struktur auszulesen.<BR>
  2724. Die zus&auml;tzliche Liste von erlaubten Werten oder der Wertebereich zwischen Minimum und Maximum wird nicht zur&uuml;ck gegeben.<BR>
  2725. </ul>
  2726. </td></tr>
  2727. </table>
  2728. <table><tr><td><ul><code>get &lt;service&gt; &lt;option&gt;</code></ul></td></tr></table>
  2729. <ul><ul>
  2730. <table>
  2731. <tr>
  2732. <td><code>&lt;service&gt;</code> : </td><td>Der Name des Service welcher ausgelesen werden soll. Z.B.: "<code>/heatingCircuits/hc1/operationMode</code>"<BR>
  2733. &nbsp;&nbsp;Es gibt nur den Wert, aber nicht die Werteliste oder den m&ouml;glichen Wertebereich zur&uuml;ck.<BR>
  2734. </td>
  2735. </tr>
  2736. </table>
  2737. </ul></ul>
  2738. <ul><ul>
  2739. <table>
  2740. <tr>
  2741. <td><code>&lt;option&gt;</code> : </td><td>Das optionelle Argument f&uuml;r Ausgabe des get-Befehls Z.B.: "<code>json</code>"<BR>
  2742. &nbsp;&nbsp;Folgende Optionen sind verf&uuml;gbar:<BR>
  2743. &nbsp;&nbsp;json - Gibt anstelle des Wertes, die gesamte Json Antwort des KMxxx als String zur&uuml;ck
  2744. </td>
  2745. </tr>
  2746. </table>
  2747. </ul></ul>
  2748. <BR>
  2749. <table>
  2750. <tr><td><a name="KM200Attr"></a><b>Attributes</b></td></tr>
  2751. <tr><td>
  2752. <ul>
  2753. Die folgenden Modul-spezifischen Attribute k&ouml;nnen neben den bekannten globalen Attributen gesetzt werden wie z.B.: <a href="#room">room</a>.<BR>
  2754. </ul>
  2755. </td></tr>
  2756. </table>
  2757. <ul><ul>
  2758. <table>
  2759. <tr>
  2760. <td>
  2761. <tr><td><li><code>IntervalDynVal</code> : </li></td><td>Ein g&uuml;ltiges Abfrageintervall f&uuml;r die sich st&auml;ndig ver&auml;ndernden - dynamischen Werte der KMxxx Services. Der Wert muss gr&ouml;&szlig;er gleich >=20s sein um dem Modul gen&uuml;gend Zeit einzur&auml;umen eine volle Abfrage auszuf&uuml;hren bevor die n&auml;chste Abfrage startet.<BR>
  2762. Der Default-Wert ist 300s.<BR>
  2763. </td></tr>
  2764. </td>
  2765. </tr>
  2766. </table>
  2767. </ul></ul>
  2768. <ul><ul>
  2769. <table>
  2770. <tr>
  2771. <td>
  2772. <tr><td><li><code>PollingTimeout</code> : </li></td><td>Ein g&uuml;ltiger Zeitwert um dem KMxxx gen&uuml;gend Zeit zur Antwort einzelner Werte einzur&auml;umen. Normalerweise braucht dieser Wert nicht ver&auml;ndert werden, muss jedoch im Falle eines langsamen Netzwerks erh&ouml;ht werden<BR>
  2773. Der Default-Wert ist 5s.<BR>
  2774. </td></tr>
  2775. </td>
  2776. </tr>
  2777. </table>
  2778. </ul></ul>
  2779. <ul><ul>
  2780. <table>
  2781. <tr>
  2782. <td>
  2783. <tr><td><li><code>DoNotPoll</code> : </li></td><td>Eine durch Leerzeichen (Blank) getrennte Liste von Services welche von der Abfrage aufgrund irrelevanter Werte oder fhem - Abst&uuml;rzen ausgenommen werden sollen.<BR>
  2784. Die Liste kann auch Hierarchien von services enthalten. Dies bedeutet, das alle Services unterhalb dieses Services ebenfalls gel&ouml;scht werden.<BR>
  2785. Der Default Wert ist (empty) somit werden alle bekannten Services abgefragt.<BR>
  2786. </td></tr>
  2787. </td>
  2788. </tr>
  2789. </table>
  2790. </ul></ul>
  2791. <ul><ul>
  2792. <table>
  2793. <tr>
  2794. <td>
  2795. <tr><td><li><code>ReadBackDelay</code> : </li></td><td>Ein g&uuml;ltiger Zeitwert in Mllisekunden [ms] f&uuml;r die Pause zwischen schreiben und zur&uuml;cklesen des Wertes durch den "set" - Befehl. Der Wert muss >=0ms sein.<BR>
  2796. Der Default-Wert ist 100 = 100ms = 0,1s.<BR>
  2797. </td></tr>
  2798. </td>
  2799. </tr>
  2800. </table>
  2801. </ul></ul>
  2802. <ul><ul>
  2803. <table>
  2804. <tr>
  2805. <td>
  2806. <tr><td><li><code>disable</code> : </li></td><td>Deaktiviert das Device und l&ouml;scht alle bestehenden Readings.<BR>
  2807. Der Default-Wert ist 0 = aktiviert<BR>
  2808. </td></tr>
  2809. </td>
  2810. </tr>
  2811. </table>
  2812. </ul></ul>
  2813. </ul>
  2814. =end html_DE