45_Plugwise.pm 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503
  1. #################################################################################
  2. # 45_Plugwise.pm
  3. #
  4. # FHEM Module for Plugwise
  5. #
  6. # Copyright (C) 2014 Stefan Guttmann
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. #
  22. # Info on protocol:
  23. # http://roheve.wordpress.com/2011/05/15/plugwise-protocol-analysis-part-3/
  24. # http://www.domoticaforum.eu/viewtopic.php?f=39&t=4319&start=30
  25. #
  26. # The GNU General Public License may also be found at http://www.gnu.org/licenses/gpl-2.0.html .
  27. #
  28. # define myPlugwise Plugwise /dev/ttyPlugwise
  29. #
  30. #
  31. ###########################
  32. # # $Id: 45_Plugwise.pm 11989 2016-08-19 17:50:52Z icinger $
  33. package main;
  34. use strict;
  35. use warnings;
  36. use Time::HiRes qw(gettimeofday);
  37. use Digest::CRC qw(crc);
  38. #use Math::Round;
  39. use Data::Dumper;
  40. my $Make2Channels = 1;
  41. my $testcount=-1;
  42. my $firstrun=0;
  43. my $device=0;
  44. my $data="";
  45. my $toggle=0;
  46. my $status="";
  47. my ($self)=();
  48. my $lastcircle="";
  49. my $buffer="";
  50. my $LastTime=time;
  51. my $lastSync=-1;
  52. my @buffer=();
  53. my $initdone=0;
  54. my %PW_gets = (
  55. "features" => 'Z'
  56. );
  57. my %PW_sets = (
  58. "Scan_Circles" => " ",
  59. "reOpen" => " ",
  60. "syncTime" => " ",
  61. # "pwPairForSec" => ""
  62. );
  63. my %PWType = (
  64. "00" => "PW_Circle",
  65. "01" => "PW_Circle",
  66. "02" => "PW_Circle",
  67. "03" => "PW_Switch",
  68. "04" => "PW_Switch",
  69. "05" => "PW_Sense",
  70. "06" => "PW_Scan"
  71. );
  72. sub PW_Read($);
  73. sub PW_Ready($);
  74. sub PW_Undef($$);
  75. sub PW_Write;
  76. sub PW_Parse($$$$);
  77. sub PW_DoInit($);
  78. sub Plugwise_Initialize($$)
  79. {
  80. my ($hash) = @_;
  81. $self = bless {
  82. _buf => '',
  83. baud => 115200,
  84. device => '',
  85. _awaiting_stick_response => 0
  86. };
  87. require "$attr{global}{modpath}/FHEM/DevIo.pm";
  88. # Provider
  89. $hash->{Clients} = ":PW_Circle:PW_Scan:PW_Switch:PW_Sense:";
  90. my %mc = (
  91. "1:PW_Circle" => "^PW_Circle",
  92. "2:PW_Scan" => "^PW_Scan",
  93. "3:PW_Switch" => "^PW_Switch",
  94. "4:PW_Sense" => "^PW_Sense"
  95. );
  96. $hash->{MatchList} = \%mc;
  97. # Normal devices
  98. $hash->{ReadFn} = "PW_Read";
  99. $hash->{WriteFn} = "PW_Write";
  100. $hash->{ReadyFn} = "PW_Ready";
  101. $hash->{DefFn} = "PW_Define";
  102. $hash->{UndefFn} = "PW_Undef";
  103. $hash->{SetFn} = "PW_Set";
  104. $hash->{GetFn} = "PW_Get";
  105. $hash->{StateFn} = "PW_SetState";
  106. $hash->{AttrList}= "do_not_notify:1,0 interval circlecount WattFormat showCom autosync";
  107. $hash->{ShutdownFn} = "PW_Shutdown";
  108. }
  109. #####################################
  110. sub PW_Define($$)
  111. {
  112. my ($hash, $def) = @_;
  113. my @a = split("[ \t][ \t]*", $def);
  114. my $inter = 10;
  115. if (@a != 3 ) {
  116. my $msg = "wrong syntax: define <name> Plugwise devicename";
  117. Log3 $hash, 2, $msg;
  118. return $msg;
  119. }
  120. my $name = $a[0];
  121. my $dev = $a[2];
  122. $hash->{NAME}=$name;
  123. DevIo_CloseDev($hash);
  124. $firstrun=0;
  125. $hash->{DeviceName} = $dev;
  126. if( $init_done ) {
  127. $attr{$name}{room}="Plugwise";
  128. $attr{$name}{interval}=10;
  129. $attr{$name}{circlecount}=50;
  130. $attr{$name}{WattFormat}="%0.f";
  131. }
  132. my $ret = DevIo_OpenDev( $hash, 0, undef);
  133. InternalTimer(gettimeofday()+5, "PW_GetUpdate", $hash, 0);
  134. return undef;
  135. }
  136. sub PW_GetUpdate($)
  137. {
  138. my $hash = shift;
  139. my $name = $hash->{NAME};
  140. my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, $Jahr, $Wochentag, $Jahrestag, $Sommerzeit) = localtime(time);
  141. my $n=0;
  142. if ($firstrun==2) {return undef};
  143. InternalTimer(gettimeofday()+$attr{$name}{interval}, "PW_GetUpdate", $hash, 1);
  144. # Log 3,Dumper($hash->{helper});
  145. if ($firstrun==0) {
  146. PW_DoInit($hash);
  147. return undef;
  148. }
  149. delete $self->{_waiting};
  150. foreach ( keys %{ $hash->{helper}->{circles} } ) {
  151. $n=$_;
  152. if (defined $hash->{helper}->{circles}->{$n}->{lastContact}) {
  153. if (time>$hash->{helper}->{circles}->{$n}->{lastContact} +960) {
  154. Log3 $hash,3,"Set Circle $n offline";
  155. my %xplmsg = ( schema => 'plugwise.basic', );
  156. my $saddr=$hash->{helper}->{circles}->{$n}->{name};
  157. $xplmsg{dest}=$self->{_plugwise}->{circles}->{$saddr}->{type};
  158. $xplmsg{type} = 'output';
  159. $xplmsg{text}= 'offline';
  160. $xplmsg{short} = $saddr;
  161. PW_Parse($hash, $hash, $hash->{NAME}, \%xplmsg);
  162. delete $hash->{helper}->{circles}->{$n};
  163. } elsif (time > $hash->{helper}->{circles}->{$n}->{lastContact} +900) {
  164. command($hash,'history',$hash->{helper}->{circles}->{$n}->{name},4);
  165. Log 3,"GetLog offline Circle $n";
  166. }
  167. }
  168. }
  169. foreach ( keys %{ $self->{_plugwise}->{circles} } ) {
  170. $n=$_;
  171. if (!defined $self->{_plugwise}->{circles}->{$n}->{type}) {$self->{_plugwise}->{circles}->{$n}->{type}=""};
  172. if ($self->{_plugwise}->{circles}->{$n}->{type} eq "" ||
  173. !defined $self->{_plugwise}->{circles}->{$n}->{type}) {
  174. command($hash,'status',$n);
  175. }
  176. if (defined $attr{$name}{autosync}) {
  177. if ($attr{$name}{autosync}>0 && time > $lastSync+$attr{$name}{autosync}) {
  178. $lastSync=time;
  179. command($hash,'syncTime',$n);
  180. }
  181. }
  182. }
  183. }
  184. sub MyRead($$)
  185. {
  186. my ($hash, $msg) = @_;
  187. return if (!defined $msg->{dest} );
  188. PW_Parse($hash, $hash, $hash->{NAME}, $msg) if defined $msg;
  189. }
  190. sub PW_Write
  191. {
  192. my ($hash,$reciever,$fn,$a) = @_;
  193. my $name = $hash->{NAME};
  194. return if(!defined($fn));
  195. my $msg = "$hash->{NAME} sending $fn";
  196. $msg .= " to Adress $a" if defined $a;
  197. if ($fn =~ /(on|off)/) {
  198. command($hash,$fn,$reciever,$a);
  199. }
  200. elsif ($fn =~ /(syncTime|ping|removeNode|livepower|status)/) {
  201. command($hash,$fn,$reciever)
  202. }
  203. elsif ($fn eq "getLog") {
  204. command($hash,'history',$reciever,$a) if($a ne -1);
  205. }
  206. else
  207. { Log3 $hash,3,$msg;
  208. }
  209. return undef;
  210. }
  211. #####################################
  212. sub PW_Undef($$)
  213. {
  214. my ($hash, $arg) = @_;
  215. $firstrun=2;
  216. DevIo_CloseDev($hash);
  217. return undef;
  218. }
  219. #####################################
  220. sub PW_Shutdown($)
  221. {
  222. my ($hash) = @_;
  223. DevIo_CloseDev($hash);
  224. return undef;
  225. }
  226. #NeedsEdit
  227. #####################################
  228. sub PW_Set($@)
  229. {
  230. my ($hash, @a) = @_;
  231. my $msg;
  232. my $name=$a[0]; my $reading= $a[1];
  233. my $n=1;
  234. return "\"set X\" needs at least one argument" if ( @a < 2 );
  235. if ($reading eq "myTest") {
  236. $testcount=0;
  237. } elsif ($reading eq "myTestOff") {
  238. $testcount=-1;
  239. }
  240. elsif(!$PW_sets{$reading}) {
  241. my @cList = keys %PW_sets;
  242. return "Unknown argument $reading, choose one of " . join(" ", @cList);
  243. }
  244. if ($reading eq "Scan_Circles") {
  245. PW_DoInit($hash);
  246. #query_connected_circles($hash);
  247. }
  248. elsif ($reading eq "syncTime") {
  249. foreach ( keys %{ $self->{_plugwise}->{circles} } ) {
  250. $n=$_;
  251. command($hash,'syncTime',$n);
  252. }
  253. }
  254. elsif ($reading eq "reOpen") {
  255. DevIo_CloseDev($hash);
  256. $hash->{ERRCNT} = 0;
  257. $firstrun=0;
  258. my $ret = DevIo_OpenDev( $hash, 0, undef);
  259. RemoveInternalTimer($hash);
  260. InternalTimer(gettimeofday()+2, "PW_GetUpdate", $hash, 0);
  261. return undef;
  262. }
  263. elsif ($reading eq "pwPairForSec") {
  264. # RemoveInternalTimer("pairTimer");
  265. # InternalTimer(gettimeofday()+$value, "PW_Circle_OnOffTimer", 'pairTimer'), 1);
  266. Mywrite( $hash, "000701" . _addr_s2l( $self->{_plugwise}->{coordinator_MAC} ) ,1 );
  267. }
  268. }
  269. sub PW_Get($@)
  270. {
  271. my ( $hash, @a ) = @_;
  272. my $n=1;
  273. return "\"get X\" needs at least one argument" if ( @a < 2 );
  274. my $name = shift @a;
  275. my $opt = shift @a;
  276. if(!$PW_gets{$opt}) {
  277. my @cList = keys %PW_gets;
  278. return "Unknown argument $opt, choose one of " . join(" ", @cList);
  279. }
  280. if($opt eq 'features') {
  281. foreach ( keys %{ $self->{_plugwise}->{circles} } ) {
  282. $n=$_;
  283. command($hash,'feature',$n);
  284. }
  285. return undef;
  286. }
  287. }
  288. #NeedsEdit
  289. #####################################
  290. sub PW_SetState($$$$)
  291. {
  292. my ($hash, $tim, $vt, $val) = @_;
  293. return undef;
  294. }
  295. #####################################
  296. sub PW_DoInit($)
  297. {
  298. my $hash = shift;
  299. Mywrite($hash,"000A",1);
  300. return undef;
  301. }
  302. #####################################
  303. # called from the global loop, when the select for hash->{FD} reports data
  304. sub PW_Read($)
  305. {
  306. my ($hash) = @_;
  307. my $name = $hash->{NAME};
  308. my $char;
  309. my $body;
  310. # read from serial device
  311. my $buf = DevIo_SimpleRead($hash);
  312. my $buf2= $buf;
  313. $buf2=~s/\r\n/\|/g;
  314. return "" if ( !defined($buf) );
  315. $hash->{helper}{buffer} .= $buf;
  316. return unless ( $hash->{helper}{buffer} =~ s/(.+)\r\n// );
  317. do {
  318. my $v=$1;
  319. if ($v=~/\x83?\x05\x05\x03\x03(\w+)/) {
  320. $body = process_response($hash,$1);
  321. if($body ne undef) {
  322. my $str2=AttrVal($hash->{NAME},"showCom","xyz");
  323. my $showcom=qr/$str2/;
  324. if ($body->{showCom} =~ $showcom) {readingsSingleUpdate($hash,"communication", $body->{showCom},1)}
  325. if ($body->{text} eq "Found circle") {
  326. if ($body->{device} ne "FFFFFFFFFFFFFFFF") {
  327. PW_Write($hash,$body->{short},"getLog",1);
  328. command($hash,'status',$body->{short});
  329. command($hash,'livepower',$body->{short});
  330. } else {$body->{type}=""}
  331. }
  332. if ($body->{text} eq "Connected") {$hash->{"STATE"}="Connected";}
  333. if ($body->{type} =~ /output|power|sense|humtemp|energy|ping/) {
  334. if ($body->{dest} eq "PW_Switch" && $Make2Channels==1) {
  335. my $dest=$body->{short};
  336. $body->{short}=$dest . "_Ch".$body->{val3};
  337. MyRead($hash,$body);
  338. } else {
  339. MyRead($hash,$body);
  340. }
  341. }
  342. if ($body->{dest} eq "none"
  343. && $body->{type} eq "stat"
  344. && $body->{text} ne "ack") {
  345. readingsSingleUpdate($hash,"LastMsg", $body->{text}." - Device: ".$body->{code},1) ;
  346. }
  347. if ($body->{type} eq "err3") {Mywrite($hash, "0026" . $body->{device} ,1);}
  348. if ($body->{type} eq "err") {readingsSingleUpdate($hash,"LastMsg", $body->{text}." - Device: ".$body->{code},1) ;;
  349. my $tm=(time - $LastTime);
  350. if ($tm>600) {$hash->{"ERRCNT"}=0};
  351. $LastTime=time;
  352. $hash->{"ERRCNT"}++;
  353. Log 3,Dumper($body);
  354. if ($hash->{"ERRCNT"} == 50) {
  355. Log3 $hash,3,"$name - Too many Errors, giving up. Use 'get $name reOpen' after correcting the Problem";
  356. DevIo_CloseDev($hash);
  357. $firstrun=2;
  358. DevIo_CloseDev($hash);
  359. Log 3,Dumper($hash->{helper}{buffer});
  360. Log 3,"$name Disconnected...........................................";
  361. $hash->{"STATE"}="Disconnected";
  362. @buffer=();
  363. return undef;
  364. }
  365. }
  366. }
  367. } elsif ($v=~/\x23.*/) {}
  368. elsif ($v=~/[0-9A-F]{16}/){}
  369. else
  370. {
  371. Log3 $hash,3,"Not processed: $v";
  372. }
  373. } while ( $hash->{helper}{buffer} =~ s/(.+)\r\n// );
  374. $self->{_awaiting_stick_response} = 0;
  375. if (@buffer) {real_write($hash)};
  376. return $body;
  377. }
  378. sub PW_Parse($$$$)
  379. {
  380. my ($hash, $iohash, $name, $rmsg) = @_;
  381. my %addvals;
  382. Log3 $hash, 5, "PW_Parse() ".Dumper($rmsg);
  383. $hash->{"MSGCNT"}++;
  384. $hash->{"TIME"} = TimeNow();
  385. $hash->{RAWMSG} = $rmsg;
  386. %addvals = (RAWMSG => $rmsg);
  387. Dispatch($iohash, $rmsg->{'dest'}, \%addvals);
  388. }
  389. #NeedEdit
  390. #####################################
  391. sub PW_Ready($)
  392. {
  393. my ($hash) = @_;
  394. return undef;
  395. return DevIo_OpenDev($hash, 1, "PW_Ready") if($hash->{STATE} eq "disconnected");
  396. # This is relevant for windows/USB only
  397. my $po = $hash->{USBDev};
  398. my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags) = $po->status;
  399. return ($InBytes>0);
  400. }
  401. ############# Plugwise-Tools
  402. sub Mywrite {
  403. my ( $hash, $cmd, $cb, $pri ) = @_;
  404. my $packet = "\05\05\03\03" . $cmd . _plugwise_crc($cmd) . "\r\n"; # "\05\05\03\03" .
  405. real_write($hash,$packet,$pri);
  406. }
  407. sub _plugwise_crc {
  408. my ( $data ) = @_;
  409. sprintf( "%04X", crc( $data, 16, 0, 0, 0, 0x1021, 0, 0 ) );
  410. }
  411. sub real_write {
  412. my ( $hash, $str, $pri ) = @_;
  413. if (!$pri) {$pri=0;}
  414. if (defined $str) {
  415. if ($pri==0) {
  416. push @buffer,$str;
  417. } else {
  418. unshift @buffer,$str;
  419. }
  420. }
  421. if ($self->{_awaiting_stick_response} == 1) {
  422. return undef;
  423. }
  424. $str=shift @buffer;
  425. DevIo_SimpleWrite($hash,$str,undef);
  426. $str=~s/\r\n//;
  427. $self->{_awaiting_stick_response} = 1;
  428. my $str2=AttrVal($hash->{NAME},"showCom","xyz");
  429. my $showcom=qr/$str2/;
  430. $str=~s/....([[:xdigit:]]{4})([[:xdigit:]]{4})(.*)/$1 $2 $3/g;
  431. if ($str =~ $showcom) {readingsSingleUpdate($hash,"communication", ">> $str",1)}
  432. readingsSingleUpdate($hash,"Buffer",@buffer,1);
  433. }
  434. # Print the data in hex
  435. sub _hexdump {
  436. my $s = shift;
  437. my $r = unpack 'H*', $s;
  438. $s =~ s/[^ -~]/./g;
  439. $r . ' ' . $s;
  440. }
  441. # This function processes a response received from the USB stick.
  442. #
  443. # In a first step, the ACK response from the stick is handled. This means that the
  444. # communication sequence number is captured, and a new entry is made in the response queue.
  445. #
  446. # Second step, if we receive an error response from the stick, pass this message back
  447. #
  448. # Finally, of course, decode actual useful messages and return their value to the caller
  449. #
  450. # The input to this function is the message with CRC, with the header and trailing part removed
  451. sub process_response {
  452. # my ( $hash, $frame ) = @_;
  453. my $hash= shift;
  454. my $frame= shift;
  455. if (!defined $frame||$frame eq '') {
  456. return undef
  457. }
  458. $frame =~ s/\x83*//g;
  459. Log3 $hash,5, "Response-Processing '$frame'";
  460. my $name=$hash->{NAME};
  461. my %xplmsg = ( schema => 'plugwise.basic', );
  462. # Check if the CRC matches
  463. if (!( _plugwise_crc( substr( $frame, 0, -4 ) ) eq
  464. substr( $frame, -4, 4 )
  465. )
  466. )
  467. {
  468. # Send out notification...
  469. #$xpl->ouch("PLUGWISE: received a frame with an invalid CRC");
  470. $xplmsg{dest}='none';
  471. $xplmsg{type} = 'err';
  472. $xplmsg{text}="Received frame with invalid CRC";
  473. $xplmsg{code} = $frame;
  474. return \%xplmsg;
  475. }
  476. #Switch:
  477. if ($testcount>=0){
  478. $testcount=$testcount+1;
  479. if ($testcount == 41) { $frame = "002403C1000D6F0002907DC90F09412E0006A17000856539070140264E0844C2030000";Log 3,"Insert 0024";}
  480. if ($testcount == 39) { $frame = "0061FFFE000D6F0002907DC90000";Log 3,"Insert 0061";}
  481. if ($testcount == 47) { $frame = "004FFFFE000D6F0002907DC9000000";Log 3,"Insert 004F";}
  482. if ($testcount == 53) { $frame = "0056FFFF000D6F0002907DC90101xxxx";Log 3,"Insert 0056";}
  483. if ($testcount == 56) { $frame = "0056FFFF000D6F0002907DC90100xxxx";Log 3,"Insert keypress";}
  484. if ($testcount == 62) { $frame = "0056FFFF000D6F0002907DC90201xxxx";Log 3,"Insert keypress";}
  485. if ($testcount == 69) { $frame = "0056FFFF000D6F0002907DC90200xxxx";Log 3,"Insert keypress";}
  486. # Circle
  487. # $testcount=$testcount+1;
  488. # if ($testcount == 40) { $frame = "0027527B000D6F0002907DC83F807E5AB5DCBDA03D74A00400000000xxxx";Log 3,"Insert Calibration";}
  489. # if ($testcount == 42) { $frame = "0024527C000D6F0002907DC80F097CA60006A95801856539070140264E0844C202xxxx";Log 3,"Insert Status";}
  490. # if ($testcount == 48) { $frame = "0013527E000D6F0002907DC800000000xxxx";Log 3,"Insert PowerInfo";}
  491. # if ($testcount == 54) { $frame = "0024527C000D6F0002907DC80F097CA60006A95800856539070140264E0844C202xxxx";Log 3,"Insert Status";}
  492. }
  493. # Strip CRC, we already know it is correct
  494. $frame =~ s/(.{4}$)//;
  495. # my $str2=AttrVal($hash->{NAME},"showCom","xyz");
  496. # my $showcom=qr/$str2/;
  497. # if ($frame =~ $showcom) {readingsSingleUpdate($hash,"communication", "<< $frame",1)}
  498. Log3 $hash,4,"Frame after CRC-strip: $frame";
  499. # After a command is sent to the stick, we first receive an 'ACK'. This 'ACK' contains a sequence number that we want to track and that notifies us of errors.
  500. if ( $frame =~ /^0000([[:xdigit:]]{4})([[:xdigit:]]{4})(.*)/ ) {
  501. # ack | seq. nr. || response code |
  502. my $seqnr = $1;
  503. $xplmsg{showCom}="<< 0000 $1 $2 $3";
  504. $xplmsg{dest}='none';
  505. $xplmsg{type} = 'stat';
  506. $xplmsg{code} = $frame;
  507. if ( $2 eq "00C1" ) { $xplmsg{text}="ack"; return \%xplmsg;}
  508. elsif ( $2 eq "00C2" ) { $xplmsg{text}="Error on Ack-Signal"; $xplmsg{type} = 'err';Log 3,Dumper(%xplmsg);return \%xplmsg;}
  509. #Mywrite($hash,"000A");
  510. elsif ( $2 eq "00E1" ) { $xplmsg{text}="Circle out of range"; $xplmsg{text}="ack";return \%xplmsg;}
  511. elsif ( $2 eq "00DE" ) {
  512. if ( $initdone == 0) {return undef};
  513. my $saddr = _addr_l2s($3);
  514. $xplmsg{dest}=$self->{_plugwise}->{circles}->{$saddr}->{type};
  515. $xplmsg{type} = 'output';
  516. $xplmsg{text}= 'off';
  517. $xplmsg{code} = $frame;
  518. $xplmsg{device} = $3;
  519. $xplmsg{short} = $saddr;
  520. return \%xplmsg;
  521. }
  522. elsif ( $2 eq "00D8" ) {
  523. if ( $initdone == 0) {return undef};
  524. my $saddr = _addr_l2s($3);
  525. $xplmsg{dest}=$self->{_plugwise}->{circles}->{$saddr}->{type};
  526. $xplmsg{type} = 'output';
  527. $xplmsg{text}= 'on';
  528. $xplmsg{code} = $frame;
  529. $xplmsg{device} = $3;
  530. $xplmsg{short} = $saddr;
  531. return \%xplmsg;
  532. }
  533. elsif ( $2 eq "00F9" ) { $xplmsg{text}="Clear group MAC-Table" ; return \%xplmsg;}
  534. elsif ( $2 eq "00FA" ) { $xplmsg{text}="Fill Switch-schedule" ; return \%xplmsg;}
  535. elsif ( $2 eq "00F7" ) { $xplmsg{text}="Request self-removal from network" ; return \%xplmsg;}
  536. elsif ( $2 eq "00F1" ) { $xplmsg{text}="Set broadcast-time interval" ; return \%xplmsg;}
  537. elsif ( $2 eq "00F5" ) { $xplmsg{text}="Set handle off" ; return \%xplmsg;}
  538. elsif ( $2 eq "00F4" ) { $xplmsg{text}="Set handle on" ; return \%xplmsg;}
  539. elsif ( $2 eq "00E6" ) { $xplmsg{text}="Set PN" ; return \%xplmsg;}
  540. elsif ( $2 eq "00F8" ) { $xplmsg{text}="Set powerrecording" ; return \%xplmsg;}
  541. elsif ( $2 eq "00BE" ) { $xplmsg{text}="Set scan-params ACK" ; return \%xplmsg;}
  542. elsif ( $2 eq "00BF" ) { $xplmsg{text}="Set scan-params NACK" ; $xplmsg{type} = 'err';return \%xplmsg;}
  543. elsif ( $2 eq "00B5" ) { $xplmsg{text}="Set sense-boundaries ACK" ; return \%xplmsg;}
  544. elsif ( $2 eq "00B6" ) { $xplmsg{text}="Set sense-boundaries NACK" ; $xplmsg{type} = 'err';return \%xplmsg;}
  545. elsif ( $2 eq "00B3" ) { $xplmsg{text}="Set sense-interval ACK" ; return \%xplmsg;}
  546. elsif ( $2 eq "00B4" ) { $xplmsg{text}="Set sense-interval NACK" ; $xplmsg{type} = 'err';return \%xplmsg;}
  547. elsif ( $2 eq "00F6" ) { $xplmsg{text}="Set sleep-behavior" ; return \%xplmsg;}
  548. elsif ( $2 eq "00E5" ) { $xplmsg{text}="Activate Switch-schedule on" ; return \%xplmsg;}
  549. elsif ( $2 eq "00E4" ) { $xplmsg{text}="Activate Switch-schedule off" ; return \%xplmsg;}
  550. elsif ( $2 eq "00DD" ) { $xplmsg{text}="Allow nodes to join ACK0" ; return \%xplmsg;}
  551. elsif ( $2 eq "00D9" ) { $xplmsg{text}="Allow nodes to join ACK1" ; return \%xplmsg;}
  552. elsif ( $2 eq "00C8" ) { $xplmsg{text}="Bootload aborted" ; $xplmsg{type} = 'err'; return \%xplmsg;}
  553. elsif ( $2 eq "00C9" ) { $xplmsg{text}="Bootload done" ; return \%xplmsg;}
  554. elsif ( $2 eq "00D5" ) { $xplmsg{text}="Cancel read Powermeter-Info Logdata" ; return \%xplmsg;}
  555. elsif ( $2 eq "00C4" ) { $xplmsg{text}="Cannot join network" ; $xplmsg{type} = 'err';return \%xplmsg;}
  556. elsif ( $2 eq "00C3" ) { $xplmsg{text}="Command not allowed" ; $xplmsg{type} = 'err';return \%xplmsg;}
  557. elsif ( $2 eq "00D1" ) { $xplmsg{text}="Done reading Powermeter-Info Logdata" ; return \%xplmsg;}
  558. elsif ( $2 eq "00C0" ) { $xplmsg{text}="Ember stack error" ; $xplmsg{type} = 'err';return \%xplmsg;}
  559. elsif ( $2 eq "00C5" ) { $xplmsg{text}="Exceeding Tableindex" ;$xplmsg{type} = 'err'; return \%xplmsg;}
  560. elsif ( $2 eq "00CF" ) { $xplmsg{text}="Flash erased" ; return \%xplmsg;}
  561. elsif ( $2 eq "00C6" ) { $xplmsg{text}="Flash error" ; $xplmsg{type} = 'err';return \%xplmsg;}
  562. elsif ( $2 eq "00ED" ) { $xplmsg{text}="Group-MAC added" ; return \%xplmsg;}
  563. elsif ( $2 eq "00EF" ) { $xplmsg{text}="Group-MAC not added" ; $xplmsg{type} = 'err'; return \%xplmsg;}
  564. elsif ( $2 eq "00F0" ) { $xplmsg{text}="Group-MAC not removed" ; $xplmsg{type} = 'err'; return \%xplmsg;}
  565. elsif ( $2 eq "00EE" ) { $xplmsg{text}="Group-MAC removed" ; return \%xplmsg;}
  566. elsif ( $2 eq "00E8" ) { $xplmsg{text}="Image activate ACK" ; return \%xplmsg;}
  567. elsif ( $2 eq "00CC" ) { $xplmsg{text}="Image check timeout" ; $xplmsg{type} = 'err'; return \%xplmsg;}
  568. elsif ( $2 eq "00CB" ) { $xplmsg{text}="Image invalid" ; $xplmsg{type} = 'err'; return \%xplmsg;}
  569. elsif ( $2 eq "00CA" ) { $xplmsg{text}="Image valid" ; return \%xplmsg;}
  570. elsif ( $2 eq "00C7" ) { $xplmsg{text}="Node-change accepted" ; return \%xplmsg;}
  571. elsif ( $2 eq "00CD" ) { $xplmsg{text}="Ping timeout 1sec" ; $xplmsg{type} = 'err'; return \%xplmsg;}
  572. elsif ( $2 eq "00EB" ) { $xplmsg{text}="Pingrun busy" ; return \%xplmsg;}
  573. elsif ( $2 eq "00EC" ) { $xplmsg{text}="Pingrun finished" ; return \%xplmsg;}
  574. elsif ( $2 eq "00CE" ) { $xplmsg{text}="Public network-info complete" ; return \%xplmsg;}
  575. elsif ( $2 eq "00D0" ) { $xplmsg{text}="Remote flash erased" ; return \%xplmsg;}
  576. elsif ( $2 eq "00F3" ) { $xplmsg{text}="Reply role changed NOK" ; $xplmsg{type} = 'err'; return \%xplmsg;}
  577. elsif ( $2 eq "00F2" ) { $xplmsg{text}="Reply role changed OK" ; return \%xplmsg;}
  578. elsif ( $2 eq "00E0" ) { $xplmsg{text}="Send switchblock NACK" ; $xplmsg{type} = 'err'; return \%xplmsg;}
  579. elsif ( $2 eq "00DA" ) { $xplmsg{text}="Send calib-params ACK" ; return \%xplmsg;}
  580. elsif ( $2 eq "00E2" ) { $xplmsg{text}="Set relais denied" ; $xplmsg{type} = 'err'; return \%xplmsg;}
  581. elsif ( $2 eq "00DF" ) { $xplmsg{text}="Set RTC-Data ACK" ; return \%xplmsg;}
  582. elsif ( $2 eq "00E7" ) { $xplmsg{text}="Set RTC-Data NACK" ; $xplmsg{type} = 'err'; return \%xplmsg;}
  583. elsif ( $2 eq "00D7" ) { $xplmsg{text}="Set year, month and flashadress DONE" ; return \%xplmsg;}
  584. elsif ( $2 eq "00BD" ) { $xplmsg{text}="Start Light-Calibration started" ; return \%xplmsg;}
  585. elsif ( $2 eq "00E9" ) { $xplmsg{text}="Start Pingrun ACK" ; return \%xplmsg;}
  586. elsif ( $2 eq "00EA" ) { $xplmsg{text}="Stop Pingrun ACK" ; return \%xplmsg;}
  587. elsif ( $2 eq "00DC" ) { $xplmsg{text}="Syncronize NC ACK" ; return \%xplmsg;}
  588. elsif ( $2 eq "00D6" ) { $xplmsg{text}="Timeout Powermeter Logdata" ; $xplmsg{type} = 'err'; return \%xplmsg;}
  589. else {
  590. if ( $initdone == 0) {return undef};
  591. $xplmsg{schema} = 'log.basic';
  592. # Default error message
  593. my $text = 'Received error response: $frame';
  594. my $error = $2;
  595. my $msg_causing_error = $frame;
  596. if ( $msg_causing_error =~ /^0026([[:xdigit:]]{16}$)/ ) {
  597. my $device = _addr_l2s($1);
  598. $text = "No calibration response received for $device";
  599. delete $self->{_plugwise}->{circles}->{$device};
  600. }
  601. Log3 $hash,3, "Received error response: $frame";
  602. $xplmsg{dest}='none';
  603. $xplmsg{type} = 'stat';
  604. $xplmsg{text}= $text;
  605. $xplmsg{code} = $frame . ":" . $error;
  606. return \%xplmsg;
  607. }
  608. }
  609. if ( $frame
  610. =~ /^0011([[:xdigit:]]{4})([[:xdigit:]]{16})([[:xdigit:]]{4})([[:xdigit:]]{16})([[:xdigit:]]{4})/
  611. )
  612. #0011 0063 000D6F00029014D 8010 14D0D6F00029C512 2BA4DFF4 6D2
  613. # init resp | seq. nr.|| stick MAC addr || don't care || network key || short key
  614. {
  615. $hash->{"STICK_MAC"} = $2;
  616. $hash->{"NET_KEY"} = $4;
  617. $self->{_plugwise}->{stick_MAC} = _addr_l2s( $2 );
  618. $self->{_plugwise}->{network_key} = $4;
  619. $self->{_plugwise}->{short_key} = $5;
  620. $self->{_plugwise}->{connected} = 1;
  621. $firstrun = 1;
  622. Log3 $hash,3, "PLUGWISE: Received a valid response to the init request from the Stick. Connected!";
  623. query_connected_circles($hash);
  624. $xplmsg{dest}='none';
  625. $xplmsg{type} = 'stat';
  626. $xplmsg{text}= 'Connected';
  627. $xplmsg{code} = $frame;
  628. $xplmsg{showCom}="<< 0011 $1 $2 $3 $4 $5";
  629. return \%xplmsg;
  630. }
  631. ##############################################################################
  632. ##### Heartbeat
  633. ##### 0061 ???? Circle-MAC CRC
  634. ##############################################################################
  635. if ( $frame =~ /^0061([[:xdigit:]]{4})([[:xdigit:]]{16})$/ ) {
  636. if ( $initdone == 0) {return undef};
  637. my $saddr = _addr_l2s($2);
  638. unless ($saddr ~~ $self->{_plugwise}->{circles}->{$saddr}) {
  639. Log3 $hash,3, "PLUGWISE:Heartbeat from Unknown Device $2";
  640. $self->{_plugwise}->{circles}->{ _addr_l2s( $2 ) } = {};
  641. Mywrite($hash, "0026" . $2 ,0);
  642. command($hash,'feature',_addr_l2s($2));
  643. $xplmsg{dest}='none';
  644. $xplmsg{type} = 'stat';
  645. $xplmsg{text}= 'Found circle';
  646. $xplmsg{code} = $frame;
  647. $xplmsg{device} = $2;
  648. $xplmsg{showCom}="<< 0061 $1 $2";
  649. $xplmsg{short} = $saddr;
  650. }
  651. return \%xplmsg;
  652. }
  653. # Process the response on a powerinfo request
  654. # powerinfo resp | seq. nr. || Circle MAC || pulse1 || pulse8 | other stuff we don't care about
  655. #0013 0051 000D6F0000994CAA 0000 FFFF 00000000 FFFFF DB9000D
  656. if ( $frame
  657. =~ /^0013([[:xdigit:]]{4})([[:xdigit:]]{16})([[:xdigit:]]{4})([[:xdigit:]]{4})/
  658. )
  659. {
  660. my $saddr = _addr_l2s($2);
  661. my $pulse1 = $3;
  662. my $pulse8 = $4;
  663. # Assign the values to the data hash
  664. $self->{_plugwise}->{circles}->{$saddr}->{pulse1} = $pulse1;
  665. $self->{_plugwise}->{circles}->{$saddr}->{pulse8} = $pulse8;
  666. $xplmsg{showCom}="<< 0013 $1 $2 $3 $4";
  667. if ($4 eq "FFFF") {
  668. $xplmsg{dest}='none';
  669. $xplmsg{type} = 'ignore';
  670. $xplmsg{text}= 'Ignored Spike';
  671. $xplmsg{code} = $frame;
  672. $xplmsg{device} = $2;
  673. $xplmsg{short} = $saddr;
  674. return \%xplmsg;
  675. }
  676. # Ensure we have the calibration info before we try to calc the power,
  677. # if we don't have it, return an error reponse
  678. if ( !defined $self->{_plugwise}->{circles}->{$saddr}->{gainA} ) {
  679. $xplmsg{dest}='none';
  680. $xplmsg{type} = 'err3';
  681. $xplmsg{text}= 'Report power failed, calibration data not retrieved yet';
  682. $xplmsg{code} = $frame;
  683. $xplmsg{device} = $2;
  684. $xplmsg{short} = $saddr;
  685. return \%xplmsg;
  686. }
  687. # Calculate the live power
  688. my ( $pow1, $pow8 ) = _calc_live_power($hash,$saddr);
  689. $xplmsg{dest}=$self->{_plugwise}->{circles}->{$saddr}->{type};
  690. $xplmsg{type} = 'power';
  691. $xplmsg{text}= ' ';
  692. $xplmsg{code} = $frame;
  693. $xplmsg{device} = $2;
  694. $xplmsg{short} = $saddr;
  695. $xplmsg{val1} = $pow1;
  696. $xplmsg{val2} = $pow8;
  697. $xplmsg{unit1} = 'W';
  698. $xplmsg{unit2} = 'W';
  699. return \%xplmsg;
  700. }
  701. # Process the response on a query known circles command
  702. # circle query resp| seq. nr. || Circle+ MAC || Circle MAC on || memory position
  703. if ( $frame
  704. =~ /^0019([[:xdigit:]]{4})([[:xdigit:]]{16})([[:xdigit:]]{16})([[:xdigit:]]{2})$/
  705. )
  706. {
  707. $xplmsg{showCom}="<< 0019 $1 $2 $3 $4";
  708. my $nr=sprintf( "%02X", AttrVal($hash->{NAME},"circlecount",50) -1);
  709. if ($4 eq $nr) {Log 3,$hash->{NAME} . "Init done, found ". (keys(%{$self->{_plugwise}->{circles}})) . " devices";$initdone=1}
  710. if ( $3 ne "FFFFFFFFFFFFFFFF" ) {
  711. $self->{_plugwise}->{circles}->{ _addr_l2s( $3 ) } = {};
  712. Mywrite($hash, "0026" . $3 ,0);
  713. }
  714. $xplmsg{schema} = 'log.basic';
  715. $xplmsg{dest}='none';
  716. $xplmsg{type} = 'stat';
  717. $xplmsg{text}='none';
  718. $xplmsg{text}= 'Found circle' if (defined $self->{_plugwise}->{circles}->{_addr_l2s($3)});
  719. $xplmsg{code} = $frame;
  720. $xplmsg{device} = $3;
  721. $xplmsg{short} = _addr_l2s($3);
  722. return \%xplmsg;
  723. }
  724. # Process the response on a status request
  725. # status response | seq. nr. || Circle+ MAC || year,mon, min || curr_log_addr || powerstate
  726. if ( $frame
  727. #0024 0050 000D6F0000994CAA 0F08595B 000440B 80 18 565390701402 24E0844C2 02
  728. =~ /^0024([[:xdigit:]]{4})([[:xdigit:]]{16})([[:xdigit:]]{8})([[:xdigit:]]{8})([[:xdigit:]]{2})([[:xdigit:]]{2})([[:xdigit:]]{12})([[:xdigit:]]{8})([[:xdigit:]]{2})/
  729. )
  730. {
  731. my $saddr = _addr_l2s($2);
  732. my $onoff = $5 eq '00' ? 'off' : 'on';
  733. my $current = $5 eq '00' ? 'LOW' : 'HIGH';
  734. $self->{_plugwise}->{circles}->{$saddr}->{onoff} = $onoff;
  735. if(!exists $PWType{$9}) {
  736. Log3 $name, 2, "$name: Autocreate: unknown familycode '$9' found. Please report this!";
  737. next;
  738. } else {
  739. # Log 3,"Device $saddr now is $PWType{$9}";
  740. $self->{_plugwise}->{circles}->{$saddr}->{type} = $PWType{$9};
  741. }
  742. # $self->{_plugwise}->{circles}->{$saddr}->{type} = 'Circle' if (hex($9) <= 2);
  743. # $self->{_plugwise}->{circles}->{$saddr}->{type} = 'Switch' if (hex($9) == 3 || hex($9) == 4);
  744. # $self->{_plugwise}->{circles}->{$saddr}->{type} = 'Sense' if (hex($9) == 5);
  745. # $self->{_plugwise}->{circles}->{$saddr}->{type} = 'Scan' if (hex($9) == 6);
  746. $self->{_plugwise}->{circles}->{$saddr}->{curr_logaddr} = ( hex($4) - 278528 ) / 8;
  747. Log 3, "Unknown Device-Code: $frame" if (!defined $self->{_plugwise}->{circles}->{$saddr}->{type});
  748. Log 3, "Unknown Circle: $saddr" if (!defined $self->{_plugwise}->{circles}->{$saddr});
  749. my $circle_date_time = _tstamp2time($hash,$3);
  750. $xplmsg{dest}=$self->{_plugwise}->{circles}->{$saddr}->{type};
  751. $xplmsg{type} = 'output';
  752. $xplmsg{text}= $onoff;
  753. $xplmsg{code} = $frame;
  754. $xplmsg{device} = $2;
  755. $xplmsg{short} = $saddr;
  756. $xplmsg{showCom}="<< 0024 $1 $2 $3 $4 $5 $6 $7 $8 $9";
  757. $xplmsg{val1} = $self->{_plugwise}->{circles}->{$saddr}->{curr_logaddr};
  758. $xplmsg{val2} = $circle_date_time;
  759. $xplmsg{val3} = 0;
  760. return \%xplmsg;
  761. }
  762. # Process the response on a calibration request
  763. if ( $frame
  764. =~ /^0027([[:xdigit:]]{4})([[:xdigit:]]{16})([[:xdigit:]]{8})([[:xdigit:]]{8})([[:xdigit:]]{8})([[:xdigit:]]{8})$/
  765. )
  766. {
  767. # calibration resp | seq. nr. || Circle+ MAC || gainA || gainB || offtot || offruis
  768. #print "Received for $2 calibration response!\n";
  769. my $saddr = _addr_l2s($2);
  770. #print "Short address = $saddr\n";
  771. Log3 $hash,5,"PLUGWISE: Received calibration reponse for circle $saddr";
  772. $self->{_plugwise}->{circles}->{$saddr}->{gainA}
  773. = _hex2float($3);
  774. $self->{_plugwise}->{circles}->{$saddr}->{gainB}
  775. = _hex2float($4);
  776. $self->{_plugwise}->{circles}->{$saddr}->{offtot}
  777. = _hex2float($5);
  778. $self->{_plugwise}->{circles}->{$saddr}->{offruis}
  779. = _hex2float($6);
  780. Log3 $hash,5,"$2 - Calib: $3 - $4 - $5 - $6";
  781. $lastcircle=$saddr;
  782. $xplmsg{dest}='none';
  783. $xplmsg{type} = 'stat';
  784. $xplmsg{text}= 'Calibration-Info received.';
  785. $xplmsg{showCom}="<< 0027 $1 $2 $3 $4 $5 $6";
  786. $xplmsg{code} = $frame;
  787. $xplmsg{device} = $2;
  788. $xplmsg{short} = $saddr;
  789. return \%xplmsg;
  790. }
  791. # Process a Feature-Request
  792. if ( $frame
  793. =~ /^0060([[:xdigit:]]{4})([[:xdigit:]]{16})([[:xdigit:]]{16})/
  794. )
  795. {
  796. my $s_id = _addr_l2s($2);
  797. $xplmsg{dest}='none';
  798. $xplmsg{showCom}="<< 0060 $1 $2 $3";
  799. $xplmsg{type} = 'stat';
  800. $xplmsg{text}= 'Features';
  801. $xplmsg{code} = $frame;
  802. $xplmsg{device} = $2;
  803. $xplmsg{short} = $s_id;
  804. $xplmsg{val1} = $3;
  805. Log3 $hash,5,Dumper(%xplmsg);
  806. Log3 $hash,3, "PLUGWISE: Features for $s_id are $3";
  807. return \%xplmsg;
  808. }
  809. # Process the response of TempHum-Sensor
  810. if ( $frame
  811. =~ /^0105([[:xdigit:]]{4})([[:xdigit:]]{16})([[:xdigit:]]{4})([[:xdigit:]]{4})/
  812. )
  813. {
  814. my $s_id = _addr_l2s($2);
  815. $xplmsg{dest}=$self->{_plugwise}->{circles}->{$s_id}->{type};
  816. $xplmsg{type} = 'humtemp';
  817. $xplmsg{showCom}="<< 0105 $1 $2 $3 $4";
  818. $xplmsg{text}= ' ';
  819. $xplmsg{code} = $frame;
  820. $xplmsg{device} = $2;
  821. $xplmsg{short} = $s_id;
  822. $xplmsg{val1} = (hex($3)-3145)/524.30;
  823. $xplmsg{val2} = (hex($4)-17473)/372.90;
  824. $xplmsg{unit1} = 'h';
  825. $xplmsg{unit2} = 'C';
  826. Log3 $hash,5,Dumper(%xplmsg);
  827. Log3 $hash,5, "PLUGWISE: Temperature for $s_id set";
  828. return \%xplmsg;
  829. }
  830. ## RemoveNode response
  831. if ( $frame
  832. =~ /^001D([[:xdigit:]]{4})([[:xdigit:]]{16})([[:xdigit:]]{16})([[:xdigit:]]{2})/
  833. )
  834. #001D 1026 000D6F00029C5122 000D6F00029C5122 00
  835. {
  836. Log3 $hash,3,"Removed Node $3 (Index $4) from Network.";
  837. $xplmsg{showCom}="<< 0000 $1 $2 $3 $4";
  838. $xplmsg{dest}='none';
  839. $xplmsg{type} = 'stat';
  840. $xplmsg{code} = $frame;
  841. $xplmsg{text} = 'Removed Node $3 (Index $4) from Network.';
  842. return \%xplmsg;
  843. }
  844. ## Keypress on Switch
  845. #0056FFFF000D6F0002769C7D0101
  846. if ( $frame
  847. =~ /^0056([[:xdigit:]]{4})([[:xdigit:]]{16})([[:xdigit:]]{2})([[:xdigit:]]{2})/
  848. )
  849. {
  850. Log3 $hash,4,"Keypress";
  851. my $s_id = _addr_l2s($2);
  852. $xplmsg{dest}=$self->{_plugwise}->{circles}->{$s_id}->{type};
  853. $xplmsg{type} = 'sense';
  854. $xplmsg{showCom}="<< 0056 $1 $2 $3 $4";
  855. $xplmsg{text}= ' ';
  856. $xplmsg{code} = $frame;
  857. $xplmsg{device} = $2;
  858. $xplmsg{short} = $s_id;
  859. $xplmsg{val1} = hex($4);
  860. if ($Make2Channels==0) {
  861. $xplmsg{val1} = hex($4); #+((hex($3)-1)<<1) if ($self->{_plugwise}->{circles}->{$s_id}->{type} eq "PW_Switch");
  862. $xplmsg{val2} = (hex($3)-1)<<1;
  863. } else {
  864. $xplmsg{val3} = hex($3);
  865. }
  866. Log3 $hash,5,Dumper(%xplmsg);
  867. Log3 $hash,5, "PLUGWISE: Motion-Signal detected";
  868. return \%xplmsg;
  869. }
  870. # Ping-Response
  871. if ( $frame
  872. =~ /^000E([[:xdigit:]]{4})([[:xdigit:]]{16})([[:xdigit:]]{2})([[:xdigit:]]{2})([[:xdigit:]]{4})/
  873. )
  874. {
  875. if ( $initdone == 0) {return undef};
  876. Log3 $hash,4,"ping";
  877. my $s_id = _addr_l2s($2);
  878. $xplmsg{dest}=$self->{_plugwise}->{circles}->{$s_id}->{type};
  879. $xplmsg{type} = 'ping';
  880. $xplmsg{showCom}="<< 004F $1 $2 $3 $4 $5";
  881. $xplmsg{text}= ' ';
  882. $xplmsg{code} = $frame;
  883. $xplmsg{device} = $2;
  884. $xplmsg{short} = $s_id;
  885. $xplmsg{val1} = hex($3);
  886. $xplmsg{val2} = hex($4);
  887. $xplmsg{val3} = hex($5);
  888. Log3 $hash,5,Dumper(%xplmsg);
  889. return \%xplmsg;
  890. }
  891. # Pushbuttons
  892. if ( $frame
  893. =~ /^004F([[:xdigit:]]{4})([[:xdigit:]]{16})([[:xdigit:]]{2})/
  894. )
  895. {
  896. if ( $initdone == 0) {return undef};
  897. Log3 $hash,4,"Keypress";
  898. my $s_id = _addr_l2s($2);
  899. $xplmsg{dest}=$self->{_plugwise}->{circles}->{$s_id}->{type};
  900. $xplmsg{type} = 'press';
  901. $xplmsg{showCom}="<< 004F $1 $2 $3";
  902. $xplmsg{text}= ' ';
  903. $xplmsg{code} = $frame;
  904. $xplmsg{device} = $2;
  905. $xplmsg{short} = $s_id;
  906. $xplmsg{val1} = hex($3);
  907. Log3 $hash,5,Dumper(%xplmsg);
  908. return \%xplmsg;
  909. }
  910. # Process the response on a historic buffer readout
  911. if ( $frame
  912. =~ /^0049([[:xdigit:]]{4})([[:xdigit:]]{16})([[:xdigit:]]{16})([[:xdigit:]]{16})([[:xdigit:]]{16})([[:xdigit:]]{16})([[:xdigit:]]{8})$/
  913. )
  914. {
  915. # history resp | seq. nr. || Circle+ MAC || info 1 || info 2 || info 3 || info 4 || address
  916. my $s_id = _addr_l2s($2);
  917. my $log_addr = ( hex($7) - 278528 ) / 8;
  918. $xplmsg{showCom}="<< 0049 $1 $2 $3 $4 $5 $6 $7";
  919. #print "Received history response for $2 and address $log_addr!\n";
  920. # Assign the values to the data hash
  921. $self->{_plugwise}->{circles}->{$s_id}->{history}->{logaddress}
  922. = $log_addr;
  923. $self->{_plugwise}->{circles}->{$s_id}->{history}->{info1} = $3;
  924. $self->{_plugwise}->{circles}->{$s_id}->{history}->{info2} = $4;
  925. $self->{_plugwise}->{circles}->{$s_id}->{history}->{info3} = $5;
  926. $self->{_plugwise}->{circles}->{$s_id}->{history}->{info4} = $6;
  927. # Ensure we have the calibration info before we try to calc the power,
  928. # if we don't have it, return an error reponse
  929. if ( !defined $self->{_plugwise}->{circles}->{$s_id}->{gainA} ) {
  930. #$xpl->ouch("Cannot report the power, calibration data not received yet for $s_id\n");
  931. $xplmsg{dest}='none';
  932. $xplmsg{type} = 'err';
  933. $xplmsg{text}= 'Report power failed, calibration data not retrieved yet';
  934. $xplmsg{showCom}="<< 0049 $1 $2 $3 $4 $5 $6 $7";
  935. $xplmsg{code} = $frame;
  936. $xplmsg{device} = $2;
  937. $xplmsg{short} = $s_id;
  938. return \%xplmsg;
  939. }
  940. my ( $tstamp, $energy ) = _report_history($hash,$s_id);
  941. # If the timestamp is no good, we tried to retrieve a field that contains no valid data, generate an error response
  942. if ( $tstamp eq "000000000000" ) {
  943. #$xpl->ouch("Cannot report the power for interval $log_addr of circle $s_id, it is in the future\n");
  944. $xplmsg{dest}='none';
  945. $xplmsg{type} = 'err';
  946. $xplmsg{text}= 'Report power failed, no valid data in time interval';
  947. $xplmsg{code} = $frame;
  948. $xplmsg{device} = $2;
  949. $xplmsg{short} = $s_id;
  950. $xplmsg{showCom}="<< 0049 $1 $2 $3 $4 $5 $6 $7";
  951. return \%xplmsg;
  952. }
  953. $xplmsg{dest}=$self->{_plugwise}->{circles}->{$s_id}->{type};
  954. $xplmsg{type} = 'energy';
  955. $xplmsg{text}= ' ';
  956. $xplmsg{code} = $frame;
  957. $xplmsg{device} = $2;
  958. $xplmsg{short} = $s_id;
  959. $xplmsg{val1} = $energy;
  960. $xplmsg{val2} = $tstamp;
  961. $xplmsg{val3} = $log_addr;
  962. $xplmsg{unit1} = 'kWh';
  963. Log3 $hash,5,Dumper(%xplmsg);
  964. Log3 $hash,5, "PLUGWISE: Historic energy for $s_id [$log_addr] is $energy kWh on $tstamp";
  965. return \%xplmsg;
  966. }
  967. # We should not get here unless we receive responses that are not implemented...
  968. #$xpl->ouch("Received unknown response: '$frame'");
  969. Log3 $hash,3,"PLUGWISE: Unknown Frame received: $frame - Please report this";
  970. $xplmsg{dest}='none';
  971. $xplmsg{type} = 'err2';
  972. $xplmsg{text}= 'Unknown Frame received';
  973. $xplmsg{code} = $frame;
  974. return \%xplmsg;
  975. }
  976. sub command {
  977. my ( $hash, $command, $target, $parameter ) = @_;
  978. Log3 $hash,5,"Command=$command - Target=$target";
  979. if ( !defined($command) || !defined($target) ) {
  980. Log3 $hash,3,"A command to the stick needs a command and a target ID as parameter";
  981. return 0;
  982. }
  983. #Log 3,"Set $self->{_plugwise}->{circles}->{$target}->{type} $target $command to $parameter";
  984. my $packet = "";
  985. my $pri=0;
  986. if ( defined $target ) {
  987. # Commands that target a specific device might need to be sent multiple times
  988. # if multiple devices are defined
  989. my $circle = uc($target);
  990. if ( $command =~ /(on|off)/ ) {
  991. if ($self->{_plugwise}->{circles}->{$circle}->{type} eq "PW_Circle") {
  992. $packet = "0017" . _addr_s2l($circle) . ($1 eq 'on' ? '01' : '00');
  993. } elsif($self->{_plugwise}->{circles}->{$circle}->{type} eq "PW_Switch"){
  994. # Log 3,"Set Switch $circle $parameter to $1";
  995. if ($parameter eq "left") {
  996. $packet = "0017" . _addr_s2l($circle) . "01" . $1 eq 'on' ? '01' : '00';
  997. } elsif ($parameter eq "right") {
  998. $packet = "0017" . _addr_s2l($circle) . "02" . $1 eq 'on' ? '01' : '00';
  999. }
  1000. }
  1001. $pri=1;
  1002. }
  1003. elsif ($command eq "feature") {
  1004. $packet = "005F" . _addr_s2l($circle);
  1005. }
  1006. elsif ($command eq "ping") {
  1007. $packet = "000D" . _addr_s2l($circle);
  1008. }
  1009. elsif ( $command eq 'syncTime' ) {
  1010. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  1011. $packet = "0016" .
  1012. _addr_s2l($circle) .
  1013. sprintf( "%02X", $year-100) .
  1014. sprintf( "%02X", $mon) .
  1015. sprintf( "%04X", ($mday * 24 * 60) + ($hour * 60) + $min) .
  1016. "FFFFFFFF" .
  1017. sprintf( "%02X", $hour) . sprintf( "%02X", $min) . sprintf( "%02X", $sec) . sprintf( "%02X", $wday) ;
  1018. # Log3 $hash,3,"syncTime-Frame: $packet";
  1019. # return (undef);
  1020. }
  1021. elsif ( $command eq 'status' ) {
  1022. $packet = "0023" . _addr_s2l($circle);
  1023. }
  1024. elsif ($command eq 'removeNode') {
  1025. $packet = "001C" . _addr_s2l( $self->{_plugwise}->{coordinator_MAC} ) . _addr_s2l($circle);
  1026. }
  1027. elsif ( $command eq 'livepower' ) {
  1028. # Ensure we have the calibration readings before we send the read command
  1029. # because the processing of the response of the read command required the
  1030. # calibration readings output to calculate the actual power
  1031. # Log3 $hash,3,Dumper( $self->{_plugwise});
  1032. if (!defined(
  1033. $self->{_plugwise}->{circles}->{$circle}->{offruis}
  1034. )
  1035. )
  1036. {
  1037. my $longaddr = _addr_s2l($circle);
  1038. Mywrite( $hash,"0026" . $longaddr ,0)
  1039. ; #, "Request calibration info");
  1040. }
  1041. $packet = "0012" . _addr_s2l($circle);
  1042. }
  1043. elsif ( $command eq 'history' ) {
  1044. # Ensure we have the calibration readings before we send the read command
  1045. # because the processing of the response of the read command required the
  1046. # calibration readings output to calculate the actual power
  1047. if (!defined(
  1048. $self->{_plugwise}->{circles}->{$circle}->{offruis}
  1049. )
  1050. )
  1051. {
  1052. my $longaddr = _addr_s2l($circle);
  1053. Mywrite($hash, "0026" . $longaddr ,0)
  1054. ; #, "Request calibration info");
  1055. }
  1056. if ( !defined $parameter ) {
  1057. Log3 $hash,3,"The 'history' command needs both a Circle ID and an address to read...";
  1058. return 0;
  1059. }
  1060. Log3 $hash,5,"requesting Log for $parameter";
  1061. my $address = ($parameter * 8) + 278528;#* 8 + 278528;
  1062. $packet
  1063. = "0048"
  1064. . _addr_s2l($circle)
  1065. . sprintf( "%08X", $address );
  1066. Log3 $hash,5,"Write command: $packet";
  1067. }
  1068. else {
  1069. Log3 $hash,3,"Received invalid command '$command'";
  1070. return 0;
  1071. }
  1072. # Send the packet to the stick!
  1073. Log3 $hash,5,"Write command: $packet";
  1074. Mywrite($hash,$packet,$pri) if ( defined $packet );
  1075. }
  1076. }
  1077. # Interrogate the network coordinator (Circle+) for all connected Circles
  1078. # This sub will generate the requests, and then the response parser function
  1079. # will generate a hash with all known circles
  1080. # When a circle is detected, a calibration request is sent to ge the relevant info
  1081. # required to calculate the power information.
  1082. # Circle info goes into a global hash like this:
  1083. # $object->{_plugwise}->{circles}
  1084. # A single circle entry contains the short id and the following info:
  1085. # short_id => { gainA => xxx,
  1086. # gainB => xxx,
  1087. # offtot => xxx,
  1088. # offruis => xxx }
  1089. sub query_connected_circles {
  1090. my ($hash) = @_;
  1091. # In this code we will scan all connected circles to be able to add them to the $self->{_plugwise}->{circles} hash
  1092. my $index = 0;
  1093. Log3 $hash,5,$hash->{NAME} . " - Looking for Circles.....";
  1094. # Interrogate the Circle+ and add its info into the circles hash
  1095. $self->{_plugwise}->{coordinator_MAC}
  1096. = _addr_l2s( $self->{_plugwise}->{network_key} );
  1097. $self->{_plugwise}->{circles} = {}; # Reset known circles hash
  1098. $self->{_plugwise}->{circles}->{ _addr_l2s( $self->{_plugwise}->{network_key} ) }
  1099. = {}; # Add entry for Circle+
  1100. Mywrite( $hash, "0026" . _addr_s2l( $self->{_plugwise}->{coordinator_MAC} ) ,0);
  1101. # Interrogate the first x connected devices
  1102. while ( $index < AttrVal($hash->{NAME},"circlecount",50) ) {
  1103. my $strindex = sprintf( "%02X", $index++ );
  1104. my $packet
  1105. = "0018"
  1106. . _addr_s2l( $self->{_plugwise}->{coordinator_MAC} )
  1107. . $strindex;
  1108. Mywrite($hash,$packet,0); #, "Query connected device $strindex");
  1109. }
  1110. return;
  1111. }
  1112. # Convert the long Circle address notation to short
  1113. sub _addr_l2s {
  1114. my ( $address ) = @_;
  1115. my $saddr = substr( $address, -8, 8 );
  1116. # We will return at least 6 bytes, more if required
  1117. # This is to keep compatibility with existing code that only supports 6 byte short addresses
  1118. return sprintf( "%06X", hex($saddr) );
  1119. }
  1120. # Convert the short Circle address notation to long
  1121. sub _addr_s2l {
  1122. my ( $address ) = @_;
  1123. # Log 3,Dumper(caller) if ($address eq 0xffffffff);
  1124. return "000D6F00" . sprintf( "%08X", hex($address) );
  1125. }
  1126. # Convert hex values to float for power readout
  1127. sub _hex2float {
  1128. my ( $hexstr ) = @_;
  1129. my $floater = unpack( 'f', reverse pack( 'H*', $hexstr ) );
  1130. return $floater;
  1131. }
  1132. sub _report_history {
  1133. my ( $hash, $id ) = @_;
  1134. # Get the first data entry
  1135. my $data = $self->{_plugwise}->{circles}->{$id}->{history}->{info1};
  1136. my $energy = 0;
  1137. my $tstamp = 0;
  1138. if ( $data =~ /^([[:xdigit:]]{8})([[:xdigit:]]{8})$/ ) {
  1139. # Calculate Wh
  1140. my $corrected_pulses = _pulsecorrection( $hash,$id, hex($2) );
  1141. $energy = $corrected_pulses / 3600 / 468.9385193 * 1000;
  1142. $tstamp = _tstamp2time($hash,$1);
  1143. # Round to 1 Wh
  1144. $energy = sprintf($attr{$hash->{NAME}}{WattFormat},$energy);
  1145. # Report kWh
  1146. # $energy = $energy / 1000;
  1147. #print "info1 date: $tstamp, energy $energy kWh\n";
  1148. }
  1149. return ( $tstamp, $energy );
  1150. }
  1151. # Convert a Plugwise timestamp to a human-readable format
  1152. sub _tstamp2time {
  1153. my ( $hash, $tstamp ) = @_;
  1154. # Return empty time on empty timestamp
  1155. return "000000000000" if ( $tstamp eq "FFFFFFFF" );
  1156. # Convert
  1157. if ( $tstamp =~ /([[:xdigit:]]{2})([[:xdigit:]]{2})([[:xdigit:]]{4})/ ) {
  1158. my $circle_date = sprintf( "%04i-%02i-%02i",
  1159. 2000 + hex($1),
  1160. hex($2), int( hex($3) / 60 / 24 ) + 1 );
  1161. my $circle_time = hex($3) % ( 60 * 24 );
  1162. my $circle_hours = int( $circle_time / 60 );
  1163. my $circle_minutes = $circle_time % 60;
  1164. $circle_time = sprintf( " %02i:%02i", $circle_hours, $circle_minutes );
  1165. return $circle_date . $circle_time;
  1166. }
  1167. else {
  1168. return "000000000000";
  1169. }
  1170. }
  1171. # Calculate the live power consumption from the last report.
  1172. sub _calc_live_power {
  1173. my ( $hash, $id ) = @_;
  1174. #my ($pulse1, $pulse8) = $self->pulsecorrection($id);
  1175. my $pulse1 = _pulsecorrection( $hash,$id,
  1176. hex( $self->{_plugwise}->{circles}->{$id}->{pulse1} ) );
  1177. my $pulse8 = _pulsecorrection( $hash,$id,
  1178. hex( $self->{_plugwise}->{circles}->{$id}->{pulse8} ) /8 );
  1179. my $live1 = $pulse1 * 1000 / 468.9385193;
  1180. my $live8 = $pulse8 * 1000 / 468.9385193;
  1181. # Round
  1182. $live1 = sprintf($attr{$hash->{NAME}}{WattFormat},$live1);
  1183. $live8 = sprintf($attr{$hash->{NAME}}{WattFormat},$live8);
  1184. return ( $live1, $live8 );
  1185. }
  1186. # Correct the reported number of pulses based on the calibration values
  1187. sub _pulsecorrection {
  1188. my ( $hash, $id, $pulses ) = @_;
  1189. # Get the calibration values for the circle
  1190. my $offnoise = $self->{_plugwise}->{circles}->{$id}->{offruis};
  1191. my $offtot = $self->{_plugwise}->{circles}->{$id}->{offtot};
  1192. my $gainA = $self->{_plugwise}->{circles}->{$id}->{gainA};
  1193. my $gainB = $self->{_plugwise}->{circles}->{$id}->{gainB};
  1194. # Correct the pulses with the calibration data
  1195. my $out
  1196. = ( ( $pulses + $offnoise ) ^ 2 ) * $gainB
  1197. + ( ( $pulses + $offnoise ) * $gainA )
  1198. + $offtot;
  1199. # Never report negative values, can happen with really small values
  1200. $out = 0 if ( $out < 0 );
  1201. return $out;
  1202. }
  1203. "Cogito, ergo sum.";
  1204. =pod
  1205. =item device
  1206. =item summary Module for controling Plugwise-Devices
  1207. =item summary_DE Modul für das Plugwise-System
  1208. =begin html
  1209. <a name="Plugwise"></a>
  1210. <h3>Plugwise</h3>
  1211. <ul>
  1212. This module is for the Plugwise-System.
  1213. <br>
  1214. Note: this module requires the Device::SerialPort or Win32::SerialPort module
  1215. if the devices is connected via USB or a serial port.
  1216. Also needed: digest:CRC
  1217. You can install these modules using CPAN.
  1218. <br><br>
  1219. <b>Define</b>
  1220. <ul>
  1221. <code>define &lt;name&gt; Plugwise &lt;device&gt; </code><br>
  1222. </ul>
  1223. <br>
  1224. &lt;device&gt; specifies the serial port to communicate with the Plugwise-Stick.
  1225. Normally on Linux the device will be named /dev/ttyUSBx, where x is a number.
  1226. For example /dev/ttyUSB0. Please note that the Plugwise-Stick normally operates at 115200 baud. You may specify the baudrate used after the @ char.<br>
  1227. <br>
  1228. Example: <br>
  1229. <code>define myPlugwise Plugwise /dev/ttyPlugwise@115200</code>
  1230. <br>
  1231. </ul>
  1232. <br>
  1233. <a name="PLUGWISEset"></a>
  1234. <b>Set</b>
  1235. <ul>
  1236. <code>Scan_Circles</code>
  1237. <ul>
  1238. Initiates a scan for new devices and defines them.
  1239. </ul><br><br>
  1240. <code>syncTime</code>
  1241. <ul>
  1242. Syncs all reachable devices to the system-time.
  1243. </ul><br><br>
  1244. <code>reOpen</code>
  1245. <ul>
  1246. Closes and reopens the serial-Port. (useful in case of to many Errors)
  1247. </ul><br><br>
  1248. </ul>
  1249. <br><br>
  1250. <b>Attributes</b>
  1251. <ul>
  1252. <code>circlecount</code><br>
  1253. <ul>
  1254. Max. Number of Circles to be found by the Scan-Command
  1255. <br><br>
  1256. </ul>
  1257. <code>interval</code><br>
  1258. <ul>standard polling-interval for new Circles
  1259. </ul><br><br>
  1260. <code>autosync</code><br>
  1261. <ul>Sends every n seconds a SyncTime to each device
  1262. </ul><br><br>
  1263. <code>WattFormat</code><br>
  1264. <ul>A string representing the format of the power-readings.
  1265. If not defined, it defaults to %0.f
  1266. </ul><br><br>
  1267. <code>showCom</code><br>
  1268. <ul>Writes the complete communication matching a RegEx into the reading "communication"
  1269. (can be viewed in EventMonitor or used with a FileLog)
  1270. </ul><br><br>
  1271. <br>
  1272. </ul>
  1273. =end html
  1274. =begin html_DE
  1275. <a name="Plugwise"></a>
  1276. <h3>Plugwise</h3>
  1277. <ul>
  1278. Modul für das Plugwise-System.
  1279. <br>
  1280. Achtung: Dieses Modul benötigt folgende Perl-Module:
  1281. <ul><li>Device::SerialPort oder Win32::SerialPort</li>
  1282. <li>digest:CRC</li></ul>
  1283. <br><br>
  1284. <b>Define</b>
  1285. <ul>
  1286. <code>define &lt;name&gt; Plugwise &lt;device&gt; </code><br>
  1287. </ul>
  1288. <br>
  1289. &lt;device&gt; Gibt den COM-Port des Plugwise-Stick an.
  1290. Unter Linux ist dies im Normalfall /dev/ttyUSBx, wobei x eine fortlaufende Nummer ist. (zB /dev/ttyUSB0)
  1291. Wobei es unter Linux sinnvoller ist, den Port mittels UDEV-Regeln oder mittels /dev/by-id/ anzugeben.
  1292. Der Plugwise-Stick läuft fix auf 115200 Baud<br>
  1293. <br>
  1294. Beispiel: <br>
  1295. <code>define myPlugwise Plugwise /dev/ttyPlugwise</code>
  1296. <br>
  1297. </ul>
  1298. <br>
  1299. <a name="PLUGWISEset"></a>
  1300. <b>Set</b>
  1301. <ul>
  1302. <code>Scan_Circles</code>
  1303. <ul>
  1304. Startet eine Suche nach neuen Geräten und legt diese per Autocreate an.
  1305. </ul><br><br>
  1306. <code>syncTime</code>
  1307. <ul>
  1308. Syncronisiert die internen RTCs der Geräte mit der aktuellen Systemzeit.
  1309. </ul><br><br>
  1310. <code>reOpen</code>
  1311. <ul>
  1312. Öffnet den COM-Port neu (zB bei zu vielen Fehlern, nach deren Behebung)
  1313. </ul><br><br>
  1314. </ul>
  1315. <br><br>
  1316. <b>Attribute</b>
  1317. <ul>
  1318. <code>circlecount</code><br>
  1319. <ul>
  1320. Maximale Anzahl der Geräte, nach denengesucht wird.
  1321. <br><br>
  1322. </ul>
  1323. <code>interval</code><br>
  1324. <ul>Standard-Abfrageintervall der Circles
  1325. </ul><br><br>
  1326. <code>autosync</code><br>
  1327. <ul>Sendet alle >n< Sekunden ein "syncTime" an alle Geräte
  1328. </ul><br><br>
  1329. <code>WattFormat</code><br>
  1330. <ul>String, mit welchem die Power-Readings formatiert werden
  1331. Standard: %0.f
  1332. </ul><br><br>
  1333. <code>showCom</code><br>
  1334. <ul>Schreibt die gesamte Kommunikation (gefiltern nach >regEx<) in das Reading "communication"
  1335. (Am besten mit FileLog oder dem Eventmonitor anzusehen)
  1336. </ul><br><br>
  1337. <br>
  1338. </ul>
  1339. =end html
  1340. =cut