10_IT.pm 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736
  1. ######################################################
  2. # InterTechno Switch Manager as FHM-Module
  3. #
  4. # (c) Olaf Droegehorn / DHS-Computertechnik GmbH
  5. # (c) Björn Hempel
  6. #
  7. # Published under GNU GPL License
  8. #
  9. # $Id: 10_IT.pm 13196 2017-01-22 20:27:22Z bjoernh $
  10. #
  11. ######################################################
  12. package main;
  13. use strict;
  14. use warnings;
  15. #use Data::Dumper qw(Dumper);
  16. use SetExtensions;
  17. my %codes = (
  18. "XMIToff" => "off",
  19. "XMITon" => "on", # Set to previous dim value (before switching it off)
  20. "00" => "off",
  21. "01" => "dim06%",
  22. "02" => "dim12%",
  23. "03" => "dim18%",
  24. "04" => "dim25%",
  25. "05" => "dim31%",
  26. "06" => "dim37%",
  27. "07" => "dim43%",
  28. "08" => "dim50%",
  29. "09" => "dim56%",
  30. "0a" => "dim62%",
  31. "0b" => "dim68%",
  32. "0c" => "dim75%",
  33. "0d" => "dim81%",
  34. "0e" => "dim87%",
  35. "0f" => "dim93%",
  36. "10" => "dim100%",
  37. "XMITdimup" => "dimup",
  38. "XMITdimdown" => "dimdown",
  39. "99" => "on-till",
  40. );
  41. my %codes_he800 = (
  42. "XMIToff" => "off",
  43. "XMITon" => "on", # Set to previous dim value (before switching it off)
  44. "00" => "off",
  45. #"01" => "last-dim-on",
  46. "02" => "dim12%",
  47. "03" => "dim25%",
  48. "04" => "dim37%",
  49. "05" => "dim50%",
  50. "06" => "dim62%",
  51. "07" => "dim75%",
  52. "08" => "dim87%",
  53. "09" => "dim100%",
  54. "XMITdimup" => "dimup",
  55. "XMITdimdown" => "dimdown",
  56. "99" => "on-till",
  57. );
  58. my %it_c2b;
  59. my %it_c2b_he800;
  60. my $it_defrepetition = 6; ## Default number of InterTechno Repetitions
  61. my %models = (
  62. itremote => 'sender',
  63. itswitch => 'simple',
  64. itdimmer => 'dimmer',
  65. ev1527 => 'ev1527',
  66. );
  67. my %bintotristate=(
  68. "00" => "0",
  69. "01" => "F",
  70. "10" => "D",
  71. "11" => "1"
  72. );
  73. my %bintotristateV3=(
  74. "10" => "1",
  75. "01" => "0",
  76. "00" => "D"
  77. );
  78. my %bintotristateHE=(
  79. "10" => "1",
  80. "01" => "0",
  81. "11" => "2",
  82. "00" => "D"
  83. );
  84. my %ev_action = (
  85. "on" => "0011",
  86. "off" => "0000"
  87. );
  88. sub bin2dec {
  89. unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
  90. }
  91. sub bin2dec64 {
  92. unpack("N", pack("B32", substr("0" x 64 . shift, -64)));
  93. }
  94. sub
  95. IT_Initialize($)
  96. {
  97. my ($hash) = @_;
  98. foreach my $k (keys %codes) {
  99. $it_c2b{$codes{$k}} = $k;
  100. }
  101. foreach my $k (keys %codes_he800) {
  102. $it_c2b_he800{$codes_he800{$k}} = $k;
  103. }
  104. $hash->{Match} = "^i......";
  105. $hash->{SetFn} = "IT_Set";
  106. #$hash->{StateFn} = "IT_SetState";
  107. $hash->{DefFn} = "IT_Define";
  108. $hash->{UndefFn} = "IT_Undef";
  109. $hash->{ParseFn} = "IT_Parse";
  110. $hash->{AttrFn} = "IT_Attr";
  111. $hash->{AttrList} = "IODev ITfrequency ITrepetition ITclock switch_rfmode:1,0 do_not_notify:1,0 ignore:0,1 protocol:V1,V3,HE_EU,SBC_FreeTec,HE800 SIGNALduinoProtocolId userV1setCodes unit group dummy:1,0 " .
  112. "$readingFnAttributes " .
  113. "model:".join(",", sort keys %models);
  114. $hash->{AutoCreate}=
  115. { "IT.*" => { GPLOT => "", FILTER => "%NAME", autocreateThreshold => "2:30"} };
  116. }
  117. #####################################
  118. sub
  119. IT_SetState($$$$)
  120. {
  121. my ($hash, $tim, $vt, $val) = @_;
  122. return undef;
  123. $val = $1 if($val =~ m/^(.*) \d+$/);
  124. return "Undefined value $val" if(!defined($it_c2b{$val}));
  125. }
  126. #############################
  127. sub
  128. IT_Do_On_Till($@)
  129. {
  130. my ($hash, $name, @a) = @_;
  131. return "Timespec (HH:MM[:SS]) needed for the on-till command" if(@a != 3);
  132. my ($err, $hr, $min, $sec, $fn) = GetTimeSpec($a[2]);
  133. return $err if($err);
  134. my @lt = localtime;
  135. my $hms_till = sprintf("%02d:%02d:%02d", $hr, $min, $sec);
  136. my $hms_now = sprintf("%02d:%02d:%02d", $lt[2], $lt[1], $lt[0]);
  137. if($hms_now ge $hms_till) {
  138. Log 4, "on-till: won't switch as now ($hms_now) is later than $hms_till";
  139. return "";
  140. }
  141. my @b = ("on");
  142. IT_Set($hash, $name, @b);
  143. my $tname = $hash->{NAME} . "_till";
  144. CommandDelete(undef, $tname) if($defs{$tname});
  145. CommandDefine(undef, "$tname at $hms_till set $name off");
  146. }
  147. ###################################
  148. sub
  149. IT_Set($@)
  150. {
  151. my ($hash, $name, @a) = @_;
  152. my $ret = undef;
  153. my $na = int(@a);
  154. my $message;
  155. return "no set value specified" if($na < 1);
  156. # return, if this is a dummy device
  157. return "Dummydevice $hash->{NAME}: will not set data" if(IsDummy($hash->{NAME}));
  158. my $list = "";
  159. $list .= "off:noArg on:noArg " if( AttrVal($name, "model", "") ne "itremote" );
  160. if ($hash->{userV1setCodes}) {
  161. if ($hash->{READINGS}{protocol}{VAL} eq "EV1527" || $hash->{READINGS}{protocol}{VAL} eq "V1") {
  162. foreach my $setCode (keys %{$hash->{userV1setCodes}}) {
  163. $list .= "$setCode:noArg ";
  164. }
  165. }
  166. }
  167. my $c = $it_c2b{$a[0]};
  168. if ($hash->{READINGS}{protocol}{VAL} eq "V3") {
  169. if($na > 1 && $a[0] eq "dim") {
  170. $a[0] = ($a[1] eq "0" ? "off" : sprintf("dim%02d%%",$a[1]) );
  171. splice @a, 1, 1;
  172. $na = int(@a);
  173. } elsif ($na == 2 && ($a[0] =~ /dim/)) {
  174. return "Bad time spec" if($na == 2 && $a[1] !~ m/^\d*\.?\d+$/);
  175. my $val;
  176. #$a[0] = ($a[1] eq "0" ? "off" : sprintf("dim%02d%%",$a[1]) );
  177. #splice @a, 1, 1;
  178. #$na = int(@a);
  179. if($na == 2) { # Timed command.
  180. $c = sprintf("%02X", (hex($c) | 0x20)); # Set the extension bit
  181. ########################
  182. # Calculating the time.
  183. LOOP: for(my $i = 0; $i <= 12; $i++) {
  184. for(my $j = 0; $j <= 15; $j++) {
  185. $val = (2**$i)*$j*0.25;
  186. if($val >= $a[1]) {
  187. if($val != $a[1]) {
  188. Log3 $name, 2, "$name: changing timeout to $val from $a[1]";
  189. }
  190. $c .= sprintf("%x%x", $i, $j);
  191. last LOOP;
  192. }
  193. }
  194. }
  195. Log3 $hash ,2, "$name: NOT Implemented now!";
  196. return "Specified timeout too large, max is 15360" if(length($c) == 2);
  197. }
  198. }
  199. $list = (join(" ", sort keys %it_c2b) . " dim:slider,0,6.25,100")
  200. if( AttrVal($name, "model", "") eq "itdimmer" );
  201. } elsif ($hash->{READINGS}{protocol}{VAL} eq "HE800") {
  202. $c = $it_c2b_he800{$a[0]};
  203. if($na > 1 && $a[0] eq "dim") {
  204. $a[0] = ($a[1] eq "0" ? "off" : sprintf("dim%02d%%",$a[1]) );
  205. splice @a, 1, 1;
  206. $na = int(@a);
  207. }
  208. $list = (join(" ", sort keys %it_c2b_he800) . " dim:slider,0,12.5,100")
  209. if( AttrVal($name, "model", "") eq "itdimmer" );
  210. } else {
  211. $list .= "dimup:noArg dimdown:noArg on-till" if( AttrVal($name, "model", "") eq "itdimmer" );
  212. }
  213. #if ($hash->{READINGS}{protocol}{VAL} eq "HE800") {
  214. # $list .= " learn_on_codes:noArg learn_off_codes:noArg";
  215. #}
  216. return SetExtensions($hash, $list, $name, @a) if( $a[0] eq "?" );
  217. return SetExtensions($hash, $list, $name, @a) if( !grep( $_ =~ /^\Q$a[0]\E($|:)/, split( ' ', $list ) ) );
  218. return IT_Do_On_Till($hash, $name, @a) if($a[0] eq "on-till");
  219. return "Bad time spec" if($na == 2 && $a[1] !~ m/^\d*\.?\d+$/);
  220. my $io = $hash->{IODev};
  221. my $v = $name ." ". join(" ", @a);
  222. ## Log that we are going to switch InterTechno
  223. Log3 $hash, 3, "$io->{NAME} IT_set: $v";
  224. my (undef, $cmd) = split(" ", $v, 2); # Not interested in the name...
  225. # Look for all devices with the same code, and set state, timestamp
  226. my $code;
  227. if ($hash->{READINGS}{protocol}{VAL} eq "EV1527") { # beim EV1527 darf der code nicht aus dem $hash->{XMIT} geholt werden
  228. $code = "$hash->{CODE}{1}";
  229. } else {
  230. $code = "$hash->{XMIT}";
  231. }
  232. foreach my $n (keys %{ $modules{IT}{defptr}{$code} }) {
  233. my $lh = $modules{IT}{defptr}{$code}{$n};
  234. #$lh->{STATE} = $cmd;
  235. if ($hash->{READINGS}{protocol}{VAL} eq "HE800") {
  236. my $count = $hash->{"count"};
  237. $count = $count + 1;
  238. if ($count > 3) {
  239. $count = 0;
  240. }
  241. $hash->{"count"} = $count;
  242. # }
  243. }
  244. if ($hash->{READINGS}{protocol}{VAL} eq "V3" || $hash->{READINGS}{protocol}{VAL} eq "HE800") {
  245. if( AttrVal($name, "model", "") eq "itdimmer" ) {
  246. if ($cmd eq "on") {
  247. my $lastDimVal = $hash->{READINGS}{lastDimValue}{VAL};
  248. if ($lastDimVal ne "") {
  249. #$cmd = $lastDimVal;
  250. #readingsSingleUpdate($lh, "state", $lastDimVal,1);
  251. readingsSingleUpdate($lh, "dim", substr($lastDimVal, 3, -1),1);
  252. } else {
  253. readingsSingleUpdate($lh, "dim", "100",1);
  254. }
  255. readingsSingleUpdate($lh, "state", "on",1);
  256. } elsif ($cmd eq "off") {
  257. readingsSingleUpdate($lh, "dim", "0",1);
  258. readingsSingleUpdate($lh, "state", "off",1);
  259. } else {
  260. if ($cmd eq "dim100%") {
  261. $lh->{STATE} = "on";
  262. readingsSingleUpdate($lh, "state", "on",1);
  263. } elsif ($cmd eq "dim00%") {
  264. $lh->{STATE} = "off";
  265. readingsSingleUpdate($lh, "lastDimValue", "",1);
  266. readingsSingleUpdate($lh, "state", "off",1);
  267. #} elsif ($cmd eq "last-dim-on") {
  268. # $cmd = AttrVal($name, "lastDimValue", "");
  269. # readingsSingleUpdate($lh, "state", $cmd,1);
  270. } else {
  271. readingsSingleUpdate($lh, "state", $cmd,1);
  272. }
  273. if ($cmd eq "dimup") {
  274. readingsSingleUpdate($lh, "lastDimValue", "dim100%",1);
  275. } elsif ($cmd eq "dimdown") {
  276. if ($hash->{READINGS}{protocol}{VAL} eq "HE800") {
  277. readingsSingleUpdate($lh, "lastDimValue", "dim12%",1);
  278. } else {
  279. readingsSingleUpdate($lh, "lastDimValue", "dim06%",1);
  280. }
  281. } else {
  282. readingsSingleUpdate($lh, "lastDimValue", $cmd,1);
  283. }
  284. }
  285. } else {
  286. readingsSingleUpdate($lh, "state", $cmd,1);
  287. }
  288. } else {
  289. readingsSingleUpdate($lh, "state", $cmd,1);
  290. if( AttrVal($name, "model", "") eq "itdimmer" ) {
  291. readingsSingleUpdate($lh,"dim",$cmd,1);
  292. }
  293. }
  294. }
  295. Log3 $hash, 5, "$io->{NAME} IT_set: Type=" . $io->{TYPE} . ' Protocol=' . $hash->{READINGS}{protocol}{VAL};
  296. if ($io->{TYPE} ne "SIGNALduino") {
  297. # das IODev ist kein SIGNALduino
  298. ## Do we need to change RFMode to SlowRF??
  299. if(defined($attr{$name}) && defined($attr{$name}{"switch_rfmode"})) {
  300. if ($attr{$name}{"switch_rfmode"} eq "1") { # do we need to change RFMode of IODev
  301. my $ret = CallFn($io->{NAME}, "AttrFn", "set", ($io->{NAME}, "rfmode", "SlowRF"));
  302. }
  303. }
  304. ## Do we need to change ITClock ?? }
  305. if(defined($attr{$name}) && defined($attr{$name}{"ITclock"})) {
  306. #$message = "isc".$attr{$name}{"ITclock"};
  307. #CallFn($io->{NAME}, "GetFn", $io, (" ", "raw", $message));
  308. $message = $attr{$name}{"ITclock"};
  309. CallFn($io->{NAME}, "SetFn", $io, ($hash->{NAME}, "ITClock", $message));
  310. Log3 $hash, 3, "IT set ITclock: $message for $io->{NAME}";
  311. }
  312. ## Do we need to change ITrepetition ??
  313. if(defined($attr{$name}) && defined($attr{$name}{"ITrepetition"})) {
  314. $message = "isr".$attr{$name}{"ITrepetition"};
  315. CallFn($io->{NAME}, "GetFn", $io, (" ", "raw", $message));
  316. Log3 $hash,4, "IT set ITrepetition: $message for $io->{NAME}";
  317. }
  318. ## Do we need to change ITfrequency ??
  319. if(defined($attr{$name}) && defined($attr{$name}{"ITfrequency"})) {
  320. my $f = $attr{$name}{"ITfrequency"}/26*65536;
  321. my $f2 = sprintf("%02x", $f / 65536);
  322. my $f1 = sprintf("%02x", int($f % 65536) / 256);
  323. my $f0 = sprintf("%02x", $f % 256);
  324. my $arg = sprintf("%.3f", (hex($f2)*65536+hex($f1)*256+hex($f0))/65536*26);
  325. Log3 $hash, 3, "Setting ITfrequency (0D,0E,0F) to $f2 $f1 $f0 = $arg MHz";
  326. CallFn($io->{NAME}, "GetFn", $io, (" ", "raw", "if$f2$f1$f0"));
  327. }
  328. }
  329. if ($hash->{READINGS}{protocol}{VAL} eq "V3") {
  330. if( AttrVal($name, "model", "") eq "itdimmer" ) {
  331. my @itvalues = split(' ', $v);
  332. if ($itvalues[1] eq "dimup") {
  333. $a[0] = "dim100%";
  334. readingsSingleUpdate($hash, "state", $itvalues[1],1);
  335. readingsSingleUpdate($hash, "dim", 100, 1);
  336. $message = "is".uc(substr($hash->{XMIT},0,length($hash->{XMIT})-5).$hash->{READINGS}{group}{VAL}."D".$hash->{READINGS}{unit}{VAL}."1111");
  337. } elsif ($itvalues[1] eq "dimdown") {
  338. $a[0] = "dim06%";
  339. readingsSingleUpdate($hash, "state", $itvalues[1],1);
  340. readingsSingleUpdate($hash, "dim", 6, 1);
  341. $message = "is".uc(substr($hash->{XMIT},0,length($hash->{XMIT})-5).$hash->{READINGS}{group}{VAL}."D".$hash->{READINGS}{unit}{VAL}."0000");
  342. } elsif ($itvalues[1] =~ /dim/) {
  343. my $dperc = substr($itvalues[1], 3, -1);
  344. my $dec = (15*$dperc)/100;
  345. my $bin = sprintf ("%b",$dec);
  346. while (length($bin) < 4) {
  347. # suffix 0
  348. $bin = '0'.$bin;
  349. }
  350. readingsSingleUpdate($hash, "dim", $dperc, 1);
  351. if ($dperc == 0) {
  352. $message = "is".uc(substr($hash->{XMIT},0,length($hash->{XMIT})-5).$hash->{READINGS}{group}{VAL}."0".$hash->{READINGS}{unit}{VAL});
  353. } else {
  354. $message = "is".uc(substr($hash->{XMIT},0,length($hash->{XMIT})-5).$hash->{READINGS}{group}{VAL}."D".$hash->{READINGS}{unit}{VAL}.$bin);
  355. }
  356. } else {
  357. my $stateVal;
  358. if ($a[0] eq "off") {
  359. $stateVal = "0";
  360. } else {
  361. $stateVal = $hash->{$c};
  362. readingsSingleUpdate($hash, "lastDimValue", "",1);
  363. }
  364. $message = "is".uc(substr($hash->{XMIT},0,length($hash->{XMIT})-5).$hash->{READINGS}{group}{VAL}.$stateVal.$hash->{READINGS}{unit}{VAL});
  365. }
  366. } else {
  367. $message = "is".uc(substr($hash->{XMIT},0,length($hash->{XMIT})-5).$hash->{READINGS}{group}{VAL}.$hash->{$c}.$hash->{READINGS}{unit}{VAL});
  368. }
  369. } elsif ($hash->{READINGS}{protocol}{VAL} eq "HE_EU") {
  370. my $masterVal = "11";
  371. if ($hash->{READINGS}{mode}{VAL} eq "master") {
  372. if ($hash->{$c} eq "01") {
  373. $masterVal = "01";
  374. }
  375. }
  376. $message = "ise".uc(substr($hash->{XMIT},0,length($hash->{XMIT})-7).$hash->{$c}.$masterVal.$hash->{READINGS}{unit}{VAL});
  377. } elsif ($hash->{READINGS}{protocol}{VAL} eq "HE800") {
  378. my $cVal;
  379. my $mode;
  380. my @mn;
  381. my $msg;
  382. my %he800MapingTable = (
  383. 12 => 2,
  384. 25 => 3,
  385. 37 => 4,
  386. 50 => 5,
  387. 62 => 6,
  388. 75 => 7,
  389. 87 => 8,
  390. 100 => 9,
  391. );
  392. (undef, $cVal) = split(" ", $v, 2); # Not interested in the name...
  393. my @key = (9, 6, 3, 8, 10, 0, 2, 12, 4, 14, 7, 5, 1, 15, 11, 13, 9); # cryptokey
  394. my $rollingCode = $hash->{"count"};
  395. if ($rollingCode > 3) {
  396. $rollingCode = 0;
  397. }
  398. my $oldMode = 0;
  399. if ($cVal eq "on") {
  400. my $sendVal = $hash->{READINGS}{"on_" . $rollingCode}{VAL};
  401. if (defined $sendVal && $sendVal ne "" && $sendVal ne "0") {
  402. $message = "ish".uc($sendVal);
  403. $oldMode = 1;
  404. Log3 $hash,4, "Use old Mode sendVal $sendVal ";
  405. } else {
  406. readingsSingleUpdate($hash, "lastDimValue", "",1);
  407. $mode = 1;
  408. }
  409. } elsif ($cVal eq "off") {
  410. my $sendVal = $hash->{READINGS}{"off_" . $rollingCode}{VAL};
  411. if (defined $sendVal && $sendVal ne "" && $sendVal ne "0") {
  412. $message = "ish".uc($sendVal);
  413. $oldMode = 1;
  414. Log3 $hash,4, "Use old Mode sendVal $sendVal ";
  415. } else {
  416. $mode = 0;
  417. }
  418. } else {
  419. Log3 $hash,5, "mode is DIM MODE: $v Model: " . AttrVal($name, "model", "");
  420. # DIM Mode
  421. if( AttrVal($name, "model", "") eq "itdimmer" ) {
  422. my @itvalues = split(' ', $v);
  423. if ($itvalues[1] eq "dimup") {
  424. readingsSingleUpdate($hash, "state", $itvalues[1],1);
  425. readingsSingleUpdate($hash, "dim", 100, 1);
  426. $mode = 9;
  427. } elsif ($itvalues[1] eq "dimdown") {
  428. readingsSingleUpdate($hash, "state", $itvalues[1],1);
  429. readingsSingleUpdate($hash, "dim", 12, 1);
  430. $mode = 2;
  431. } else {
  432. if ($itvalues[1] =~ /dim/) {
  433. my $dperc = substr($itvalues[1], 3, -1);
  434. #my $dperc = $itvalues[2];
  435. my $dec = $he800MapingTable{$dperc};
  436. my $bin = sprintf ("%b",$dec);
  437. while (length($bin) < 4) {
  438. # suffix 0
  439. $bin = '0'.$bin;
  440. }
  441. readingsSingleUpdate($hash, "dim", $dperc, 1);
  442. if ($dperc == 0) {
  443. $mode = 0;
  444. } else {
  445. $mode = $dec;
  446. }
  447. }
  448. }
  449. }
  450. }
  451. #}
  452. if ($oldMode == 0) {
  453. Log3 $hash,5, "mode is $mode";
  454. my @XMIT_split = split(/_/,$hash->{XMIT});
  455. my $receiverID = $XMIT_split[1];
  456. my $transmitterID = $XMIT_split[0];
  457. #encrypt
  458. $mn[0] = $XMIT_split[1]; # mn[0] = iiiib i=receiver-ID
  459. $mn[1] = ($rollingCode << 2) & 15; # 2 lowest bits of rolling-code
  460. if ($mode > 0) { # ON or OFF
  461. $mn[1] |= 2; # mn[1] = rrs0b r=rolling-code, s=ON/OFF, 0=const 0?
  462. }
  463. $mn[2] = $transmitterID & 15; # mn[2..5] = ttttb t=txID in nibbles -> 4x ttttb
  464. $mn[3] = ($transmitterID >> 4) & 15;
  465. $mn[4] = ($transmitterID >> 8) & 15;
  466. $mn[5] = ($transmitterID >> 12) & 15;
  467. if ($mode >= 2 && $mode <= 9) { # mn[6] = dpppb d = dim ON/OFF, p=%dim/10 - 1
  468. $mn[6] = $mode - 2; # dim: 0=10%..7=80%
  469. $mn[6] |= 8; # dim: ON
  470. } else {
  471. $mn[6] = 0; # dim: OFF
  472. }
  473. #XOR encryption 2 rounds
  474. for (my $r=0; $r<=1; $r++){ # 2 encryption rounds
  475. $mn[0] = $key[ $mn[0]-$r+1]; # encrypt first nibble
  476. my $i = 0;
  477. for ($i=1; $i<=5 ; $i++){ # encrypt 4 nibbles
  478. $mn[$i] = $key[($mn[$i] ^ $mn[$i-1])-$r+1]; # crypted with predecessor & key
  479. }
  480. }
  481. $mn[6] = $mn[6] ^ 9; # no encryption
  482. $msg = ($mn[6] << 0x18) | ($mn[5] << 0x14) | # copy the encrypted nibbles in output buffer
  483. ($mn[4] << 0x10) | ($mn[3] << 0x0c) |
  484. ($mn[2] << 0x08) | ($mn[1] << 0x04) | $mn[0];
  485. $msg = ($msg >> 2) | (($msg & 3) << 0x1a); # shift 2 bits right & copy lowest 2 bits of cbuf[0] in msg bit 27/28
  486. $msg = ~$msg & 0xFFFFFFF;
  487. my $bin1=sprintf("%024b",$msg);
  488. while (length($bin1) < 28) {
  489. # suffix 0
  490. $bin1 = '0'.$bin1;
  491. }
  492. my $bin = $bin1;# . $bin3;
  493. Log3 $hash,4, "msg $msg - bin1 $bin1";
  494. $message = "ish".uc($bin);
  495. }
  496. } else {
  497. my $onoffcode;
  498. if (defined($c)) {
  499. $onoffcode = $hash->{$c};
  500. } else {
  501. if ($hash->{userV1setCodes}) {
  502. $onoffcode = $hash->{userV1setCodes}{$a[0]};
  503. }
  504. }
  505. if (length($onoffcode) == 4) { # EV1527
  506. $onoffcode = $bintotristate{substr($onoffcode,0,2)} . $bintotristate{substr($onoffcode,2,2)};
  507. }
  508. $message = "is".uc($hash->{XMIT}.$onoffcode);
  509. }
  510. if ($io->{TYPE} ne "SIGNALduino") {
  511. # das IODev ist kein SIGNALduino
  512. ## Send Message to IODev and wait for correct answer
  513. my $msg = CallFn($io->{NAME}, "GetFn", $io, (" ", "raw", $message));
  514. Log3 $hash,5,"IT_Set: GetFn(raw): message = $message Antwort = $msg";
  515. if ($msg =~ m/raw => $message/) {
  516. Log 4, "ITSet: Answer from $io->{NAME}: $msg";
  517. } else {
  518. Log 2, "IT IODev device didn't answer is command correctly: $msg";
  519. }
  520. ## Do we need to change ITrepetition back??
  521. if(defined($attr{$name}) && defined($attr{$name}{"ITrepetition"})) {
  522. $message = "isr".$it_defrepetition;
  523. CallFn($io->{NAME}, "GetFn", $io, (" ", "raw", $message));
  524. Log3 $hash, 3, "IT set ITrepetition back: $message for $io->{NAME}";
  525. }
  526. ## Do we need to change ITfrequency back??
  527. if(defined($attr{$name}) && defined($attr{$name}{"ITfrequency"})) {
  528. Log3 $hash,4 ,"Setting ITfrequency back to 433.92 MHz";
  529. CallFn($io->{NAME}, "GetFn", $io, (" ", "raw", "if0"));
  530. }
  531. ## Do we need to change ITClock back??
  532. if(defined($attr{$name}) && defined($attr{$name}{"ITclock"}))
  533. {
  534. Log3 $hash, 3, "Setting ITClock back to 420";
  535. #CallFn($io->{NAME}, "GetFn", $io, (" ", "raw", "sic250"));
  536. CallFn($io->{NAME}, "SetFn", $io, ($hash->{NAME}, "ITClock", "420"));
  537. }
  538. ## Do we need to change RFMode back to HomeMatic??
  539. if(defined($attr{$name}) && defined($attr{$name}{"switch_rfmode"})) {
  540. if ($attr{$name}{"switch_rfmode"} eq "1") { # do we need to change RFMode of IODev
  541. my $ret = CallFn($io->{NAME}, "AttrFn", "set", ($io->{NAME}, "rfmode", "HomeMatic"));
  542. }
  543. }
  544. } else { # SIGNALduino
  545. my $SignalRepeats = AttrVal($name,'ITrepetition', '6');
  546. my $ITClock = AttrVal($name,'ITclock', undef);
  547. my $f = AttrVal($name,'ITfrequency',undef);
  548. my $ITfrequency = '';
  549. my $protocolId;
  550. if (defined($f)) {
  551. $f = $f / 26 * 65536;
  552. my $f2 = sprintf("%02x", $f / 65536);
  553. my $f1 = sprintf("%02x", int($f % 65536) / 256);
  554. my $f0 = sprintf("%02x", $f % 256);
  555. my $arg = sprintf("%.3f", (hex($f2)*65536+hex($f1)*256+hex($f0))/65536*26);
  556. Log3 $hash, 3, "$io->{NAME} IT_set: Setting ITfrequency (0D,0E,0F) to $f2 $f1 $f0 = $arg MHz";
  557. $ITfrequency = "#F$f2$f1$f0";
  558. }
  559. if (defined($ITClock)) {
  560. $ITClock = '#C' . $ITClock;
  561. } else {
  562. $ITClock = '';
  563. }
  564. $protocolId = AttrVal($name,'SIGNALduinoProtocolId', undef);
  565. if (defined($protocolId)) {
  566. $protocolId = 'P' . $protocolId . '#';
  567. } else {
  568. if ($hash->{READINGS}{protocol}{VAL} eq "V3") {
  569. $protocolId = 'P17#';
  570. } else {
  571. $protocolId = 'P3#'; # IT V1
  572. }
  573. }
  574. if ($hash->{READINGS}{protocol}{VAL} ne "EV1527" && $hash->{READINGS}{protocol}{VAL} ne "V1") { # bei ITv1 und EV1527 wird das "is" am Anfang nicht entfernt
  575. $message = substr($message,2);
  576. if (substr($message,0,1) eq "h") { # h entfernen falls am am Anfang
  577. $message = substr($message,1);
  578. }
  579. }
  580. Log3 $hash, 4, "$io->{NAME} IT_set: sendMsg=" . $protocolId . $message . '#R' . $SignalRepeats . $ITClock;
  581. IOWrite($hash, 'sendMsg', $protocolId . $message . '#R' . $SignalRepeats . $ITClock . $ITfrequency);
  582. }
  583. return $ret;
  584. }
  585. #############################
  586. sub
  587. IT_Define($$)
  588. {
  589. my ($hash, $def) = @_;
  590. my @a = split("[ \t][ \t]*", $def);
  591. # calculate transmit code from IT A-P rotary switches
  592. if($a[2] =~ /^([A-O])(([0]{0,1}[1-9])|(1[0-6]))$/i) {
  593. my %it_1st = (
  594. "A","0000","B","F000","C","0F00","D","FF00","E","00F0","F","F0F0",
  595. "G","0FF0","H","FFF0","I","000F","J","F00F","K","0F0F","L","FF0F",
  596. "M","00FF","N","F0FF","O","0FFF","P","FFFF"
  597. );
  598. my %it_2nd = (
  599. 1 ,"0000",2 ,"F000",3 ,"0F00",4 ,"FF00",5 ,"00F0",6 ,"F0F0",
  600. 7 ,"0FF0",8 ,"FFF0",9 ,"000F",10,"F00F",11,"0F0F",12,"FF0F",
  601. 13,"00FF",14,"F0FF",15,"0FFF",16,"FFFF"
  602. );
  603. $a[2] = $it_1st{$1}.$it_2nd{int($2)}."0F";
  604. defined $a[3] or $a[3] = "FF";
  605. defined $a[4] or $a[4] = "F0";
  606. defined $a[5] or $a[5] = "0F";
  607. defined $a[6] or $a[6] = "00";
  608. }
  609. # calculate transmit code from FLS 100 I,II,III,IV rotary switches
  610. if($a[2] =~ /^(I|II|III|IV)([1-4])$/i) {
  611. my %fls_1st = ("I","0FFF","II","F0FF","III","FF0F","IV","FFF0" );
  612. my %fls_2nd = (1 ,"0FFF",2 ,"F0FF",3 ,"FF0F",4 ,"FFF0");
  613. $a[2] = $fls_1st{$1}.$fls_2nd{int($2)}."0F";
  614. defined $a[3] or $a[3] = "FF";
  615. defined $a[4] or $a[4] = "F0";
  616. defined $a[5] or $a[5] = "0F";
  617. defined $a[6] or $a[6] = "00";
  618. }
  619. my $u = "wrong syntax: define <name> IT 10-bit-housecode " .
  620. "off-code on-code [dimup-code] [dimdown-code] or for protocol V3 " .
  621. "define <name> IT <26 bit Address> <1 bit group bit> <4 bit unit>";
  622. return $u if(int(@a) < 3);
  623. my $housecode;
  624. my $oncode;
  625. my $offcode;
  626. my $unitCode;
  627. my $groupBit;
  628. my $name = $a[0];
  629. if ($a[3] eq "HE800") {
  630. # OLD, do not use anymore
  631. $housecode = $a[2];
  632. $hash->{READINGS}{protocol}{VAL} = 'HE800';
  633. $hash->{"count"} = '0';
  634. $oncode = "N/A";
  635. $offcode = "N/A";
  636. $unitCode="N/A";
  637. #return "FALSE";
  638. } elsif ($a[2] eq "HE800") {
  639. $housecode = ($a[3] + 0) . "_" . ($a[4] + 0);
  640. $hash->{READINGS}{protocol}{VAL} = 'HE800';
  641. $hash->{"count"} = '0';
  642. $oncode = "N/A";
  643. $offcode = "N/A";
  644. $unitCode="N/A";
  645. #return "FALSE";
  646. } elsif (length($a[2]) == 26) {
  647. # Is Protocol V3
  648. return "Define $a[0]: wrong ITv3-Code format: specify a 26 digits 0/1 "
  649. if( ($a[2] !~ m/^[0-1]{26}$/i) );
  650. return "Define $a[0]: wrong Bit Group format: specify a 1 digits 0/1 "
  651. if( ($a[3] !~ m/^[0-1]{1}$/i) );
  652. return "Define $a[0]: wrong Unit format: specify 4 digits 0/1 "
  653. if( ($a[4] !~ m/^[0-1]{4}$/i) );
  654. #return "Define $a[0]: wrong on/off/dimm format: specify a 1 digits 0/1/d "
  655. # if( ($a[3] !~ m/^[d0-1]{1}$/i) );
  656. $housecode=$a[2].$a[3].$a[4];
  657. $groupBit=$a[3];
  658. $unitCode=$a[4];
  659. $oncode = 1;
  660. $offcode = 0;
  661. $hash->{READINGS}{protocol}{VAL} = 'V3';
  662. $hash->{READINGS}{unit}{VAL} = $unitCode;
  663. $hash->{READINGS}{group}{VAL} = $groupBit;
  664. } elsif (length($a[2]) == 46) { # HE_EU
  665. return "Define $a[0]: wrong IT-Code format: specify a 29 digits 0/1 "
  666. if( ($a[2] !~ m/^[0-1]{46}$/i) );
  667. return "Define $a[0]: wrong group format: specify a 1 digits 0/1 "
  668. if( ($a[3] !~ m/^[0-1]{1}$/i) );
  669. return "Define $a[0]: wrong unit format: specify a 7 digits 0/1 "
  670. if( ($a[4] !~ m/^[0-1]{7}$/i) );
  671. $housecode = $a[2].$a[4];
  672. $groupBit = $a[3];
  673. $unitCode=$a[4];
  674. if ($groupBit == "1") {
  675. # looks like a master key
  676. $hash->{READINGS}{mode}{VAL} = "master";
  677. $oncode = "01";
  678. $offcode = "00";
  679. } else {
  680. $hash->{READINGS}{mode}{VAL} = "single";
  681. $oncode = "10";
  682. $offcode = "01";
  683. }
  684. $hash->{READINGS}{unit}{VAL} = $unitCode;
  685. $hash->{READINGS}{protocol}{VAL} = 'HE_EU';
  686. } elsif (length($a[2]) == 10 && (substr($a[2],0,4) eq '1527' || AttrVal($name, "model", "") eq "ev1527" || length($a[3]) == 4)) {
  687. # Is Protocol EV1527
  688. #Log3 $hash,2,"ITdefine 1527: $name a3=" . $a[3];
  689. $housecode = $a[2];
  690. if (substr($housecode,0,4) eq '1527') {
  691. my $evcode;
  692. my $bincode = sprintf("%020b",hex(substr($housecode,5)));
  693. for (my $n=0; $n<20; $n=$n+2) {
  694. $evcode = $evcode . $bintotristate{substr($bincode,$n,2)};
  695. }
  696. $hash->{XMIT} = lc($evcode);
  697. } else {
  698. $hash->{XMIT} = lc($housecode);
  699. }
  700. return "Define $a[0]: wrong dimup-code format: specify a 4 digits 0/1 "
  701. if ( ($a[3] !~ m/^[0-1]{4}$/i) );
  702. return "Define $a[0]: wrong dimup-code format: specify a 4 digits 0/1 "
  703. if ( ($a[4] !~ m/^[0-1]{4}$/i) );
  704. $oncode = $a[3];
  705. $offcode = $a[4];
  706. $hash->{READINGS}{protocol}{VAL} = 'EV1527';
  707. } elsif (length($a[2]) == 8) { # SBC, FreeTec
  708. return "Define $a[0]: wrong IT-Code format: specify a 8 digits 0/1/f "
  709. if( ($a[2] !~ m/^[f0-1]{8}$/i) );
  710. return "Define $a[0]: wrong ON format: specify a 4 digits 0/1/f "
  711. if( ($a[3] !~ m/^[f0-1]{4}$/i) );
  712. return "Define $a[0]: wrong OFF format: specify a 4 digits 0/1/f "
  713. if( ($a[4] !~ m/^[f0-1]{4}$/i) );
  714. $housecode = $a[2];
  715. $oncode = $a[3];
  716. $offcode = $a[4];
  717. $hash->{READINGS}{protocol}{VAL} = 'SBC_FreeTec';
  718. } else {
  719. #Log3 $hash,2,"ITdefine v1: $name";
  720. return "Define $a[0]: wrong IT-Code format: specify a 10 digits 0/1/f "
  721. if( ($a[2] !~ m/^[f0-1]{10}$/i) );
  722. return "Define $a[0]: wrong ON format: specify a 2 digits 0/1/f/d "
  723. if( ($a[3] !~ m/^[df0-1]{2}$/i) );
  724. return "Define $a[0]: wrong OFF format: specify a 2 digits 0/1/f/d "
  725. if( ($a[4] !~ m/^[df0-1]{2}$/i) );
  726. $housecode = $a[2];
  727. $oncode = $a[3];
  728. $offcode = $a[4];
  729. $hash->{READINGS}{protocol}{VAL} = 'V1';
  730. }
  731. if ($hash->{READINGS}{protocol}{VAL} ne 'EV1527') {
  732. $hash->{XMIT} = lc($housecode);
  733. }
  734. $hash->{$it_c2b{"on"}} = lc($oncode);
  735. $hash->{$it_c2b{"off"}} = lc($offcode);
  736. if (int(@a) > 5) {
  737. if (length($a[5]) != 4) { # kein EV1527
  738. return "Define $a[0]: wrong dimup-code format: specify a 2 digits 0/1/f/d "
  739. if( ($a[5] !~ m/^[df0-1]{2}$/i) );
  740. } else {
  741. return "Define $a[0]: wrong dimup-code format: specify a 4 digits 0/1 "
  742. if( ($a[5] !~ m/^[0-1]{4}$/i) );
  743. }
  744. $hash->{$it_c2b{"dimup"}} = lc($a[5]);
  745. if (int(@a) == 7) {
  746. if (length($a[6]) != 4) { # kein EV1527
  747. return "Define $a[0]: wrong dimdown-code format: specify a 2 digits 0/1/f/d "
  748. if( ($a[6] !~ m/^[df0-1]{2}$/i) );
  749. } else {
  750. return "Define $a[0]: wrong dimup-code format: specify a 4 digits 0/1 "
  751. if( ($a[6] !~ m/^[0-1]{4}$/i) );
  752. }
  753. }
  754. $hash->{$it_c2b{"dimdown"}} = lc($a[6]);
  755. } else {
  756. $hash->{$it_c2b{"dimup"}} = "00";
  757. $hash->{$it_c2b{"dimdown"}} = "00";
  758. }
  759. my $code = lc($housecode);
  760. my $ncode = 1;
  761. $hash->{CODE}{$ncode++} = $code;
  762. $modules{IT}{defptr}{$code}{$name} = $hash;
  763. AssignIoPort($hash);
  764. }
  765. #############################
  766. sub
  767. IT_Undef($$)
  768. {
  769. my ($hash, $name) = @_;
  770. foreach my $c (keys %{ $hash->{CODE} } ) {
  771. $c = $hash->{CODE}{$c};
  772. # As after a rename the $name my be different from the $defptr{$c}{$n}
  773. # we look for the hash.
  774. foreach my $dname (keys %{ $modules{IT}{defptr}{$c} }) {
  775. delete($modules{IT}{defptr}{$c}{$dname})
  776. if($modules{IT}{defptr}{$c}{$dname} == $hash);
  777. }
  778. }
  779. return undef;
  780. }
  781. sub
  782. IT_Parse($$)
  783. {
  784. my ($hash, $msg) = @_;
  785. my $ioname = $hash->{NAME};
  786. my $housecode;
  787. my $transmittercode;
  788. my $dimCode;
  789. my $unitCode;
  790. my $groupBit;
  791. my $onoffcode;
  792. my $def;
  793. my $newstate;
  794. my @list;
  795. if ((substr($msg, 0, 1)) ne 'i') {
  796. Log3 $hash,4,"$ioname IT: message not supported by IT \"$msg\"!";
  797. return undef;
  798. }
  799. if (length($msg) != 7 && length($msg) != 12 && length($msg) != 17 && length($msg) != 19 && length($msg) != 20) {
  800. Log3 $hash,3,"$ioname IT: message \"$msg\" (" . length($msg) . ") too short!";
  801. return undef;
  802. }
  803. Log3 $hash,4,"$ioname IT: message \"$msg\" (" . length($msg) . ")";
  804. my $bin = undef;
  805. my $isDimMode = 0;
  806. if (length($msg) == 17) { # IT V3
  807. my $bin1=sprintf("%024b",hex(substr($msg,1,length($msg)-1-8)));
  808. while (length($bin1) < 32) {
  809. # suffix 0
  810. $bin1 = '0'.$bin1;
  811. }
  812. my $bin2=sprintf("%024b",hex(substr($msg,1+8,length($msg)-1)));
  813. while (length($bin2) < 32) {
  814. # suffix 0
  815. $bin2 = '0'.$bin2;
  816. }
  817. $bin = $bin1 . $bin2;
  818. Log3 $hash,4,"$ioname ITv3: bin message \"$bin\" (" . length($bin) . ")";
  819. } elsif (length($msg) == 19 ) { # IT V3 Dimm
  820. my $bin1=sprintf("%024b",hex(substr($msg,1,length($msg)-1-8-8)));
  821. while (length($bin1) < 32) {
  822. # suffix 0
  823. $bin1 = '0'.$bin1;
  824. }
  825. my $bin2=sprintf("%024b",hex(substr($msg,1+2,length($msg)-1-8-2)));
  826. while (length($bin2) < 32) {
  827. # suffix 0
  828. $bin2 = '0'.$bin2;
  829. }
  830. my $bin3=sprintf("%024b",hex(substr($msg,1+8+2,length($msg)-1)));
  831. while (length($bin3) < 32) {
  832. # suffix 0
  833. $bin3 = '0'.$bin3;
  834. }
  835. $bin = substr($bin1 . $bin2 . $bin3,24,length($bin1 . $bin2 . $bin3)-1);
  836. Log3 $hash,4,"$ioname ITv3dimm: bin message \"$bin\" (" . length($bin) . ")";
  837. } elsif (length($msg) == 20 && (substr($msg, 1, 1)) eq 'h') { # HomeEasy EU
  838. #Log3 undef,3,"HEX Part1: " . substr($msg,2,8);
  839. my $bin1=sprintf("%024b",hex(substr($msg,2,8)));
  840. while (length($bin1) < 32) {
  841. # suffix 0
  842. $bin1 = '0'.$bin1;
  843. }
  844. #Log3 undef,3,"HEX Part2: " . substr($msg,2+8,7);
  845. my $bin2=sprintf("%024b",hex(substr($msg,2+8,7)));
  846. #$bin2 = substr($bin2,4);
  847. while (length($bin2) < 28) {
  848. # suffix 0
  849. $bin2 = '0'.$bin2;
  850. }
  851. $bin = $bin1 . $bin2;# . $bin3;
  852. } elsif (length($msg) == 12 && (substr($msg, 1, 1)) eq 'h') { # HomeEasy HE800
  853. my $bin1=sprintf("%024b",hex(substr($msg,2,8)));
  854. while (length($bin1) < 32) {
  855. # suffix 0
  856. $bin1 = '0'.$bin1;
  857. }
  858. $bin = $bin1;# . $bin3;
  859. } else { # IT
  860. $bin=sprintf("%024b",hex(substr($msg,1,length($msg)-1)));
  861. }
  862. if ((length($bin) % 2) != 0) {
  863. # suffix 0
  864. $bin = '0'.$bin;
  865. }
  866. my $binorg = $bin;
  867. my $msgcode="";
  868. if (length($msg) == 12 && (substr($msg, 1, 1)) eq 'h') { # HomeEasy HE800;
  869. $msgcode=substr($bin, 0, 28);
  870. } elsif (length($msg) == 20 && (substr($msg, 1, 1)) eq 'h') { # HomeEasy EU;
  871. $msgcode=substr($bin, 0, 57);
  872. } else {
  873. while (length($bin)>=2) {
  874. if (length($msg) == 7) {
  875. if (substr($bin,0,2) != "10") {
  876. $msgcode=$msgcode.$bintotristate{substr($bin,0,2)};
  877. } else {
  878. if (length($msgcode) >= 10) {
  879. Log3 $hash,5,"$ioname IT Parse bintotristate: msgcode=$msgcode, unknown tristate in onoff-code. is evtl a EV1527 sensor";
  880. # $msgcode = substr($msgcode,0,10) . '00';
  881. $msgcode = substr($msgcode,0,10) . $bintotristate{substr($binorg,20,2)} . $bintotristate{substr($binorg,22,2)};
  882. } else {
  883. $msgcode = "";
  884. }
  885. last;
  886. #Log3 $hash,4,"$ioname IT:unknown tristate in \"$bin\"";
  887. #return "unknown tristate in \"$bin\""
  888. }
  889. } elsif (length($msg) == 20 && (substr($msg, 1, 1)) eq 'h') { # HomeEasy EU
  890. $msgcode=$msgcode.$bintotristateHE{substr($bin,0,2)};
  891. } else {
  892. $msgcode=$msgcode.$bintotristateV3{substr($bin,0,2)};
  893. }
  894. $bin=substr($bin,2,length($bin)-2);
  895. }
  896. }
  897. Log3 $hash,4,"$ioname IT: msgcode \"$msgcode\" (" . length($msgcode) . ") bin = $binorg";
  898. my $isEV1527 = undef;
  899. if (length($msg) == 7) {
  900. if ($msgcode) { # ITv1 or SBC_FreeTec
  901. if (substr($msg,6, 1) eq '0' && substr($msgcode,8,2) ne 'FF') { # SBC_FreeTec
  902. $housecode=substr($msgcode,0,8);
  903. $onoffcode=substr($msgcode,length($msgcode)-4,4);
  904. Log3 $hash,5,"$ioname IT: SBC_FreeTec housecode = $housecode onoffcode = $onoffcode";
  905. } else { # ITv1
  906. $housecode=substr($msgcode,0,10);
  907. $onoffcode=substr($msgcode,length($msgcode)-2,2);
  908. Log3 $hash,5,"$ioname IT: V1 housecode = $housecode onoffcode = $onoffcode";
  909. }
  910. } else {
  911. $isEV1527 = 1;
  912. $housecode = '1527x' . sprintf("%05x", oct("0b".substr($binorg,0,20)));
  913. $onoffcode = substr($binorg, 20);
  914. Log3 $hash,5,"$ioname IT: EV1527 housecode = $housecode onoffcode = $onoffcode";
  915. }
  916. } elsif (length($msg) == 17 || length($msg) == 19) {
  917. $groupBit=substr($msgcode,26,1);
  918. $onoffcode=substr($msgcode,27,1);
  919. $unitCode=substr($msgcode,28,4);
  920. $housecode=substr($msgcode,0,26).$groupBit.$unitCode;
  921. if (length($msg) == 19) {
  922. $dimCode=substr($msgcode,32,4);
  923. }
  924. } elsif (length($msg) == 20 && (substr($msg, 1, 1)) eq 'h') { # HomeEasy EU
  925. $onoffcode=substr($msgcode,46,2);
  926. $groupBit=substr($msgcode,48,2);
  927. $unitCode=substr($msgcode,50,7);
  928. $housecode=substr($msgcode,0,46).$unitCode;
  929. } elsif (length($msg) == 12 && (substr($msg, 1, 1)) eq 'h') { # HomeEasy HE800
  930. #$housecode=substr($msgcode,0,6).substr($msgcode,26,2);
  931. #$onoffcode=0;
  932. Log3 $hash,4,"$ioname IT: msg:" . $msg . " msgcode:" . substr($msg, 2, 8) ;
  933. my $msgVal = hex(substr($msg, 2, 8));
  934. my @mn;
  935. my $receiverID;
  936. my $mode;
  937. my @ikey = (5, 12, 6, 2, 8, 11, 1, 10, 3, 0, 4, 14, 7, 15, 9, 13); #invers cryptokey (exchanged index & value)
  938. Log3 $hash,4,"$ioname IT: HEX:" . $msg . " DEC:" . $msgVal ;
  939. $msgVal = ~($msgVal >> 4) & 0xFFFFFFF;
  940. Log3 $hash,4,"$ioname IT: DEC:" . $msgVal ;
  941. $msgVal = (($msgVal << 2) & 0x0FFFFFFF) | (($msgVal & 0xC000000) >> 0x1a); # shift 2 bits left & copy bit 27/28 to bit 1/2
  942. Log3 $hash,4,"$ioname IT: DEC:" . $msgVal ;
  943. $mn[0] = $msgVal & 0x0000000F;
  944. $mn[1] = ($msgVal & 0x000000F0) >> 0x4;
  945. $mn[2] = ($msgVal & 0x00000F00) >> 0x8;
  946. $mn[3] = ($msgVal & 0x0000F000) >> 0xc;
  947. $mn[4] = ($msgVal & 0x000F0000) >> 0x10;
  948. $mn[5] = ($msgVal & 0x00F00000) >> 0x14;
  949. $mn[6] = ($msgVal & 0x0F000000) >> 0x18;
  950. $mn[6] = $mn[6] ^ 9; # no decryption
  951. Log3 $hash,4,"$ioname IT: mn: @mn";
  952. # XOR decryption 2 rounds
  953. my $r = 0;
  954. for ($r=0; $r<=1; $r++){ # 2 decryption rounds
  955. my $i = 5;
  956. for ($i=5; $i>=1 ; $i--){ # decrypt 4 nibbles
  957. $mn[$i] = (($ikey[$mn[$i]]-$r) & 0x0F) ^ $mn[$i-1]; # decrypted with predecessor & key
  958. }
  959. $mn[0] = ($ikey[$mn[0]]-$r) & 0x0F; #decrypt first nibble
  960. }
  961. Log3 $hash,4,"$ioname IT: mn: @mn ";
  962. $receiverID = $mn[0];
  963. $mode = ((($mn[1]>>1) & 1) + ($mn[6] & 0x7) + (($mn[6] & 0x8) >> 3));
  964. my $rollingCode = ($mn[1] >> 2);
  965. my $transmitterID = (($mn[5] << 12) + ($mn[4] << 8) + ($mn[3] << 4) + $mn[2]);
  966. $housecode = $transmitterID . "_" . $receiverID;
  967. $transmittercode = $transmitterID;
  968. $unitCode = $receiverID;
  969. $onoffcode = $mode;
  970. Log3 $hash,4,"receiverID : " . $receiverID ; # receiver-ID [0]1..15, 0=Broadcast 1-15 (HE844A button# 1-4 & MASTER=0, HE850 UNIT# 1-15, HE853 = 1)
  971. Log3 $hash,4,"OFF/ON/DIM : " . $mode ; # 0=OFF 1=ON, 2=10%dim..9=80%dim (no 90%dim!)
  972. Log3 $hash,4,"Rolling-Code : " . $rollingCode ; # rolling-code 0-3 (differentiate new message from repeated message)
  973. Log3 $hash,4,"Transmitter-ID: " . $transmitterID ; # unique transmitter-ID [0]1..65535 (0 valid?, 65535 or lower limit?)
  974. } else {
  975. Log3 $hash,4,"$ioname IT: Wrong IT message received: $msgcode";
  976. return undef;
  977. }
  978. if(!defined($modules{IT}{defptr}{lc("$housecode")})) {
  979. if(length($msg) == 7) {
  980. Log3 $hash,4,"$ioname IT: $housecode not defined (Switch code: $onoffcode)";
  981. #return "$housecode not defined (Switch code: $onoffcode)!";
  982. my $tmpOffCode;
  983. my $tmpOnCode;
  984. if (!defined($isEV1527)) { # itv1
  985. if ($onoffcode eq "F0") { # on code IT
  986. Log3 $hash,3,"$ioname IT: For autocreate please use the on button.";
  987. return undef;
  988. }
  989. $tmpOffCode = "F0";
  990. $tmpOnCode = "0F";
  991. if ($onoffcode eq "FF") { # on code IT
  992. $tmpOnCode = "FF";
  993. }
  994. } else { # ev1527
  995. $tmpOffCode = $ev_action{'off'};
  996. #$tmpOnCode = $ev_action{'on'};
  997. $tmpOnCode = $onoffcode;
  998. }
  999. if (length($housecode) == 8){
  1000. $tmpOffCode = '1000';
  1001. $tmpOnCode = '0100';
  1002. }
  1003. return "UNDEFINED IT_$housecode IT $housecode $tmpOnCode $tmpOffCode" if(!$def);
  1004. } elsif (length($msg) == 20) { # HE_EU
  1005. my $isGroupCode = '0';
  1006. if (($onoffcode == '01' && $groupBit == '01') || ($onoffcode == '00' && $groupBit == '11')) {
  1007. # Group Code found
  1008. $isGroupCode = '1';
  1009. }
  1010. Log3 $hash,2,"$ioname IT: $housecode not defined (Address: ".substr($msgcode,0,46)." Unit: $unitCode Switch code: $onoffcode GroupCode: $isGroupCode)";
  1011. #return "$housecode not defined (Address: ".substr($msgcode,0,26)." Group: $groupBit Unit: $unitCode Switch code: $onoffcode)!";
  1012. return "UNDEFINED IT_$housecode IT " . substr($msgcode,0,46) . " $isGroupCode $unitCode" if(!$def);
  1013. } elsif (length($msg) == 12 && (substr($msg, 1, 1)) eq 'h') { # HE800
  1014. Log3 $hash,2,"$ioname IT: $housecode not defined (HE800)";
  1015. return "UNDEFINED IT_HE800_$housecode IT " . "HE800 $transmittercode $unitCode" if(!$def);
  1016. } else {
  1017. my $hexCode = sprintf("%x", oct("0b".$housecode));
  1018. Log3 $hash,2,"$ioname IT: IT_V3_$hexCode ($housecode) not defined (Address: ".substr($msgcode,0,26)." Group: $groupBit Unit: $unitCode Switch code: $onoffcode)";
  1019. return "UNDEFINED IT_V3_$hexCode IT " . substr($msgcode,0,26) . " $groupBit $unitCode" if(!$def);
  1020. }
  1021. }
  1022. $def=$modules{IT}{defptr}{lc($housecode)};
  1023. #$lh->{"learn"} = 'ON';
  1024. foreach my $name (keys %{$def}) {
  1025. if (length($msg) == 17 || length($msg) == 19) {
  1026. if ($def->{$name}->{READINGS}{group}{VAL} != $groupBit || $def->{$name}->{READINGS}{unit}{VAL} != $unitCode) {
  1027. next;
  1028. }
  1029. } elsif (length($msg) == 7 && !defined($isEV1527) && AttrVal($name, "model", "") eq "ev1527") {
  1030. $onoffcode = substr($binorg, 20);
  1031. $def->{$name}->{READINGS}{protocol}{VAL} = 'EV1527';
  1032. Log3 $hash,4,"$ioname IT EV1527: " . $def->{$name}{NAME} . ', on code=' . $def->{$name}->{$it_c2b{"on"}} . ", Switch code=$onoffcode";
  1033. }
  1034. if ($def->{$name}->{READINGS}{protocol}{VAL} eq 'HE800') {
  1035. my %he800MapingTable = (
  1036. 2 => 12,
  1037. 3 => 25,
  1038. 4 => 37,
  1039. 5 => 50,
  1040. 6 => 62,
  1041. 7 => 75,
  1042. 8 => 87,
  1043. 9 => 100,
  1044. );
  1045. if ($onoffcode == 0) {
  1046. # OFF
  1047. my $actState = $hash->{READINGS}{state}{VAL};
  1048. $newstate="off";
  1049. if( AttrVal($name, "model", "") eq "itdimmer" ) {
  1050. readingsSingleUpdate($def->{$name},"dim",0,1);
  1051. }
  1052. } elsif ($onoffcode == 1) {
  1053. # On
  1054. $newstate="on";
  1055. if( AttrVal($name, "model", "") eq "itdimmer" ) {
  1056. my $lastDimVal = $def->{$name}->{READINGS}{lastDimValue}{VAL};
  1057. if (defined $lastDimVal && $lastDimVal ne "") {
  1058. my $dperc = substr($lastDimVal, 3, -1);
  1059. readingsSingleUpdate($def->{$name},"dim",$dperc,1);
  1060. readingsSingleUpdate($def->{$name}, "lastDimValue", "",1);
  1061. } else {
  1062. readingsSingleUpdate($def->{$name},"dim",100,1);
  1063. }
  1064. }
  1065. } else {
  1066. my $binVal = $he800MapingTable{$onoffcode};
  1067. $binVal = int($binVal);
  1068. $newstate = sprintf("dim%02d%%",$binVal);
  1069. readingsSingleUpdate($def->{$name},"dim",$binVal,1);
  1070. readingsSingleUpdate($def->{$name}, "lastDimValue", $newstate,1);
  1071. Log3 $hash,4,"$ioname HE800: onoffcode $onoffcode newstate " . $newstate;
  1072. #if ($binVal == 100) {
  1073. # $newstate="on";
  1074. #} els
  1075. if ($binVal == 0) {
  1076. $newstate="off";
  1077. }
  1078. }
  1079. } elsif ($def->{$name}->{$it_c2b{"on"}} eq lc($onoffcode)) {
  1080. $newstate="on";
  1081. if( AttrVal($name, "model", "") eq "itdimmer" ) {
  1082. my $lastDimVal = $def->{$name}->{READINGS}{lastDimValue}{VAL};
  1083. if (defined $lastDimVal && $lastDimVal ne "") {
  1084. my $dperc = substr($lastDimVal, 3, -1);
  1085. readingsSingleUpdate($def->{$name},"dim",$dperc,1);
  1086. readingsSingleUpdate($def->{$name}, "lastDimValue", "",1);
  1087. } else {
  1088. readingsSingleUpdate($def->{$name},"dim",100,1);
  1089. }
  1090. }
  1091. } elsif ($def->{$name}->{$it_c2b{"off"}} eq lc($onoffcode)) {
  1092. $newstate="off";
  1093. if( AttrVal($name, "model", "") eq "itdimmer" ) {
  1094. readingsSingleUpdate($def->{$name},"dim",0,1);
  1095. }
  1096. } elsif ($def->{$name}->{$it_c2b{"dimup"}} eq lc($onoffcode)) {
  1097. $newstate="dimup";
  1098. if( AttrVal($name, "model", "") eq "itdimmer" ) {
  1099. readingsSingleUpdate($def->{$name},"dim","dimup",1);
  1100. }
  1101. } elsif ($def->{$name}->{$it_c2b{"dimdown"}} eq lc($onoffcode)) {
  1102. $newstate="dimdown";
  1103. if( AttrVal($name, "model", "") eq "itdimmer" ) {
  1104. readingsSingleUpdate($def->{$name},"dim","dimdown",1);
  1105. }
  1106. } elsif ('d' eq lc($onoffcode)) {
  1107. # dim
  1108. my $binVal = ((bin2dec($dimCode)+1)*100)/16;
  1109. $binVal = int($binVal);
  1110. $newstate = sprintf("dim%02d%%",$binVal);
  1111. readingsSingleUpdate($def->{$name},"dim",$binVal,1);
  1112. readingsSingleUpdate($def->{$name}, "lastDimValue", $newstate,1);
  1113. if ($binVal == 100) {
  1114. $newstate="on";
  1115. } elsif ($binVal == 0) {
  1116. $newstate="off";
  1117. }
  1118. } else {
  1119. Log3 $def->{$name}{NAME},3,"$ioname IT: Code $onoffcode not supported by $def->{$name}{NAME}.";
  1120. next;
  1121. }
  1122. Log3 $def->{$name}{NAME},3,"$ioname IT: $def->{$name}{NAME} ".$def->{$name}->{STATE}."->".$newstate;
  1123. push(@list,$def->{$name}{NAME});
  1124. readingsSingleUpdate($def->{$name},"state",$newstate,1);
  1125. }
  1126. return @list;
  1127. }
  1128. sub IT_Attr(@)
  1129. {
  1130. my ($cmd,$name,$aName,$aVal) = @_;
  1131. my $hash = $defs{$name};
  1132. my $ret;
  1133. #Log3 $hash, 4, "$name IT_Attr: Calling Getting Attr sub with args: $cmd $aName = $aVal";
  1134. if( $aName eq 'model' && $aVal eq 'ev1527') {
  1135. #Log3 $hash, 4, "$name IT_Attr: ev1527";
  1136. $hash->{READINGS}{protocol}{VAL} = 'EV1527';
  1137. } elsif ( $aName eq 'userV1setCodes') {
  1138. my @array = split(" ",$aVal);
  1139. $hash->{userV1setCodes} = undef;
  1140. foreach my $item(@array) {
  1141. my ($i,$j)= split(/:/, $item);
  1142. $ret = "$i wrong chars in setname (only [0-9a-zA-Z-_])"
  1143. if ( ($i !~ m/^[0-9a-z-_]+$/i) );
  1144. if (length($j) != 4) { # kein EV1527
  1145. $ret = "$j wrong setcode format: specify a 2 digits 0/1/f/d "
  1146. if( ($j !~ m/^[df0-1]{2}$/i) );
  1147. } else {
  1148. $ret = "$j wrong setcode format: specify a 4 digits 0/1 "
  1149. if( ($j !~ m/^[0-1]{4}$/i) );
  1150. }
  1151. last if (defined($ret));
  1152. $hash->{userV1setCodes}{$i} = $j;
  1153. }
  1154. }
  1155. return $ret;
  1156. }
  1157. 1;
  1158. =pod
  1159. =item summary supports Intertechno protocol version 1 and version 3 devices
  1160. =item summary_DE unterstuetzt Intertechno Protocol Version 1 und Version 3 Geraete
  1161. =begin html
  1162. <a name="IT"></a>
  1163. <h3>IT - InterTechno</h3>
  1164. <ul>
  1165. The InterTechno 433MHZ protocol is used by a wide range of devices, which are either of
  1166. the sender/sensor or the receiver/actuator category.
  1167. Right now, we are able to SEND and RECEIVE InterTechno commands.
  1168. Supported are devices like switches, dimmers, etc. through an <a href="#CUL">CUL</a> or <a href="#SIGNALduino">SIGNALduino</a> device,
  1169. this must be defined first.<br>
  1170. This module supports Intertechno protocol version 1 and version 3.
  1171. Newly found devices are added into the category "IT" by autocreate.
  1172. Hint: IT protocol 1 devices are created on pressing the on-button.
  1173. <br><br>
  1174. <a name="ITdefine"></a>
  1175. <b>Define</b>
  1176. <ul>
  1177. <code>define &lt;name&gt; IT &lt;housecode&gt; &lt;on-code&gt; &lt;off-code&gt;
  1178. [&lt;dimup-code&gt;] [&lt;dimdown-code&gt;] </code>
  1179. <br>or<br>
  1180. <code>define &lt;name&gt; IT &lt;ITRotarySwitches|FLS100RotarySwitches&gt; </code>
  1181. <br>or<br>
  1182. <code>define &lt;name&gt; IT &lt;address 26 Bit&gt; &lt;group bit&gt; &lt;unit Code&gt;</code>
  1183. <br>or<br>
  1184. <code>define &lt;name&gt; IT HE800 &lt;Transmitter ID&gt; &lt;Receiver ID&gt;</code>
  1185. <br><br>
  1186. The value of housecode is a 10-digit InterTechno Code, consisting of 0/1/F as it is
  1187. defined as a tri-state protocol. These digits depend on the device you are using.
  1188. <br>
  1189. Bit 11 and 12 are used for switching/dimming. As different manufacturers are using
  1190. different bit-codes you can specifiy here the 2-digit code for off/on/dimup/dimdown
  1191. in the same form: 0/1/F.
  1192. <br>
  1193. The value of ITRotarySwitches consists of the value of the alpha switch A-P and
  1194. the numeric switch 1-16 as set on the intertechno device. E.g. A1 or G12.
  1195. <br>
  1196. The value of FLS100RotarySwitches consist of the value of the I,II,II,IV switch
  1197. and the numeric 1,2,3,4 swicht. E.g. I2 or IV4.
  1198. <br>
  1199. The value of ITRotarySwitches and FLS100RotarySwitches are internaly translated
  1200. into a houscode value.
  1201. <ul>
  1202. <li><code>&lt;housecode&gt;</code> is a 10 digit tri-state number (0/1/F) depending on
  1203. your device setting (see list below).</li>
  1204. <li><code>&lt;on-code&gt;</code> is a 2 digit tri-state number for switching your device on;
  1205. It is appended to the housecode to build the 12-digits IT-Message.</li>
  1206. <li><code>&lt;off-code&gt;</code> is a 2 digit tri-state number for switching your device off;
  1207. It is appended to the housecode to build the 12-digits IT-Message.</li>
  1208. <li>The optional <code>&lt;dimup-code&gt;</code> is a 2 digit tri-state number for dimming your device up;
  1209. It is appended to the housecode to build the 12-digits IT-Message.</li>
  1210. <li>The optional <code>&lt;dimdown-code&gt;</code> is a 2 digit tri-state number for dimming your device down;
  1211. It is appended to the housecode to build the 12-digits IT-Message.</li>
  1212. </ul>
  1213. <br>
  1214. <b>HE800</b><br>
  1215. <ul>
  1216. <li><code>&lt;Transmitter ID&gt;</code> Eindeutige Transmitter-ID (1..65535)</li>
  1217. <li><code>&lt;Receiver ID&gt;</code> Receiver-ID [0]1..15, 0=Broadcast 1-15 (HE844A button# 1-4 & MASTER=0, HE850 UNIT# 1-15, HE853 = 1)</li>
  1218. </ul>
  1219. <br>
  1220. Examples:
  1221. <ul>
  1222. <code>define lamp IT 01FF010101 11 00 01 10</code><br>
  1223. <code>define roll1 IT 111111111F 11 00 01 10</code><br>
  1224. <code>define otherlamp IT 000000000F 11 10 00 00</code><br>
  1225. <code>define otherroll1 IT FFFFFFF00F 11 10</code><br>
  1226. <code>define IT_1527xe0fec IT 1527xe0fec 1001 0000</code><br>
  1227. <code>define itswitch1 IT A1</code><br>
  1228. <code>define lamp IT J10</code><br>
  1229. <code>define flsswitch1 IT IV1</code><br>
  1230. <code>define lamp IT II2</code><br>
  1231. <code>define HE800_TID1_SW1 IT HE800 1 1</code><br>
  1232. </ul>
  1233. <br>
  1234. For Intertechno protocol 3 the &lt;housecode&gt; is a 26-digits number.
  1235. Additionaly there are a 4-digits unit code and a 1-digit group code used.
  1236. <ul>
  1237. <li><code>&lt;address&gt;</code> is a 26 digit number (0/1)</li>
  1238. <li><code>&lt;group&gt;</code> is a 1 digit number (0/1)</li>
  1239. <li><code>&lt;unit&gt;</code> is a 4 digit number (0/1)</li>
  1240. </ul>
  1241. <br>
  1242. Examples:
  1243. <ul>
  1244. <code>define myITSwitch IT 00111100110101010110011111 0 0000</code>
  1245. </ul>
  1246. </ul>
  1247. <br>
  1248. <a name="ITset"></a>
  1249. <b>Set </b>
  1250. <ul>
  1251. <code>set &lt;name&gt; &lt;value&gt; [&lt;time&gt]</code>
  1252. <br><br>
  1253. where <code>value</code> is one of:<br>
  1254. <pre>
  1255. dimdown
  1256. dimup
  1257. off
  1258. on
  1259. on-till # Special, see the note
  1260. dim06% dim12% dim18% dim25% dim31% dim37% dim43% dim50%
  1261. dim56% dim62% dim68% dim75% dim81% dim87% dim93% dim100%<br>
  1262. <li><a href="#setExtensions">set extensions</a> are supported.</li>
  1263. </pre>
  1264. Examples:
  1265. <ul>
  1266. <code>set lamp on</code><br>
  1267. <code>set lamp1,lamp2,lamp3 on</code><br>
  1268. <code>set lamp1-lamp3 on</code><br>
  1269. <code>set lamp off</code><br>
  1270. </ul>
  1271. <br>
  1272. Notes:
  1273. <ul>
  1274. <li>on-till requires an absolute time in the "at" format (HH:MM:SS, HH:MM
  1275. or { &lt;perl code&gt; }, where the perl-code returns a time specification).
  1276. If the current time is greater than the specified time, the
  1277. command is ignored, else an "on" command is generated, and for the
  1278. given "till-time" an off command is scheduleld via the at command.
  1279. </li>
  1280. </ul>
  1281. </ul>
  1282. <br>
  1283. <b>Get</b> <ul>N/A</ul><br>
  1284. <a name="ITattr"></a>
  1285. <b>Attributes</b>
  1286. <ul>
  1287. <a name="IODev"></a>
  1288. <li>IODev<br>
  1289. Set the IO device which will be used to send signals
  1290. for this device. An example for the physical device is a CUL.
  1291. Note: On startup, fhem DOES NOT assign an InterTechno device to an
  1292. IODevice! The attribute IODev needs to be used ALWAYS!</li><br>
  1293. <a name="eventMap"></a>
  1294. <li>eventMap<br>
  1295. Replace event names and set arguments. The value of this attribute
  1296. consists of a list of space separated values. Each value is a colon
  1297. separated pair. The first part specifies the "old" value, the second
  1298. the new/desired value. If the first character is slash(/) or comma(,)
  1299. the values are not separated by space but by this character to
  1300. enable spaces in values.
  1301. Examples:<ul><code>
  1302. attr store eventMap on:open off:closed<br>
  1303. attr store eventMap /on-for-timer 10:open/off:closed/<br>
  1304. set store open
  1305. </code></ul>
  1306. </li><br>
  1307. <li><a href="#do_not_notify">do_not_notify</a></li><br>
  1308. <a name="attrdummy"></a>
  1309. <li>dummy<br>
  1310. Set the device attribute dummy to define devices which should not
  1311. output any radio signals. Associated notifys will be executed if
  1312. the signal is received. Used e.g. to react to a code from a sender, but
  1313. it will not emit radio signal if triggered in the web frontend.
  1314. </li><br>
  1315. <li><a href="#loglevel">loglevel</a></li><br>
  1316. <li><a href="#showtime">showtime</a></li><br>
  1317. <li><a href="#readingFnAttributes">readingFnAttributes</a></li><br>
  1318. <a name="model"></a>
  1319. <li>model<br>
  1320. The model attribute denotes the type of the device.
  1321. This attribute will (currently) not be used by fhem.pl directly.
  1322. It can be used by e.g. external programs or web interfaces to
  1323. distinguish classes of devices and send the appropriate commands
  1324. (e.g. "on" or "off" to a switch, "dim..%" to dimmers etc.).
  1325. The spelling of the model should match the modelname used in the
  1326. documentation that comes which the device. The name should consist of
  1327. lower-case characters without spaces. Valid characters are
  1328. <code>a-z 0-9</code> and <code>-</code> (dash),
  1329. other characters should not be used. Here is a list of "official"
  1330. devices:<br>
  1331. <b>Sender/Sensor</b>: itremote<br>
  1332. <b>Dimmer</b>: itdimmer<br>
  1333. <b>Receiver/Actor</b>: itswitch<br>
  1334. <b>EV1527</b>: ev1527
  1335. </li><br>
  1336. <a name="ignore"></a>
  1337. <li>ignore<br>
  1338. Ignore this device, e.g. if it belongs to your neighbour. The device
  1339. won't trigger any FileLogs/notifys, issued commands will be silently
  1340. ignored (no RF signal will be sent out, just like for the <a
  1341. href="#attrdummy">dummy</a> attribute). The device won't appear in the
  1342. list command (only if it is explicitely asked for it), nor will it
  1343. be affected by commands which use wildcards or attributes as name specifiers
  1344. (see <a href="#devspec">devspec</a>). You still get them with the
  1345. "ignored=1" special devspec.
  1346. </li><br>
  1347. </ul>
  1348. <br>
  1349. <a name="ITevents"></a>
  1350. <b>Generated events:</b>
  1351. <ul>
  1352. From an IT device you can receive the following events.
  1353. <li>on</li>
  1354. <li>off</li>
  1355. <li>dimdown</li>
  1356. <li>dimup<br></li>
  1357. <li>dim06% dim12% dim18% dim25% dim31% dim37% dim43% dim50%<br>
  1358. dim56% dim62% dim68% dim75% dim81% dim87% dim93% dim100%<br></li>
  1359. Which event is sent is device dependent and can sometimes configured on
  1360. the device.
  1361. </ul>
  1362. </ul>
  1363. =end html
  1364. =begin html_DE
  1365. <a name="IT"></a>
  1366. <h3>IT - InterTechno</h3>
  1367. <ul>
  1368. Das InterTechno 433MHZ Protokoll wird von einer Vielzahl von Ger&auml;ten
  1369. benutzt. Diese geh&ouml;ren entweder zur Kategorie Sender/Sensoren oder zur
  1370. Kategorie Empf&auml;nger/Aktoren. Es ist das Senden sowie das Empfangen von InterTechno
  1371. Befehlen m&ouml;glich. Ger&auml;ten können z.B.
  1372. Schalter, Dimmer usw. sein.
  1373. Von diesem Modul wird sowohl das Protolkoll 1 sowie das Protokoll 3 unterstützt.
  1374. Neu empfangene Pakete werden per Autocreate in Fhem unter der Kategorie IT angelegt.
  1375. Hinweis: IT Protokoll 1 devices werden nur beim on Befehl angelegt.
  1376. <br><br>
  1377. <a name="ITdefine"></a>
  1378. <b>Define</b>
  1379. <ul>
  1380. <code>define &lt;name&gt; IT &lt;housecode&gt; &lt;on-code&gt; &lt;off-code&gt;
  1381. [&lt;dimup-code&gt;] [&lt;dimdown-code&gt;] </code>
  1382. <br>oder<br>
  1383. <code>define &lt;name&gt; IT &lt;ITRotarySwitches|FLS100RotarySwitches&gt; </code>
  1384. <br>oder<br>
  1385. <code>define &lt;name&gt; IT &lt;Adresse 26 Bit&gt; &lt;Group bit&gt; &lt;Unit Code&gt;</code>
  1386. <br>oder<br>
  1387. <code>define &lt;name&gt; IT HE800 &lt;Transmitter ID&gt; &lt;Receiver ID&gt;</code>
  1388. <br><br>
  1389. Der Wert von housecode ist abh&auml;ngig vom verwendeten Ger&auml;t und besteht aus zehn Ziffern InterTechno-Code Protokoll 1.
  1390. Da dieser ein tri-State-Protokoll ist, k&ouml;nnen die Ziffern jeweils 0/1/F annehmen.
  1391. <br>
  1392. Bit 11/12 werden f&uuml;r Schalten oder Dimmen verwendet. Da die Hersteller verschiedene Codes verwenden, k&ouml;nnen hier die
  1393. (2-stelligen) Codes f&uuml;r an, aus, heller und dunkler (on/off/dimup/dimdown) als tri-State-Ziffern (0/1/F) festgelegt werden.
  1394. <br>
  1395. Der Wert des ITRotary-Schalters setzt sich aus dem Wert des Buchstaben-Schalters A-P und dem numerischen Schalter 1-16
  1396. des InterTechno-Ger&auml;tes zusammen, z.B. A1 oder G12.
  1397. <br>
  1398. Der Wert des FLS100Rotary-Schalters setzt sich aus dem Wert des Schalters I,II,II,IV und dem numerischen Schalter 1-4
  1399. des InterTechno-Ger&auml;tes zusammen, z.B. I2 oder IV4.
  1400. <br>
  1401. Die Werte der ITRotary-Schalter und FLS100Rotary-Schalter werden intern in housecode-Werte umgewandelt.
  1402. <br>
  1403. F&uuml;r Intertechno Protokoll 3 besteht der hauscode aus 26 Ziffern. Zusätzlich werden noch 4 Ziffern als Unit Code sowie eine Ziffer als Group code benötigt.
  1404. <br>
  1405. Neues IT Element in FHEM anlegen: define IT myITSwitch IT <Adresse 26 Bit> <Group bit> <Unit Code>
  1406. <br>
  1407. <ul>
  1408. <li><code>&lt;housecode&gt;</code> 10 Ziffern lange tri-State-Zahl (0/1/F) abh&auml;ngig vom benutzten Ger&auml;t.</li>
  1409. <li><code>&lt;on-code&gt;</code> 2 Ziffern lange tri-State-Zahl, die den Einschaltbefehl enth&auml;lt;
  1410. die Zahl wird an den housecode angef&uuml;gt, um den 12-stelligen IT-Sendebefehl zu bilden.</li>
  1411. <li><code>&lt;off-code&gt;</code> 2 Ziffern lange tri-State-Zahl, die den Ausschaltbefehl enth&auml;lt;
  1412. die Zahl wird an den housecode angef&uuml;gt, um den 12-stelligen IT-Sendebefehl zu bilden.</li>
  1413. <li>Der optionale <code>&lt;dimup-code&gt;</code> ist eine 2 Ziffern lange tri-State-Zahl, die den Befehl zum Heraufregeln enth&auml;lt;
  1414. die Zahl wird an den housecode angef&uuml;gt, um den 12-stelligen IT-Sendebefehl zu bilden.</li>
  1415. <li>Der optionale <code>&lt;dimdown-code&gt;</code> ist eine 2 Ziffern lange tri-State-Zahl, die den Befehl zum Herunterregeln enth&auml;lt;
  1416. die Zahl wird an den housecode angef&uuml;gt, um den 12-stelligen IT-Sendebefehl zu bilden.</li>
  1417. </ul>
  1418. <br>
  1419. <b>HE800</b><br>
  1420. <ul>
  1421. <li><code>&lt;Transmitter ID&gt;</code> Eindeutige Transmitter-ID (1..65535)</li>
  1422. <li><code>&lt;Receiver ID&gt;</code> Receiver-ID [0]1..15, 0=Broadcast 1-15 (HE844A button# 1-4 & MASTER=0, HE850 UNIT# 1-15, HE853 = 1)</li>
  1423. </ul>
  1424. <br>
  1425. Beispiele:
  1426. <ul>
  1427. <code>define lamp IT 01FF010101 11 00 01 10</code><br>
  1428. <code>define roll1 IT 111111111F 11 00 01 10</code><br>
  1429. <code>define otherlamp IT 000000000F 11 10 00 00</code><br>
  1430. <code>define otherroll1 IT FFFFFFF00F 11 10</code><br>
  1431. <code>define IT_1527xe0fec IT 1527xe0fec 1001 0000</code><br>
  1432. <code>define itswitch1 IT A1</code><br>
  1433. <code>define lamp IT J10</code><br>
  1434. <code>define flsswitch1 IT IV1</code><br>
  1435. <code>define lamp IT II2</code><br>
  1436. <code>define HE800_TID1_SW1 IT HE800 1 1</code><br>
  1437. </ul>
  1438. <br>
  1439. F&uuml;r Intertechno Protokoll 3 ist der &lt;housecode&gt; eine 26-stellige Zahl. Zus&auml;tzlich wird noch ein 1 stelliger Gruppen-Code, sowie
  1440. ein 4-stelliger unit code verwendet.
  1441. <ul>
  1442. <li><code>&lt;address&gt;</code> ist eine 26-stellige Nummer (0/1)</li>
  1443. <li><code>&lt;group&gt;</code> ist eine 1-stellige Nummer (0/1)</li>
  1444. <li><code>&lt;unit&gt;</code> ist eine 4-stellige Nummer (0/1)</li>
  1445. </ul>
  1446. <br>
  1447. Beispiele:
  1448. <ul>
  1449. <code>define myITSwitch IT 00111100110101010110011111 0 0000</code>
  1450. </ul>
  1451. </ul>
  1452. <br>
  1453. <a name="ITset"></a>
  1454. <b>Set </b>
  1455. <ul>
  1456. <code>set &lt;name&gt; &lt;value&gt; [&lt;time&gt]</code>
  1457. <br><br>
  1458. wobei <code>value</code> eines der folgenden Schl&uuml;sselw&ouml;rter ist:<br>
  1459. <pre>
  1460. dimdown
  1461. dimup
  1462. off
  1463. on
  1464. on-till # siehe Anmerkungen
  1465. <li>Die <a href="#setExtensions">set extensions</a> werden unterst&uuml;tzt.</li>
  1466. </pre>
  1467. Beispiele:
  1468. <ul>
  1469. <code>set lamp on</code><br>
  1470. <code>set lamp1,lamp2,lamp3 on</code><br>
  1471. <code>set lamp1-lamp3 on</code><br>
  1472. <code>set lamp off</code><br>
  1473. </ul>
  1474. <br>
  1475. Anmerkungen:
  1476. <ul>
  1477. <li>on-till erfordert eine Zeitangabe im "at"-Format (HH:MM:SS, HH:MM
  1478. oder { &lt;perl code&gt; }, wobei dieser Perl-Code eine Zeitangabe zur&uuml;ckgibt).
  1479. Ist die aktuelle Zeit gr&ouml;&szlig;er als die Zeitangabe, wird der Befehl verworfen,
  1480. andernfalls wird ein Einschaltbefehl gesendet und f&uuml;r die Zeitangabe ein
  1481. Ausschaltbefehl mittels "at"-Befehl angelegt.
  1482. </li>
  1483. </ul>
  1484. </ul>
  1485. <br>
  1486. <b>Get</b> <ul>N/A (nicht vorhanden)</ul><br>
  1487. <a name="ITattr"></a>
  1488. <b>Attributes</b>
  1489. <ul>
  1490. <a name="IODev"></a>
  1491. <li>IODev<br>
  1492. Spezifiziert das physische Ger&auml;t, das die Ausstrahlung der Befehle f&uuml;r das
  1493. "logische" Ger&auml;t ausf&uuml;hrt. Ein Beispiel f&uuml;r ein physisches Ger&auml;t ist ein CUL.<br>
  1494. Anmerkung: Beim Start weist fhem einem InterTechno-Ger&auml;t kein IO-Ger&auml;t zu.
  1495. Das Attribut IODev ist daher IMMER zu setzen.</li><br>
  1496. <a name="eventMap"></a>
  1497. <li>eventMap<br>
  1498. Ersetzt Namen von Ereignissen und set Parametern. Die Liste besteht dabei
  1499. aus mit Doppelpunkt verbundenen Wertepaaren, die durch Leerzeichen getrennt
  1500. sind. Der erste Teil des Wertepaares ist der "alte" Wert, der zweite der neue/gew&uuml;nschte.
  1501. Ist das erste Zeichen der Werteliste ein Komma (,) oder ein Schr&auml;gsstrich (/), wird
  1502. das Leerzeichen als Listenzeichen durch dieses ersetzt. Dies erlaubt die Benutzung
  1503. von Leerzeichen innerhalb der Werte.
  1504. Beispiele:<ul><code>
  1505. attr store eventMap on:open off:closed<br>
  1506. attr store eventMap /on-for-timer 10:open/off:closed/<br>
  1507. set store open
  1508. </code></ul>
  1509. </li><br>
  1510. <li><a href="#do_not_notify">do_not_notify</a></li><br>
  1511. <a name="attrdummy"></a>
  1512. <li>dummy<br>
  1513. Mit der Eigenschaft dummy lassen sich Ger&auml;te definieren, die keine physikalischen Befehle
  1514. senden sollen. Verkn&uuml;pfte notifys werden trotzdem ausgef&uuml;hrt. Damit kann z.B. auf Sendebefehle
  1515. reagiert werden, die &uuml;ber die Weboberfl&auml;che ausgel&ouml;st wurden, ohne dass der Befehl physikalisch
  1516. gesendet wurde.
  1517. </li><br>
  1518. <li><a href="#loglevel">loglevel</a></li><br>
  1519. <li><a href="#showtime">showtime</a></li><br>
  1520. <li><a href="#readingFnAttributes">readingFnAttributes</a></li><br>
  1521. <a name="model"></a>
  1522. <li>model<br>
  1523. Hiermit kann das Modell des IT-Ger&auml;ts n&auml;her beschrieben werden. Diese
  1524. Eigenschaft wird (im Moment) nicht von fhem ausgewertet.
  1525. Mithilfe dieser Information k&ouml;nnen externe Programme oder Web-Interfaces
  1526. Ger&auml;teklassen unterscheiden, um geeignete Kommandos zu senden (z.B. "on"
  1527. oder "off" an Schalter, aber "dim..%" an Dimmer usw.). Die Schreibweise
  1528. der Modellbezeichnung sollten der dem Ger&auml;t mitgelieferten Dokumentation
  1529. in Kleinbuchstaben ohne Leerzeichen entsprechen.
  1530. Andere Zeichen als <code>a-z 0-9</code> und <code>-</code> (Bindestrich)
  1531. sollten vermieden werden. Dies ist die Liste der "offiziellen" Modelltypen:<br>
  1532. <b>Sender/Sensor</b>: itremote<br>
  1533. <b>Dimmer</b>: itdimmer<br>
  1534. <b>Empf&auml;nger/Actor</b>: itswitch<br>
  1535. <b>EV1527</b>: ev1527
  1536. </li><br>
  1537. <a name="ignore"></a>
  1538. <li>ignore<br>
  1539. Durch das Setzen dieser Eigenschaft wird das Ger&auml;t nicht durch fhem beachtet,
  1540. z.B. weil es einem Nachbarn geh&ouml;rt. Aktivit&auml;ten dieses Ger&auml;tes erzeugen weder
  1541. Log-Eintr&auml;ge noch reagieren notifys darauf, erzeugte Kommandos werden ignoriert
  1542. (wie bei Verwendung des Attributes <a href="#attrdummy">dummy</a> werden keine
  1543. Signale gesendet). Das Ger&auml;t ist weder in der Ausgabe des list-Befehls enthalten
  1544. (au&szlig;er es wird explizit aufgerufen), noch wird es bei Befehlen ber&uuml;cksichtigt,
  1545. die mit Platzhaltern in Namensangaben arbeiten (siehe <a href="#devspec">devspec</a>).
  1546. Sie werden weiterhin mit der speziellen devspec (Ger&auml;tebeschreibung) "ignored=1" gefunden.
  1547. </li><br>
  1548. </ul>
  1549. <br>
  1550. <a name="ITevents"></a>
  1551. <b>Erzeugte Ereignisse (Events):</b>
  1552. <ul>
  1553. Ein IT-Ger&auml;t kann folgende Ereignisse generieren:
  1554. <li>on</li>
  1555. <li>off</li>
  1556. <li>dimdown</li>
  1557. <li>dimup<br></li>
  1558. Welche Ereignisse erzeugt werden ist ger&auml;teabh&auml;ngig und kann evtl. am Ger&auml;t eingestellt werden.
  1559. </ul>
  1560. </ul>
  1561. =end html_DE
  1562. =cut