73_km200.pm 115 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298
  1. # $Id: 73_km200.pm 12391 2016-10-21 07:02:31Z sailor-fhem $
  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} <=> $a->{t} } @{ $json->{values} };
  1506. ### For every notification do
  1507. foreach my $item (@TempSortedErrorList)
  1508. {
  1509. ### Create message string with fixed blocksize
  1510. my $TempTime = $item->{t};
  1511. $TempTime =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(20-length($1)))/e;
  1512. my $TempErrorCode = $item->{dcd};
  1513. $TempErrorCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(3 -length($1)))/e;
  1514. my $TempAddCode = $item->{ccd};
  1515. $TempAddCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(4 -length($1)))/e;
  1516. my $TempClassCode = $item->{cat};
  1517. $TempClassCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(2- length($1)))/e;
  1518. my $TempErrorMessage = "Time: " . $TempTime . "-ErrorCode: " . $TempErrorCode . " -AddCode: " . $TempAddCode . " -Category: " . $TempClassCode;
  1519. ### Create List
  1520. $TempErrorList = $TempErrorList . $TempErrorMessage . "\n";
  1521. }
  1522. ### Save raw Json string
  1523. $hash->{temp}{JsonRaw} = $decodedContent;
  1524. ### Save errorList
  1525. $json->{value} = $TempErrorList;
  1526. return $json;
  1527. }
  1528. ### Check whether the type is an refEnum which is indicating an empty parent directory
  1529. elsif ($json -> {type} eq "refEnum")
  1530. {
  1531. ### Initialise Return Message
  1532. my $ReturnMessage = "";
  1533. ### For each item found in this empty parent directory
  1534. foreach my $item (@{ $json->{references} })
  1535. {
  1536. ### If it is the first item in the list
  1537. if ($ReturnMessage eq "")
  1538. {
  1539. $ReturnMessage = $item->{id};
  1540. }
  1541. ### If it is not the first item in the list
  1542. else
  1543. {
  1544. $ReturnMessage = $ReturnMessage . "\n" . $item->{id};
  1545. }
  1546. }
  1547. ### Return list of available directories
  1548. $json->{value} = $ReturnMessage;
  1549. ### Save raw Json string
  1550. $hash->{temp}{JsonRaw} = $decodedContent;
  1551. return $json;
  1552. }
  1553. ### Check whether the type is a systeminfo
  1554. elsif ($json -> {type} eq "systeminfo")
  1555. {
  1556. my $JsonId = $json->{id};
  1557. my $JsonType = $json->{type};
  1558. my @JsonValues = $json->{values};
  1559. ### Log entries for debugging purposes
  1560. Log3 $name, 4, $name. " : km200_GetSingleService - value found for : " .$Service;
  1561. Log3 $name, 5, $name. " : km200_GetSingleService - id : " .$JsonId;
  1562. Log3 $name, 5, $name. " : km200_GetSingleService - type : " .$JsonType;
  1563. ### Initialise Return Message
  1564. my $ReturnMessage = "";
  1565. ### Initialise ArrayCounter
  1566. my $ArrayCounter = 0;
  1567. foreach my $ArrayItem (@{ $json->{values} })
  1568. {
  1569. ### Incrementation of ArrayCounter
  1570. $ArrayCounter++;
  1571. ### Get array from scalar
  1572. my %ArrayHash = %{$ArrayItem};
  1573. while( my( $SystemInfoHashKey, $SystemInfoHashValue ) = each %ArrayHash )
  1574. {
  1575. ### Create new Service and write reading for fhem
  1576. my $TempJsonId = $JsonId . "/" . sprintf ('%02d', $ArrayCounter) . "/" . $SystemInfoHashKey;
  1577. readingsSingleUpdate( $hash, $TempJsonId, $SystemInfoHashValue, 1);
  1578. ### If it is the first item in the list
  1579. if ($ReturnMessage eq "")
  1580. {
  1581. $ReturnMessage = $TempJsonId . " = " . $SystemInfoHashValue;
  1582. }
  1583. ### If it is not the first item in the list
  1584. else
  1585. {
  1586. $ReturnMessage = $ReturnMessage . "\n" . $TempJsonId . " = " . $SystemInfoHashValue;
  1587. }
  1588. }
  1589. }
  1590. ### Return list of available directories
  1591. $json->{value} = $ReturnMessage;
  1592. ### Save raw Json string
  1593. $hash->{temp}{JsonRaw} = $decodedContent;
  1594. return $json;
  1595. }
  1596. ### If the type is unknown
  1597. else
  1598. {
  1599. ### Log entries for debugging purposes
  1600. Log3 $name, 4, $name. " : km200_GetSingleService - type unknown for : " .$Service;
  1601. ### Log entries for debugging purposes
  1602. }
  1603. }
  1604. else
  1605. {
  1606. Log3 $name, 4, $name. " : km200_GetSingleService: ". $Service . " NOT available";
  1607. my $ReturnMessage = "ERROR";
  1608. $json -> {type} = $ReturnMessage;
  1609. $json -> {value} = $ReturnMessage;
  1610. return $json;
  1611. }
  1612. }
  1613. }
  1614. ####END####### Subroutine get individual data value ############################################################END#####
  1615. ###START###### Subroutine initial contact of services via HttpUtils ###########################################START####
  1616. sub km200_GetInitService($)
  1617. {
  1618. my ($hash, $def) = @_;
  1619. my $km200_gateway_host = $hash->{URL} ;
  1620. my $name = $hash->{NAME} ;
  1621. $hash->{status}{FlagInitRequest} = true;
  1622. my @KM200_InitServices = @{$hash->{Secret}{KM200ALLSERVICES}};
  1623. my $ServiceCounterInit = $hash->{temp}{ServiceCounterInit};
  1624. my $PollingTimeout = $hash->{POLLINGTIMEOUT};
  1625. my $Service = $KM200_InitServices[$ServiceCounterInit];
  1626. ### Stop the current timer
  1627. RemoveInternalTimer($hash);
  1628. ### If this this loop is accessed for the first time, stop the timer and set status
  1629. if ($ServiceCounterInit == 0)
  1630. {
  1631. ### Log file entry for debugging
  1632. Log3 $name, 5, $name. "Sounding and importing of services started";
  1633. ### Set status of km200 fhem module
  1634. $hash->{STATE} = "Sounding...";
  1635. }
  1636. ### Get the values
  1637. my $url ="http://" . $km200_gateway_host . $Service;
  1638. my $param = {
  1639. url => $url,
  1640. timeout => $PollingTimeout,
  1641. hash => $hash,
  1642. method => "GET",
  1643. header => "agent: TeleHeater/2.2.3\r\nUser-Agent: TeleHeater/2.2.3\r\nAccept: application/json",
  1644. callback => \&km200_ParseHttpResponseInit
  1645. };
  1646. ### Set flag for initialisation
  1647. $hash->{status}{FlagInitRequest} = true;
  1648. ### Get the value
  1649. HttpUtils_NonblockingGet($param);
  1650. }
  1651. ####END####### Subroutine initial contact of services via HttpUtils ############################################END#####
  1652. ###START###### Subroutine to download complete initial data set from gateway ##################################START####
  1653. # For all known, but not excluded services by attribute "DoNotPoll", try reading the respective values from gateway
  1654. sub km200_ParseHttpResponseInit($)
  1655. {
  1656. my ($param, $err, $data) = @_;
  1657. my $hash = $param->{hash};
  1658. my $name = $hash ->{NAME};
  1659. my $ServiceCounterInit = $hash ->{temp}{ServiceCounterInit};
  1660. my @KM200_RespondingServices = @{$hash ->{Secret}{KM200RESPONDINGSERVICES}};
  1661. my @KM200_WriteableServices = @{$hash ->{Secret}{KM200WRITEABLESERVICES}};
  1662. my @KM200_InitServices = @{$hash ->{Secret}{KM200ALLSERVICES}};
  1663. my $NumberInitServices = "";
  1664. my $Service = $KM200_InitServices[$ServiceCounterInit];
  1665. my $type;
  1666. my $json ->{type} = "";
  1667. if($err ne "")
  1668. {
  1669. ### Create Log entry
  1670. Log3 $name, 2, $name . " : km200_ParseHttpResponseInit - ERROR : ".$Service. ": No proper Communication with Gateway: " .$err;
  1671. ### Set status of km200 fhem module
  1672. $hash->{STATE} = "ERROR - Initial Connection failed... Try to re-connect in 10s";
  1673. ### Start the timer for polling again but wait 10s
  1674. InternalTimer(gettimeofday()+10, "km200_GetInitService", $hash, 1);
  1675. ### Create Log entry
  1676. Log3 $name, 2, $name . " : km200_ParseHttpResponseInit - ERROR : Timer restarted to try again in 10s";
  1677. Log3 $name, 5, $name . "______________________________________________________________________________________________________________________";
  1678. return "ERROR";
  1679. }
  1680. $hash->{temp}{decodedcontent} = $data;
  1681. my $decodedContent = km200_Decrypt($hash);
  1682. ### Check whether the decoded content is not empty and therefore available
  1683. if ($decodedContent ne "")
  1684. {
  1685. eval
  1686. {
  1687. $json = decode_json(encode_utf8($decodedContent));
  1688. 1;
  1689. }
  1690. or do
  1691. {
  1692. Log3 $name, 4, $name. " : km200_ParseHttpResponseInit - CANNOT be parsed : ". $Service;
  1693. };
  1694. ### Check whether the type is a single value containing a string or float value
  1695. if(($json -> {type} eq "stringValue") || ($json -> {type} eq "floatValue"))
  1696. {
  1697. my $JsonId = $json->{id};
  1698. my $JsonType = $json->{type};
  1699. my $JsonValue = $json->{value};
  1700. ### Log entries for debugging purposes
  1701. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value found for : " .$Service;
  1702. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - id : " .$JsonId;
  1703. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - type : " .$JsonType;
  1704. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value : " .$JsonValue;
  1705. ### Add service to the list of responding services
  1706. push (@KM200_RespondingServices, $Service);
  1707. ### Delete double entries in the list of responding services and sort in alphabetical order
  1708. my %FilteredKM200RespondingServices;
  1709. $FilteredKM200RespondingServices{$_}=0 for @KM200_RespondingServices;
  1710. @KM200_RespondingServices = (keys %FilteredKM200RespondingServices);
  1711. @KM200_RespondingServices = sort @KM200_RespondingServices;
  1712. ### Save json-hash for DbLog-Split
  1713. $hash->{temp}{ServiceDbLogSplitHash} = $json;
  1714. ### Write reading for fhem
  1715. readingsSingleUpdate( $hash, $JsonId, $JsonValue, 1);
  1716. ### Log file entry for debugging
  1717. my $LogMessage = " : The following Service can be read";
  1718. ### Check whether service is writeable and write name of service in array
  1719. if ($json->{writeable} == 1)
  1720. {
  1721. $LogMessage = $LogMessage . " and is writeable";
  1722. push (@KM200_WriteableServices, $Service);
  1723. }
  1724. else
  1725. {
  1726. # Do nothing
  1727. $LogMessage = $LogMessage . " ";
  1728. }
  1729. ### Log file entry for debugging
  1730. $LogMessage = $LogMessage . " : " . $JsonId;
  1731. Log3 $name, 4, $name. $LogMessage;
  1732. }
  1733. ### Check whether the type is an switchProgram
  1734. elsif ($json -> {type} eq "switchProgram")
  1735. {
  1736. my $JsonId = $json->{id};
  1737. my $JsonType = $json->{type};
  1738. my @JsonValues = $json->{switchPoints};
  1739. ### Log entries for debugging purposes
  1740. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value found for : " .$Service;
  1741. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - id : " .$JsonId;
  1742. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - type : " .$JsonType;
  1743. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value : " .@JsonValues;
  1744. ### Add service to the list of responding services
  1745. push (@KM200_RespondingServices, $Service);
  1746. ### Delete double entries in the list of responding services and sort in alphabetical order
  1747. my %FilteredKM200RespondingServices;
  1748. $FilteredKM200RespondingServices{$_}=0 for @KM200_RespondingServices;
  1749. @KM200_RespondingServices = (keys %FilteredKM200RespondingServices);
  1750. @KM200_RespondingServices = sort @KM200_RespondingServices;
  1751. ### Log file entry for debugging
  1752. my $LogMessage = " : The following Service can be read";
  1753. ### Check whether service is writeable and write name of service in array
  1754. if ($json->{writeable} == 1)
  1755. {
  1756. $LogMessage = $LogMessage . " and is writeable";
  1757. push (@KM200_WriteableServices, $Service);
  1758. }
  1759. else
  1760. {
  1761. # Do nothing
  1762. $LogMessage = $LogMessage . " ";
  1763. }
  1764. $LogMessage = $LogMessage . " : " .$JsonId;
  1765. Log3 $name, 4, $name . $LogMessage;
  1766. ### Set up variables
  1767. my $TempJsonId = "";
  1768. my $TempReadingMo = "";
  1769. my $TempReadingTu = "";
  1770. my $TempReadingWe = "";
  1771. my $TempReadingTh = "";
  1772. my $TempReadingFr = "";
  1773. my $TempReadingSa = "";
  1774. my $TempReadingSu = "";
  1775. foreach my $item (@{ $json->{switchPoints} })
  1776. {
  1777. ### Create string for time and switchpoint in fixed format and write part of Reading String
  1778. my $time = $item->{time};
  1779. my $temptime = $time / 60;
  1780. my $temptimeHH = int($temptime);
  1781. my $temptimeMM = ($time - ($temptimeHH * 60));
  1782. $temptimeHH = sprintf ('%02d', $temptimeHH);
  1783. $temptimeMM = sprintf ('%02d', $temptimeMM);
  1784. $temptime = $temptimeHH . $temptimeMM;
  1785. my $tempsetpoint = $item->{setpoint};
  1786. $tempsetpoint =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(8-length($1)))/e;
  1787. my $TempReading = $temptime . " " . $tempsetpoint;
  1788. ### Create ValueString for this day
  1789. if ($item->{dayOfWeek} eq "Mo")
  1790. {
  1791. ### If it is the first entry for this day
  1792. if ($TempReadingMo eq "")
  1793. {
  1794. ### Write the first entry
  1795. $TempReadingMo = $TempReading;
  1796. }
  1797. ### If it is NOT the first entry for this day
  1798. else
  1799. {
  1800. ### Add the next entry
  1801. $TempReadingMo = $TempReadingMo . " " . $TempReading;
  1802. }
  1803. }
  1804. elsif ($item->{dayOfWeek} eq "Tu")
  1805. {
  1806. ### If it is the first entry for this day
  1807. if ($TempReadingTu eq "")
  1808. {
  1809. ### Write the first entry
  1810. $TempReadingTu = $TempReading;
  1811. }
  1812. ### If it is NOT the first entry for this day
  1813. else
  1814. {
  1815. ### Add the next entry
  1816. $TempReadingTu = $TempReadingTu . " " . $TempReading;
  1817. }
  1818. }
  1819. elsif ($item->{dayOfWeek} eq "We")
  1820. {
  1821. ### If it is the first entry for this day
  1822. if ($TempReadingWe eq "")
  1823. {
  1824. ### Write the first entry
  1825. $TempReadingWe = $TempReading;
  1826. }
  1827. ### If it is NOT the first entry for this day
  1828. else
  1829. {
  1830. ### Add the next entry
  1831. $TempReadingWe = $TempReadingWe . " " . $TempReading;
  1832. }
  1833. }
  1834. elsif ($item->{dayOfWeek} eq "Th")
  1835. {
  1836. ### If it is the first entry for this day
  1837. if ($TempReadingTh eq "")
  1838. {
  1839. ### Write the first entry
  1840. $TempReadingTh = $TempReading;
  1841. }
  1842. ### If it is NOT the first entry for this day
  1843. else
  1844. {
  1845. ### Add the next entry
  1846. $TempReadingTh = $TempReadingTh . " " . $TempReading;
  1847. }
  1848. }
  1849. elsif ($item->{dayOfWeek} eq "Fr")
  1850. {
  1851. ### If it is the first entry for this day
  1852. if ($TempReadingFr eq "")
  1853. {
  1854. ### Write the first entry
  1855. $TempReadingFr = $TempReading;
  1856. }
  1857. ### If it is NOT the first entry for this day
  1858. else
  1859. {
  1860. ### Add the next entry
  1861. $TempReadingFr = $TempReadingFr . " " . $TempReading;
  1862. }
  1863. }
  1864. elsif ($item->{dayOfWeek} eq "Sa")
  1865. {
  1866. ### If it is the first entry for this day
  1867. if ($TempReadingSa eq "")
  1868. {
  1869. ### Write the first entry
  1870. $TempReadingSa = $TempReading;
  1871. }
  1872. ### If it is NOT the first entry for this day
  1873. else
  1874. {
  1875. ### Add the next entry
  1876. $TempReadingSa = $TempReadingSa . " " . $TempReading;
  1877. }
  1878. }
  1879. elsif ($item->{dayOfWeek} eq "Su")
  1880. {
  1881. ### If it is the first entry for this day
  1882. if ($TempReadingSu eq "")
  1883. {
  1884. ### Write the first entry
  1885. $TempReadingSu = $TempReading;
  1886. }
  1887. ### If it is NOT the first entry for this day
  1888. else
  1889. {
  1890. ### Add the next entry
  1891. $TempReadingSu = $TempReadingSu . " " . $TempReading;
  1892. }
  1893. }
  1894. else
  1895. {
  1896. Log3 $name, 5, $name. "dayOfWeek of unknow day: " . $item->{dayOfWeek};
  1897. }
  1898. }
  1899. ### Create new Service and write reading for fhem
  1900. $TempJsonId = $JsonId . "/" . "1-Mo";
  1901. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingMo, 1);
  1902. ### Log file entry for debugging
  1903. Log3 $name, 5, $name. " : The following Service can be read and is writeable : " . $TempJsonId;
  1904. ### Add service to the list of writeable services
  1905. push (@KM200_WriteableServices, $TempJsonId);
  1906. ### Create new Service and write reading for fhem
  1907. $TempJsonId = $JsonId . "/" . "2-Tu";
  1908. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingTu, 1);
  1909. ### Log file entry for debugging
  1910. Log3 $name, 5, $name. " : The following Service can be read and is writeable : " . $TempJsonId;
  1911. ### Add service to the list of writeable services
  1912. push (@KM200_WriteableServices, $TempJsonId);
  1913. ### Create new Service and write reading for fhem
  1914. $TempJsonId = $JsonId . "/" . "3-We";
  1915. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingWe, 1);
  1916. ### Log file entry for debugging
  1917. Log3 $name, 5, $name. " : The following Service can be read and is writeable : " . $TempJsonId;
  1918. ### Add service to the list of writeable services
  1919. push (@KM200_WriteableServices, $TempJsonId);
  1920. ### Create new Service and write reading for fhem
  1921. $TempJsonId = $JsonId . "/" . "4-Th";
  1922. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingTh, 1);
  1923. ### Log file entry for debugging
  1924. Log3 $name, 5, $name. " : The following Service can be read and is writeable : " . $TempJsonId;
  1925. ### Add service to the list of writeable services
  1926. push (@KM200_WriteableServices, $TempJsonId);
  1927. ### Create new Service and write reading for fhem
  1928. $TempJsonId = $JsonId . "/" . "5-Fr";
  1929. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingFr, 1);
  1930. ### Log file entry for debugging
  1931. Log3 $name, 5, $name. " : The following Service can be read and is writeable : " . $TempJsonId;
  1932. ### Add service to the list of writeable services
  1933. push (@KM200_WriteableServices, $TempJsonId);
  1934. ### Create new Service and write reading for fhem
  1935. $TempJsonId = $JsonId . "/" . "6-Sa";
  1936. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingSa, 1);
  1937. ### Log file entry for debugging
  1938. Log3 $name, 5, $name. " : The following Service can be read and is writeable : " . $TempJsonId;
  1939. ### Add service to the list of writeable services
  1940. push (@KM200_WriteableServices, $TempJsonId);
  1941. ### Create new Service and write reading for fhem
  1942. $TempJsonId = $JsonId . "/" . "7-Su";
  1943. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingSu, 1);
  1944. ### Log file entry for debugging
  1945. Log3 $name, 5, $name. " : The following Service can be read and is writeable : " . $TempJsonId;
  1946. ### Add service to the list of writeable services
  1947. push (@KM200_WriteableServices, $TempJsonId);
  1948. }
  1949. ### Check whether the type is an errorlist
  1950. elsif ($json -> {type} eq "errorList")
  1951. {
  1952. my $JsonId = $json->{id};
  1953. my $JsonType = $json->{type};
  1954. ### Log entries for debugging purposes
  1955. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value found for : " .$Service;
  1956. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - id : " .$JsonId;
  1957. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - type : " .$JsonType;
  1958. ### Add service to the list of responding services
  1959. push (@KM200_RespondingServices, $Service);
  1960. ### Delete double entries in the list of responding services and sort in alphabetical order
  1961. my %FilteredKM200RespondingServices;
  1962. $FilteredKM200RespondingServices{$_}=0 for @KM200_RespondingServices;
  1963. @KM200_RespondingServices = (keys %FilteredKM200RespondingServices);
  1964. @KM200_RespondingServices = sort @KM200_RespondingServices;
  1965. ### Log file entry for debugging
  1966. my $LogMessage = " : The following Service can be read";
  1967. ### Check whether service is writeable and write name of service in array
  1968. if ($json->{writeable} == 1)
  1969. {
  1970. $LogMessage = $LogMessage . " and is writeable ";
  1971. push (@KM200_WriteableServices, $Service);
  1972. }
  1973. else
  1974. {
  1975. # Do nothing
  1976. $LogMessage = $LogMessage . " ";
  1977. }
  1978. ### Log file entry for debugging
  1979. $LogMessage = $LogMessage . " : " . $JsonId;
  1980. Log3 $name, 4, $name . $LogMessage;
  1981. ### Sort list by timestamps descending
  1982. my $TempServiceIndex = 0;
  1983. # my @TempSortedErrorList = sort { $b->{t} <=> $a->{t} } @{ $json->{values} };
  1984. my @TempSortedErrorList = sort ( @{ $json->{values} } );
  1985. foreach my $item (@TempSortedErrorList)
  1986. {
  1987. ### Increment Service-Index
  1988. $TempServiceIndex++;
  1989. ### Create message string with fixed blocksize
  1990. my $TempTime = $item->{t};
  1991. $TempTime =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(20-length($1)))/e;
  1992. my $TempErrorCode = $item->{dcd};
  1993. $TempErrorCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(3 -length($1)))/e;
  1994. my $TempAddCode = $item->{ccd};
  1995. $TempAddCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(4 -length($1)))/e;
  1996. my $TempClassCode = $item->{cat};
  1997. $TempClassCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(2- length($1)))/e;
  1998. my $TempErrorMessage = "Time: " . $TempTime . "-ErrorCode: " . $TempErrorCode . " -AddCode: " . $TempAddCode . " -Category: " . $TempClassCode;
  1999. ### Create Service with Increment
  2000. my $TempServiceString = $Service . "/Error-" . (sprintf("%02d", $TempServiceIndex));
  2001. ### Write Reading
  2002. readingsSingleUpdate( $hash, $TempServiceString, $TempErrorMessage, 1);
  2003. ### Log file entry for debugging
  2004. Log3 $name, 5, $name. " : The following Service can be read : " .$TempServiceString;
  2005. }
  2006. }
  2007. ### Check whether the type is an refEnum which is indicating an empty parent directory
  2008. elsif ($json -> {type} eq "refEnum")
  2009. {
  2010. my $JsonId = $json->{id};
  2011. my $JsonType = $json->{type};
  2012. my @JsonReferences = $json->{references};
  2013. ### Log file entry for debugging
  2014. Log3 $name, 5, $name. " : The following Service is an empty parent directory : " . $JsonId;
  2015. ### For each item found in this empty parent directory
  2016. foreach my $item (@{ $json->{references} })
  2017. {
  2018. my $SearchWord = $item->{id};
  2019. ### If the Service found is listed as blocked service
  2020. if ((grep {$_ eq $SearchWord} @{$hash->{Secret}{KM200DONOTPOLL}}) == 1)
  2021. {
  2022. ### Do nothing
  2023. ### Log file entry for debugging
  2024. Log3 $name, 5, $name. "The following Service has been found but is blacklisted: " . $item->{id};
  2025. }
  2026. ### If the Service found is NOT listed as blocked service
  2027. else
  2028. {
  2029. ### Add service to the list of all known services
  2030. push (@{$hash ->{Secret}{KM200ALLSERVICES}}, $item->{id});
  2031. }
  2032. }
  2033. ### Sort the list of all services alphabetically
  2034. @{$hash ->{Secret}{KM200ALLSERVICES}} = sort @{$hash ->{Secret}{KM200ALLSERVICES}};
  2035. }
  2036. ### Check whether the type is a systeminfo
  2037. elsif ($json -> {type} eq "systeminfo")
  2038. {
  2039. my $JsonId = $json->{id};
  2040. my $JsonType = $json->{type};
  2041. my @JsonValues = $json->{values};
  2042. ### Log entries for debugging purposes
  2043. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value found for : " .$Service;
  2044. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - id : " .$JsonId;
  2045. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - type : " .$JsonType;
  2046. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value : " .@JsonValues;
  2047. ### Add service to the list of responding services
  2048. push (@KM200_RespondingServices, $Service);
  2049. ### Delete double entries in the list of responding services and sort in alphabetical order
  2050. my %FilteredKM200RespondingServices;
  2051. $FilteredKM200RespondingServices{$_}=0 for @KM200_RespondingServices;
  2052. @KM200_RespondingServices = (keys %FilteredKM200RespondingServices);
  2053. @KM200_RespondingServices = sort @KM200_RespondingServices;
  2054. ### Log file entry for debugging
  2055. Log3 $name, 4, $name . " : The following Service can be read : " .$JsonId;
  2056. ### Initialise ArrayCounter
  2057. my $ArrayCounter = 0;
  2058. foreach my $ArrayItem (@{ $json->{values} })
  2059. {
  2060. ### Incrementation of ArrayCounter
  2061. $ArrayCounter++;
  2062. ### Log file entry for debugging
  2063. Log3 $name, 5, $name . " : The ArrayItem is : " . $ArrayItem ;
  2064. Log3 $name, 5, $name . " : The keys ArrayItem is : " . (keys %{$ArrayItem}) ;
  2065. ### Get array from scalar
  2066. my %ArrayHash = %{$ArrayItem};
  2067. while( my( $SystemInfoHashKey, $SystemInfoHashValue ) = each %ArrayHash )
  2068. {
  2069. ### Log file entry for debugging
  2070. Log3 $name, 5, $name . " : The ArrayHashKey is : " . $SystemInfoHashKey;
  2071. Log3 $name, 5, $name . " : The ArrayHashValue is : " . $SystemInfoHashValue;
  2072. ### Create new Service and write reading for fhem
  2073. my $TempJsonId = $JsonId . "/" . sprintf ('%02d', $ArrayCounter) . "/" . $SystemInfoHashKey;
  2074. readingsSingleUpdate( $hash, $TempJsonId, $SystemInfoHashValue, 1);
  2075. ### Log file entry for debugging
  2076. Log3 $name, 5, $name . " : The following Service can be read : " . $TempJsonId;
  2077. }
  2078. }
  2079. }
  2080. ### Check whether the type is unknown
  2081. else
  2082. {
  2083. ### Log entries for debugging purposes
  2084. Log3 $name, 4, $name. " : km200_ParseHttpResponseInit - type unknown for : " .$Service;
  2085. }
  2086. }
  2087. ### Check whether the decoded content is empty and therefore NOT available
  2088. else
  2089. {
  2090. ### Log entries for debugging purposes
  2091. Log3 $name, 4, $name. " : km200_ParseHttpResponseInit - NOT available : ". $Service;
  2092. }
  2093. ### Log entries for debugging purposes
  2094. #Log3 $name, 5, $name. " : km200_ParseHttpResponseInit : response : " .$data;
  2095. Log3 $name, 5, $name . "______________________________________________________________________________________________________________________";
  2096. ### Get the size of the array
  2097. @KM200_InitServices = @{$hash ->{Secret}{KM200ALLSERVICES}};
  2098. $NumberInitServices = @KM200_InitServices;
  2099. ### If the list of KM200ALLSERVICES has not been finished yet
  2100. if ($ServiceCounterInit < ($NumberInitServices-1))
  2101. {
  2102. ++$ServiceCounterInit;
  2103. $hash->{temp}{ServiceCounterInit} = $ServiceCounterInit;
  2104. @{$hash->{Secret}{KM200RESPONDINGSERVICES}} = @KM200_RespondingServices;
  2105. @{$hash->{Secret}{KM200WRITEABLESERVICES}} = @KM200_WriteableServices;
  2106. km200_GetInitService($hash);
  2107. }
  2108. ### If the list of KM200ALLSERVICES is finished
  2109. else
  2110. {
  2111. my @KM200_DynServices = @KM200_RespondingServices;
  2112. ### Save arrays of services in hash
  2113. @{$hash->{Secret}{KM200RESPONDINGSERVICES}} = @KM200_RespondingServices;
  2114. @{$hash->{Secret}{KM200WRITEABLESERVICES}} = @KM200_WriteableServices;
  2115. @{$hash->{Secret}{KM200DYNSERVICES}} = @KM200_DynServices;
  2116. ### Reset flag for initialisation
  2117. $hash->{status}{FlagInitRequest} = false;
  2118. ###START###### Initiate the timer for continuous polling of dynamical values from KM200 ###################START####
  2119. InternalTimer(gettimeofday()+($hash->{INTERVALDYNVAL}), "km200_GetDynService", $hash, 1);
  2120. Log3 $name, 4, $name. " : km200 - Define: InternalTimer for dynamic values started with interval of: ".($hash->{INTERVALDYNVAL});
  2121. ####END####### Initiate the timer for continuous polling of dynamical values from KM200 ####################END#####
  2122. ### Reset fullResponse error message
  2123. readingsSingleUpdate( $hash, "fullResponse", "OK", 1);
  2124. ### Log file entry for debugging
  2125. Log3 $name, 5, $name. "Sounding and importing of services is completed";
  2126. ### Set status of km200 fhem module
  2127. $hash->{STATE} = "Standby";
  2128. ### Disable flag
  2129. $hash->{temp}{ServiceCounterInit} = false;
  2130. }
  2131. ### If the Initialisation process has been interuppted with an error message
  2132. if (ReadingsVal($name,"fullResponse",0) eq "ERROR")
  2133. {
  2134. ### Reset fullResponse error message
  2135. readingsSingleUpdate( $hash, "fullResponse", "Restarted after ERROR", 1);
  2136. ### Reset timer for init procedure and start over again until it works
  2137. InternalTimer(gettimeofday()+5, "km200_GetInitService", $hash, 1);
  2138. Log3 $name, 5, $name. " : km200 - Internal timer for Initialisation of services restarted after fullResponse - error.";
  2139. }
  2140. ### Clear up temporary variables
  2141. $hash->{temp}{decodedcontent} = "";
  2142. return;
  2143. }
  2144. ####END####### Subroutine to download complete initial data set from gateway ###################################END#####
  2145. ###START###### Subroutine obtaining dynamic services via HttpUtils ############################################START####
  2146. sub km200_GetDynService($)
  2147. {
  2148. my ($hash, $def) = @_;
  2149. my $km200_gateway_host = $hash->{URL};
  2150. my $name = $hash->{NAME};
  2151. $hash->{STATE} = "Polling";
  2152. my @KM200_DynServices = @{$hash->{Secret}{KM200DYNSERVICES}};
  2153. my $ServiceCounterDyn = $hash->{temp}{ServiceCounterDyn};
  2154. my $PollingTimeout = $hash->{POLLINGTIMEOUT};
  2155. ### Stop the current timer
  2156. RemoveInternalTimer($hash);
  2157. ### If at least one service to be polled is available
  2158. if (@KM200_DynServices != 0)
  2159. {
  2160. my $Service = $KM200_DynServices[$ServiceCounterDyn];
  2161. ### Log file entry for debugging
  2162. if ($ServiceCounterDyn == 0)
  2163. {
  2164. Log3 $name, 5, $name. "Starting download of dynamic services";
  2165. }
  2166. ### Log file entry for debugging
  2167. Log3 $name, 5, $name . " - km200_GetDynService - Polling : " . $Service;
  2168. my $url = "http://" . $km200_gateway_host . $Service;
  2169. my $param = {
  2170. url => $url,
  2171. timeout => $PollingTimeout,
  2172. hash => $hash,
  2173. method => "GET",
  2174. header => "agent: TeleHeater/2.2.3\r\nUser-Agent: TeleHeater/2.2.3\r\nAccept: application/json",
  2175. callback => \&km200_ParseHttpResponseDyn
  2176. };
  2177. ### Set Status Flag in order state running dynamic request
  2178. $hash->{status}{FlagDynRequest} = true;
  2179. ### Get data
  2180. HttpUtils_NonblockingGet($param);
  2181. }
  2182. ### If no service to be polled is available
  2183. else
  2184. {
  2185. Log3 $name, 5, $name . " : No dynamic values available to be read. Skipping download.";
  2186. }
  2187. }
  2188. ####END####### Subroutine get dynamic data value ###############################################################END#####
  2189. ###START###### Subroutine to download complete dynamic data set from gateway ##################################START####
  2190. # For all responding dynamic services read the respective values from gateway
  2191. sub km200_ParseHttpResponseDyn($)
  2192. {
  2193. my ($param, $err, $data) = @_;
  2194. my $hash = $param->{hash};
  2195. my $name = $hash ->{NAME};
  2196. my $ServiceCounterDyn = $hash ->{temp}{ServiceCounterDyn};
  2197. my @KM200_DynServices = @{$hash ->{Secret}{KM200DYNSERVICES}};
  2198. my $NumberDynServices = @KM200_DynServices;
  2199. my $Service = $KM200_DynServices[$ServiceCounterDyn];
  2200. my $type;
  2201. my $json ->{type} = "";
  2202. Log3 $name, 5, $name. " : Parsing response of dynamic service received for : " . $Service;
  2203. ### Reset Status Flag
  2204. $hash->{status}{FlagDynRequest} = false;
  2205. if($err ne "")
  2206. {
  2207. Log3 $name, 2, $name . " : ERROR: Service: ".$Service. ": No proper Communication with Gateway: " .$err;
  2208. readingsSingleUpdate($hash, "fullResponse", "ERROR", 1);
  2209. }
  2210. $hash->{temp}{decodedcontent} = $data;
  2211. my $decodedContent = km200_Decrypt($hash);
  2212. if ($decodedContent ne "")
  2213. {
  2214. eval
  2215. {
  2216. $json = decode_json(encode_utf8($decodedContent));
  2217. 1;
  2218. }
  2219. or do
  2220. {
  2221. Log3 $name, 5, $name. " - km200_parseHttpResponseDyn : Data cannot be parsed by JSON on km200 for http://" . $param->{url};
  2222. };
  2223. ### Check whether the type is a single value containing a string or float value
  2224. if(($json -> {type} eq "stringValue") || ($json -> {type} eq "floatValue"))
  2225. {
  2226. my $JsonId = $json->{id};
  2227. my $JsonType = $json->{type};
  2228. my $JsonValue = $json->{value};
  2229. ### Log entries for debugging purposes
  2230. Log3 $name, 4, $name. " : km200_parseHttpResponseDyn - value found for : " .$Service;
  2231. Log3 $name, 5, $name. " : km200_parseHttpResponseDyn - id : " .$JsonId;
  2232. Log3 $name, 5, $name. " : km200_parseHttpResponseDyn - type : " .$JsonType;
  2233. Log3 $name, 5, $name. " : km200_parseHttpResponseDyn - value : " .$JsonValue;
  2234. ### Log entries for debugging purposes
  2235. ### Save json-hash for DbLog-Split
  2236. $hash->{temp}{ServiceDbLogSplitHash} = $json;
  2237. ### Save json-hash for DbLog-Split
  2238. ### Write reading
  2239. readingsSingleUpdate( $hash, $JsonId, $JsonValue, 1);
  2240. ### Write reading
  2241. }
  2242. ### Check whether the type is an switchProgram
  2243. elsif ($json -> {type} eq "switchProgram")
  2244. {
  2245. my $JsonId = $json->{id};
  2246. my $JsonType = $json->{type};
  2247. ### Log entries for debugging purposes
  2248. Log3 $name, 4, $name. " : km200_parseHttpResponseDyn - value found for : " .$Service;
  2249. Log3 $name, 5, $name. " : km200_parseHttpResponseDyn - id : " .$JsonId;
  2250. Log3 $name, 5, $name. " : km200_parseHttpResponseDyn - type : " .$JsonType;
  2251. ### Set up variables
  2252. my $TempJsonId = "";
  2253. my $TempReadingMo = "";
  2254. my $TempReadingTu = "";
  2255. my $TempReadingWe = "";
  2256. my $TempReadingTh = "";
  2257. my $TempReadingFr = "";
  2258. my $TempReadingSa = "";
  2259. my $TempReadingSu = "";
  2260. foreach my $item (@{ $json->{switchPoints} })
  2261. {
  2262. ### Create string for time and switchpoint in fixed format and write part of Reading String
  2263. my $time = $item->{time};
  2264. my $temptime = $time / 60;
  2265. my $temptimeHH = int($temptime);
  2266. my $temptimeMM = ($time - ($temptimeHH * 60));
  2267. $temptimeHH = sprintf ('%02d', $temptimeHH);
  2268. $temptimeMM = sprintf ('%02d', $temptimeMM);
  2269. $temptime = $temptimeHH . $temptimeMM;
  2270. my $tempsetpoint = $item->{setpoint};
  2271. $tempsetpoint =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(8-length($1)))/e;
  2272. my $TempReading = $temptime . " " . $tempsetpoint;
  2273. ### Create ValueString for this day
  2274. if ($item->{dayOfWeek} eq "Mo")
  2275. {
  2276. ### If it is the first entry for this day
  2277. if ($TempReadingMo eq "")
  2278. {
  2279. ### Write the first entry
  2280. $TempReadingMo = $TempReading;
  2281. }
  2282. ### If it is NOT the first entry for this day
  2283. else
  2284. {
  2285. ### Add the next entry
  2286. $TempReadingMo = $TempReadingMo . " " . $TempReading;
  2287. }
  2288. }
  2289. elsif ($item->{dayOfWeek} eq "Tu")
  2290. {
  2291. ### If it is the first entry for this day
  2292. if ($TempReadingTu eq "")
  2293. {
  2294. ### Write the first entry
  2295. $TempReadingTu = $TempReading;
  2296. }
  2297. ### If it is NOT the first entry for this day
  2298. else
  2299. {
  2300. ### Add the next entry
  2301. $TempReadingTu = $TempReadingTu . " " . $TempReading;
  2302. }
  2303. }
  2304. elsif ($item->{dayOfWeek} eq "We")
  2305. {
  2306. ### If it is the first entry for this day
  2307. if ($TempReadingWe eq "")
  2308. {
  2309. ### Write the first entry
  2310. $TempReadingWe = $TempReading;
  2311. }
  2312. ### If it is NOT the first entry for this day
  2313. else
  2314. {
  2315. ### Add the next entry
  2316. $TempReadingWe = $TempReadingWe . " " . $TempReading;
  2317. }
  2318. }
  2319. elsif ($item->{dayOfWeek} eq "Th")
  2320. {
  2321. ### If it is the first entry for this day
  2322. if ($TempReadingTh eq "")
  2323. {
  2324. ### Write the first entry
  2325. $TempReadingTh = $TempReading;
  2326. }
  2327. ### If it is NOT the first entry for this day
  2328. else
  2329. {
  2330. ### Add the next entry
  2331. $TempReadingTh = $TempReadingTh . " " . $TempReading;
  2332. }
  2333. }
  2334. elsif ($item->{dayOfWeek} eq "Fr")
  2335. {
  2336. ### If it is the first entry for this day
  2337. if ($TempReadingFr eq "")
  2338. {
  2339. ### Write the first entry
  2340. $TempReadingFr = $TempReading;
  2341. }
  2342. ### If it is NOT the first entry for this day
  2343. else
  2344. {
  2345. ### Add the next entry
  2346. $TempReadingFr = $TempReadingFr . " " . $TempReading;
  2347. }
  2348. }
  2349. elsif ($item->{dayOfWeek} eq "Sa")
  2350. {
  2351. ### If it is the first entry for this day
  2352. if ($TempReadingSa eq "")
  2353. {
  2354. ### Write the first entry
  2355. $TempReadingSa = $TempReading;
  2356. }
  2357. ### If it is NOT the first entry for this day
  2358. else
  2359. {
  2360. ### Add the next entry
  2361. $TempReadingSa = $TempReadingSa . " " . $TempReading;
  2362. }
  2363. }
  2364. elsif ($item->{dayOfWeek} eq "Su")
  2365. {
  2366. ### If it is the first entry for this day
  2367. if ($TempReadingSu eq "")
  2368. {
  2369. ### Write the first entry
  2370. $TempReadingSu = $TempReading;
  2371. }
  2372. ### If it is NOT the first entry for this day
  2373. else
  2374. {
  2375. ### Add the next entry
  2376. $TempReadingSu = $TempReadingSu . " " . $TempReading;
  2377. }
  2378. }
  2379. else
  2380. {
  2381. Log3 $name, 5, $name. "dayOfWeek of unknow day: " . $item->{dayOfWeek};
  2382. }
  2383. }
  2384. ### Create new Service and write reading for fhem
  2385. $TempJsonId = $JsonId . "/" . "1-Mo";
  2386. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingMo, 1);
  2387. ### Create new Service and write reading for fhem
  2388. $TempJsonId = $JsonId . "/" . "2-Tu";
  2389. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingTu, 1);
  2390. ### Create new Service and write reading for fhem
  2391. $TempJsonId = $JsonId . "/" . "3-We";
  2392. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingWe, 1);
  2393. ### Create new Service and write reading for fhem
  2394. $TempJsonId = $JsonId . "/" . "4-Th";
  2395. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingTh, 1);
  2396. ### Create new Service and write reading for fhem
  2397. $TempJsonId = $JsonId . "/" . "5-Fr";
  2398. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingFr, 1);
  2399. ### Create new Service and write reading for fhem
  2400. $TempJsonId = $JsonId . "/" . "6-Sa";
  2401. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingSa, 1);
  2402. ### Create new Service and write reading for fhem
  2403. $TempJsonId = $JsonId . "/" . "7-Su";
  2404. readingsSingleUpdate( $hash, $TempJsonId, $TempReadingSu, 1);
  2405. }
  2406. ### Check whether the type is an errorlist
  2407. elsif ($json -> {type} eq "errorList")
  2408. {
  2409. my $JsonId = $json->{id};
  2410. my $JsonType = $json->{type};
  2411. my $TempServiceIndex = 0;
  2412. ### Sort list by timestamps descending
  2413. # my @TempSortedErrorList = sort { $b->{t} <=> $a->{t} } @{ $json->{values} };
  2414. my @TempSortedErrorList = sort ( @{ $json->{values} } );
  2415. ### For every notification do
  2416. foreach my $item (@TempSortedErrorList)
  2417. {
  2418. ### Increment Service-Index
  2419. $TempServiceIndex++;
  2420. ### Create message string with fixed blocksize
  2421. my $TempTime = $item->{t};
  2422. $TempTime =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(20-length($1)))/e;
  2423. my $TempErrorCode = $item->{dcd};
  2424. $TempErrorCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(3 -length($1)))/e;
  2425. my $TempAddCode = $item->{ccd};
  2426. $TempAddCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(4 -length($1)))/e;
  2427. my $TempClassCode = $item->{cat};
  2428. $TempClassCode =~ s/^(.+)$/sprintf("%s%s", $1, ' 'x(2- length($1)))/e;
  2429. my $TempErrorMessage = "Time: " . $TempTime . "-ErrorCode: " . $TempErrorCode . " -AddCode: " . $TempAddCode . " -Category: " . $TempClassCode;
  2430. ### Create Service with Increment and leading 0
  2431. my $TempServiceString = $Service . "/Error-" . (sprintf("%02d", $TempServiceIndex));
  2432. ### Write Reading
  2433. readingsSingleUpdate( $hash, $TempServiceString, $TempErrorMessage, 1);
  2434. }
  2435. }
  2436. ### Check whether the type is a systeminfo
  2437. elsif ($json -> {type} eq "systeminfo")
  2438. {
  2439. my $JsonId = $json->{id};
  2440. my $JsonType = $json->{type};
  2441. my @JsonValues = $json->{values};
  2442. ### Log entries for debugging purposes
  2443. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value found for : " .$Service;
  2444. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - id : " .$JsonId;
  2445. Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - type : " .$JsonType;
  2446. ### Initialise ArrayCounter
  2447. my $ArrayCounter = 0;
  2448. foreach my $ArrayItem (@{ $json->{values} })
  2449. {
  2450. ### Incrementation of ArrayCounter
  2451. $ArrayCounter++;
  2452. ### Get array from scalar
  2453. my %ArrayHash = %{$ArrayItem};
  2454. while( my( $SystemInfoHashKey, $SystemInfoHashValue ) = each %ArrayHash )
  2455. {
  2456. ### Create new Service and write reading for fhem
  2457. my $TempJsonId = $JsonId . "/" . sprintf ('%02d', $ArrayCounter) . "/" . $SystemInfoHashKey;
  2458. readingsSingleUpdate( $hash, $TempJsonId, $SystemInfoHashValue, 1);
  2459. }
  2460. }
  2461. }
  2462. ### Check whether the type is unknown
  2463. else
  2464. {
  2465. ### Log entries for debugging purposes
  2466. Log3 $name, 4, $name. " : km200_parseHttpResponseDyn - type unknown for : " .$Service;
  2467. }
  2468. }
  2469. else
  2470. {
  2471. Log3 $name, 5, $name. " : km200_parseHttpResponseDyn - Data not available on km200 for http://" . $param->{url};
  2472. }
  2473. Log3 $name, 5, $name . "______________________________________________________________________________________________________________________";
  2474. ### Clear up temporary variables
  2475. $hash->{temp}{decodedcontent} = "";
  2476. $hash->{temp}{service} = "";
  2477. ### Clear up temporary variables
  2478. ### If list is not complete yet
  2479. if ($ServiceCounterDyn < ($NumberDynServices-1))
  2480. {
  2481. ++$ServiceCounterDyn;
  2482. $hash->{temp}{ServiceCounterDyn} = $ServiceCounterDyn;
  2483. km200_GetDynService($hash);
  2484. }
  2485. ### If list is complete
  2486. else
  2487. {
  2488. $hash->{STATE} = "Standby";
  2489. $hash->{temp}{ServiceCounterDyn} = 0;
  2490. ###START###### Re-Start the timer #####################################START####
  2491. InternalTimer(gettimeofday()+$hash->{INTERVALDYNVAL}, "km200_GetDynService", $hash, 1);
  2492. ####END####### Re-Start the timer ######################################END#####
  2493. ### Update fullResponse Reading
  2494. readingsSingleUpdate( $hash, "fullResponse", "OK", 1);
  2495. $hash->{status}{FlagDynRequest} = false;
  2496. Log3 $name, 5, $name . "______________________________________________________________________________________________________________________";
  2497. }
  2498. return undef;
  2499. }
  2500. ####END####### Subroutine to download complete dynamic data set from gateway ###################################END#####
  2501. 1;
  2502. ###START###### Description for fhem commandref ################################################################START####
  2503. =pod
  2504. =item device
  2505. =item summary Connects fhem to Buderus KM300, KM200, KM100, KM50
  2506. =item summary_DE Verbindet fhem mit Buderus KM300, KM200, KM100, KM50
  2507. =begin html
  2508. <a name="km200"></a>
  2509. <h3>KM200</h3>
  2510. <ul>
  2511. <table>
  2512. <tr>
  2513. <td>
  2514. 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>
  2515. 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
  2516. er/EasyControl-4848514.html"> EasyControl</a>.<BR>
  2517. Furthermore it allows the maintenance companies to access the central heating control system to read and change settings.<BR>
  2518. The km200 fhem-module enables read/write access to these parameters.<BR>
  2519. <BR>
  2520. 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>
  2521. <BR>
  2522. <b><u>Remark:</u></b><BR>
  2523. 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>
  2524. You should configure (or leave) your internet router with the respective settings.<BR>
  2525. 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>
  2526. <BR>
  2527. As soon the module has been defined within the fhem.cfg, the module is trying to obtain all known/possible services. <BR>
  2528. 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>
  2529. This two different set of values can be bound to an individual polling interval. Refer to <a href="#KM200Attr">Attributes</a><BR>
  2530. <BR>
  2531. </td>
  2532. </tr>
  2533. </table>
  2534. <table>
  2535. <tr><td><a name="KM200define"></a><b>Define</b></td></tr>
  2536. </table>
  2537. <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>
  2538. <ul><ul>
  2539. <table>
  2540. <tr><td><code>&lt;name&gt;</code> : </td><td>The name of the device. Recommendation: "myKm200".</td></tr>
  2541. <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>
  2542. <tr><td><code>&lt;GatewayPassword&gt;</code> : </td><td>The gateway password which is provided on the type sign of the KMxxx.</td></tr>
  2543. <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>
  2544. </table>
  2545. </ul></ul>
  2546. <BR>
  2547. <table>
  2548. <tr><td><a name="KM200Set"></a><b>Set</b></td></tr>
  2549. <tr><td>
  2550. <ul>
  2551. The set function is able to change a value of a service which has the "writeable" - tag within the KMxxx service structure.<BR>
  2552. Most of those values have an additional list of allowed values which are the only ones to be set.<BR>
  2553. Other floatable type values can be changed only within their range of minimum and maximum value.<BR>
  2554. </ul>
  2555. </td></tr>
  2556. </table>
  2557. <table><tr><td><ul><code>set &lt;service&gt; &lt;value&gt;</code></ul></td></tr></table>
  2558. <ul><ul>
  2559. <table>
  2560. <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>
  2561. <tr><td><code>&lt;value&gt;</code> : </td><td>A valid value for this service.<BR></td></tr>
  2562. </table>
  2563. </ul></ul>
  2564. <BR>
  2565. <table>
  2566. <tr><td><a name="KM200Get"></a><b>Get</b></td></tr>
  2567. <tr><td>
  2568. <ul>
  2569. The get function is able to obtain a value of a service within the KMxxx service structure.<BR>
  2570. The additional list of allowed values or their range of minimum and maximum value will not be handed back.<BR>
  2571. </ul>
  2572. </td></tr>
  2573. </table>
  2574. <table><tr><td><ul><code>get &lt;service&gt; &lt;option&gt;</code></ul></td></tr></table>
  2575. <ul><ul>
  2576. <table>
  2577. <tr>
  2578. <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>
  2579. &nbsp;&nbsp;It returns only the value but not the unit or the range or list of allowed values possible.<BR>
  2580. </td>
  2581. </tr>
  2582. </table>
  2583. </ul></ul>
  2584. <ul><ul>
  2585. <table>
  2586. <tr>
  2587. <td><code>&lt;option&gt;</code> : </td><td>The optional Argument for the result of the get-command e.g.: "<code>json</code>"<BR>
  2588. &nbsp;&nbsp;The following options are available:<BR>
  2589. &nbsp;&nbsp;json - Returns the raw json-answer from the KMxxx as string.
  2590. </td>
  2591. </tr>
  2592. </table>
  2593. </ul></ul>
  2594. <BR>
  2595. <table>
  2596. <tr><td><a name="KM200Attr"></a><b>Attributes</b></td></tr>
  2597. <tr><td>
  2598. <ul>
  2599. 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>
  2600. </ul>
  2601. </td></tr>
  2602. </table>
  2603. <ul><ul>
  2604. <table>
  2605. <tr>
  2606. <td>
  2607. <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>
  2608. The default value is 300s.<BR>
  2609. </td></tr>
  2610. </td>
  2611. </tr>
  2612. </table>
  2613. </ul></ul>
  2614. <ul><ul>
  2615. <table>
  2616. <tr>
  2617. <td>
  2618. <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>
  2619. The default and minimum value is 5s.<BR>
  2620. </td></tr>
  2621. </td>
  2622. </tr>
  2623. </table>
  2624. </ul></ul>
  2625. <ul><ul>
  2626. <table>
  2627. <tr>
  2628. <td>
  2629. <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>
  2630. The list can be filled with the name of the top - hierarchy service, which means everything below that service will also be ignored.<BR>
  2631. The default value (empty) therefore nothing will be ignored.<BR>
  2632. </td></tr>
  2633. </td>
  2634. </tr>
  2635. </table>
  2636. </ul></ul>
  2637. <ul><ul>
  2638. <table>
  2639. <tr>
  2640. <td>
  2641. <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>
  2642. The default value is 100 = 100ms = 0,1s.<BR>
  2643. </td></tr>
  2644. </td>
  2645. </tr>
  2646. </table>
  2647. </ul></ul>
  2648. <ul><ul>
  2649. <table>
  2650. <tr>
  2651. <td>
  2652. <tr><td><li><code>disable</code> : </li></td><td>Stops the device from further pollings and deletes the existing readings.<BR>
  2653. The default value is 0 = activated<BR>
  2654. </td></tr>
  2655. </td>
  2656. </tr>
  2657. </table>
  2658. </ul></ul>
  2659. </ul>
  2660. =end html
  2661. =begin html_DE
  2662. <a name="km200"></a>
  2663. <h3>KM200</h3>
  2664. <ul>
  2665. <table>
  2666. <tr>
  2667. <td>
  2668. 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>
  2669. 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>
  2670. 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>
  2671. Das km200 fhem-Modul erlaubt den Lese-/Schreibzugriff dieser Parameter durch fhem.<BR>
  2672. <BR>
  2673. 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>
  2674. <BR>
  2675. <b><u>Anmerkung:</u></b><BR>
  2676. 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>
  2677. Der Router sollte entsprechend Konfiguriert bzw. so belassen werden.<BR>
  2678. 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>
  2679. <BR>
  2680. 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>
  2681. 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>
  2682. Diese beiden S&auml;tze an Services k&ouml;nnen mir einem individuellen Abfrageintervall versehen werden. Siehe <a href="#KM200Attr">Attributes</a><BR>
  2683. <BR>
  2684. </td>
  2685. </tr>
  2686. </table>
  2687. <table>
  2688. <tr><td><a name="KM200define"></a><b>Define</b></td></tr>
  2689. </table>
  2690. <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>
  2691. <ul><ul>
  2692. <table>
  2693. <tr><td><code>&lt;name&gt;</code> : </td><td>Der Name des Ger&auml;tes. Empfehlung: "myKm200".</td></tr>
  2694. <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>
  2695. <tr><td><code>&lt;GatewayPassword&gt;</code> : </td><td>Das gateway Passwort, welches auf dem Typenschild des KM200/KM50 zu finden ist.</td></tr>
  2696. <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>
  2697. </table>
  2698. </ul></ul>
  2699. <BR>
  2700. <table>
  2701. <tr><td><a name="KM200Set"></a><b>Set</b></td></tr>
  2702. <tr><td>
  2703. <ul>
  2704. Die set Funktion &auml;ndert die Werte der Services welche das Flag "schreibbar" innerhalb der KMxxx Service Struktur besitzen.<BR>
  2705. Die meisten dieser beschreibbaren Werte haben eine exklusive Liste von m&ouml;glichen Werten innerhalb dessen sich der neue Wert bewegen muss.<BR>
  2706. Andere Flie&szlig;komma Werte haben einen maximum und minumum Wert, in dessen sich der neue Wert bewegen mu&szlig;.<BR>
  2707. </ul>
  2708. </td></tr>
  2709. </table>
  2710. <table><tr><td><ul><code>set &lt;service&gt; &lt;value&gt;</code></ul></td></tr></table>
  2711. <ul><ul>
  2712. <table>
  2713. <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>
  2714. <tr><td><code>&lt;value&gt;</code> : </td><td>Ein g&uuml;ltiger Wert f&uuml;r diesen Service.<BR></td></tr>
  2715. </table>
  2716. </ul></ul>
  2717. <BR>
  2718. <table>
  2719. <tr><td><a name="KM200Get"></a><b>Get</b></td></tr>
  2720. <tr><td>
  2721. <ul>
  2722. Die get-Funktion ist in der Lage einen Wert eines Service innerhalb der KMxxx Service Struktur auszulesen.<BR>
  2723. Die zus&auml;tzliche Liste von erlaubten Werten oder der Wertebereich zwischen Minimum und Maximum wird nicht zur&uuml;ck gegeben.<BR>
  2724. </ul>
  2725. </td></tr>
  2726. </table>
  2727. <table><tr><td><ul><code>get &lt;service&gt; &lt;option&gt;</code></ul></td></tr></table>
  2728. <ul><ul>
  2729. <table>
  2730. <tr>
  2731. <td><code>&lt;service&gt;</code> : </td><td>Der Name des Service welcher ausgelesen werden soll. Z.B.: "<code>/heatingCircuits/hc1/operationMode</code>"<BR>
  2732. &nbsp;&nbsp;Es gibt nur den Wert, aber nicht die Werteliste oder den m&ouml;glichen Wertebereich zur&uuml;ck.<BR>
  2733. </td>
  2734. </tr>
  2735. </table>
  2736. </ul></ul>
  2737. <ul><ul>
  2738. <table>
  2739. <tr>
  2740. <td><code>&lt;option&gt;</code> : </td><td>Das optionelle Argument f&uuml;r Ausgabe des get-Befehls Z.B.: "<code>json</code>"<BR>
  2741. &nbsp;&nbsp;Folgende Optionen sind verf&uuml;gbar:<BR>
  2742. &nbsp;&nbsp;json - Gibt anstelle des Wertes, die gesamte Json Antwort des KMxxx als String zur&uuml;ck
  2743. </td>
  2744. </tr>
  2745. </table>
  2746. </ul></ul>
  2747. <BR>
  2748. <table>
  2749. <tr><td><a name="KM200Attr"></a><b>Attributes</b></td></tr>
  2750. <tr><td>
  2751. <ul>
  2752. Die folgenden Modul-spezifischen Attribute k&ouml;nnen neben den bekannten globalen Attributen gesetzt werden wie z.B.: <a href="#room">room</a>.<BR>
  2753. </ul>
  2754. </td></tr>
  2755. </table>
  2756. <ul><ul>
  2757. <table>
  2758. <tr>
  2759. <td>
  2760. <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>
  2761. Der Default-Wert ist 300s.<BR>
  2762. </td></tr>
  2763. </td>
  2764. </tr>
  2765. </table>
  2766. </ul></ul>
  2767. <ul><ul>
  2768. <table>
  2769. <tr>
  2770. <td>
  2771. <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>
  2772. Der Default-Wert ist 5s.<BR>
  2773. </td></tr>
  2774. </td>
  2775. </tr>
  2776. </table>
  2777. </ul></ul>
  2778. <ul><ul>
  2779. <table>
  2780. <tr>
  2781. <td>
  2782. <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>
  2783. Die Liste kann auch Hierarchien von services enthalten. Dies bedeutet, das alle Services unterhalb dieses Services ebenfalls gel&ouml;scht werden.<BR>
  2784. Der Default Wert ist (empty) somit werden alle bekannten Services abgefragt.<BR>
  2785. </td></tr>
  2786. </td>
  2787. </tr>
  2788. </table>
  2789. </ul></ul>
  2790. <ul><ul>
  2791. <table>
  2792. <tr>
  2793. <td>
  2794. <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>
  2795. Der Default-Wert ist 100 = 100ms = 0,1s.<BR>
  2796. </td></tr>
  2797. </td>
  2798. </tr>
  2799. </table>
  2800. </ul></ul>
  2801. <ul><ul>
  2802. <table>
  2803. <tr>
  2804. <td>
  2805. <tr><td><li><code>disable</code> : </li></td><td>Deaktiviert das Device und l&ouml;scht alle bestehenden Readings.<BR>
  2806. Der Default-Wert ist 0 = aktiviert<BR>
  2807. </td></tr>
  2808. </td>
  2809. </tr>
  2810. </table>
  2811. </ul></ul>
  2812. </ul>
  2813. =end html_DE