diff --git a/FHEM/10_IT.pm b/FHEM/10_IT.pm index 655f15fda..816ff9e83 100644 --- a/FHEM/10_IT.pm +++ b/FHEM/10_IT.pm @@ -18,6 +18,9 @@ my %codes = ( "XMITon" => "on", "XMITdimup" => "dimup", "XMITdimdown" => "dimdown", + "XMITgroup" => "group", + "XMITunit" => "unit", + "XMITprotocol" => "protocol", "99" => "on-till", ); @@ -37,6 +40,11 @@ my %bintotristate=( "01" => "F", "11" => "1" ); +my %bintotristateV3=( + "10" => "1", + "01" => "0", + "11" => "D" +); sub IT_Initialize($) { @@ -46,14 +54,16 @@ IT_Initialize($) $it_c2b{$codes{$k}} = $k; } - $hash->{Match} = "^i......\$"; + $hash->{Match} = "^i......"; $hash->{SetFn} = "IT_Set"; $hash->{StateFn} = "IT_SetState"; $hash->{DefFn} = "IT_Define"; $hash->{UndefFn} = "IT_Undef"; $hash->{ParseFn} = "IT_Parse"; - $hash->{AttrList} = "IODev ITfrequency ITrepetition switch_rfmode:1,0 do_not_notify:1,0 ignore:0,1 dummy:1,0 model:itremote,itswitch,itdimmer loglevel:0,1,2,3,4,5,6"; + $hash->{AttrList} = "IODev ITfrequency ITrepetition switch_rfmode:1,0 do_not_notify:1,0 ignore:0,1 dummy:1,0 model:itremote,itswitch,itdimmer protocol:V1,V3 loglevel:0,1,2,3,4,5,6"; + $hash->{AutoCreate}= + { "IT.*" => { GPLOT => "", FILTER => "%NAME" } }; } ##################################### @@ -147,8 +157,12 @@ IT_Set($@) } my $v = $name ." ". join(" ", @a); - $message = "is".uc($hash->{XMIT}.$hash->{$c}); - + if ($hash->{$it_c2b{"protocol"}} eq "V3") { + $message = "is".uc(substr($hash->{XMIT},0,length($hash->{XMIT})-5).$hash->{$it_c2b{"group"}}.$hash->{$c}.$hash->{$it_c2b{"unit"}}); + } else { + $message = "is".uc($hash->{XMIT}.$hash->{$c}); + } + ## Log that we are going to switch InterTechno Log GetLogLevel($name,2), "IT set $v"; (undef, $v) = split(" ", $v, 2); # Not interested in the name... @@ -186,8 +200,8 @@ IT_Set($@) # Look for all devices with the same code, and set state, timestamp my $code = "$hash->{XMIT}"; my $tn = TimeNow(); - foreach my $n (keys %{ $modules{IT}{defptr}{$code} }) { - + + foreach my $n (keys %{ $modules{IT}{defptr}{$code} }) { my $lh = $modules{IT}{defptr}{$code}{$n}; $lh->{CHANGED}[0] = $v; $lh->{STATE} = $v; @@ -236,21 +250,50 @@ IT_Define($$) } my $u = "wrong syntax: define IT 10-bit-housecode " . - "off-code on-code [dimup-code] [dimdown-code]"; + "off-code on-code [dimup-code] [dimdown-code] or for protocol V3 " . + "define IT <26 bit Address> <1 bit group bit> <4 bit unit>"; return $u if(int(@a) < 5); - return "Define $a[0]: wrong IT-Code format: specify a 10 digits 0/1/f " - if( ($a[2] !~ m/^[f0-1]{10}$/i) ); - return "Define $a[0]: wrong ON format: specify a 2 digits 0/1/f " + my $housecode; + + my $oncode; + my $offcode; + my $unitCode; + my $groupBit; + + if (length($a[2]) == 26) { + # Is Protocol V3 + return "Define $a[0]: wrong IT-Code format: specify a 26 digits 0/1 " + if( ($a[2] !~ m/^[0-1]{26}$/i) ); + return "Define $a[0]: wrong Bit Group format: specify a 1 digits 0/1 " + if( ($a[3] !~ m/^[0-1]{1}$/i) ); + return "Define $a[0]: wrong Unit format: specify 4 digits 0/1 " + if( ($a[4] !~ m/^[0-1]{4}$/i) ); + #return "Define $a[0]: wrong on/off/dimm format: specify a 1 digits 0/1/d " + # if( ($a[3] !~ m/^[d0-1]{1}$/i) ); + $housecode=$a[2].$a[3].$a[4]; + $groupBit=$a[3]; + $unitCode=$a[4]; + $oncode = 1; + $offcode = 0; + $hash->{$it_c2b{"protocol"}} = 'V3'; + $hash->{$it_c2b{"unit"}} = $unitCode; + $hash->{$it_c2b{"group"}} = $groupBit; + } else { + return "Define $a[0]: wrong IT-Code format: specify a 10 digits 0/1/f " + if( ($a[2] !~ m/^[f0-1]{10}$/i) ); + return "Define $a[0]: wrong ON format: specify a 2 digits 0/1/f " if( ($a[3] !~ m/^[f0-1]{2}$/i) ); - return "Define $a[0]: wrong OFF format: specify a 2 digits 0/1/f " + return "Define $a[0]: wrong OFF format: specify a 2 digits 0/1/f " if( ($a[4] !~ m/^[f0-1]{2}$/i) ); + $housecode = $a[2]; + $oncode = $a[3]; + $offcode = $a[4]; + $hash->{$it_c2b{"protocol"}} = 'V1'; + } - my $housecode = $a[2]; - my $oncode = $a[3]; - my $offcode = $a[4]; $hash->{XMIT} = lc($housecode); $hash->{$it_c2b{"on"}} = lc($oncode); @@ -275,9 +318,10 @@ IT_Define($$) my $ncode = 1; my $name = $a[0]; + $hash->{CODE}{$ncode++} = $code; $modules{IT}{defptr}{$code}{$name} = $hash; - + AssignIoPort($hash); } @@ -292,6 +336,7 @@ IT_Undef($$) # As after a rename the $name my be different from the $defptr{$c}{$n} # we look for the hash. + foreach my $dname (keys %{ $modules{IT}{defptr}{$c} }) { delete($modules{IT}{defptr}{$c}{$dname}) if($modules{IT}{defptr}{$c}{$dname} == $hash); @@ -305,38 +350,95 @@ IT_Parse($$) { my ($hash, $msg) = @_; my $housecode; + my $unitCode; + my $groupBit; my $onoffcode; my $def; my $newstate; my @list; - if (length($msg) != 7) { + if (length($msg) != 7 && length($msg) != 17) { Log3 undef,3,"message \"$msg\" to short!"; return "message \"$msg\" to short!"; } - my $bin=sprintf("%024b",hex(substr($msg,1,length($msg)-1))); + my $bin = undef; + if ( length($msg) == 17 ) { + my $bin1=sprintf("%024b",hex(substr($msg,1,length($msg)-1-8))); + while (length($bin1) < 32) { + # suffix 0 + $bin1 = '0'.$bin1; + } + my $bin2=sprintf("%024b",hex(substr($msg,1+8,length($msg)-1))); + while (length($bin2) < 32) { + # suffix 0 + $bin2 = '0'.$bin2; + } + $bin = $bin1 . $bin2; + } + else { + $bin=sprintf("%024b",hex(substr($msg,1,length($msg)-1))); + } + if ((length($bin) % 2) != 0) { + # suffix 0 + $bin = '0'.$bin; + } + #Log3 undef,4,"BIN: $bin"; my $msgcode=""; while (length($bin)>=2) { - if (substr($bin,0,2) != "10") { - $msgcode=$msgcode.$bintotristate{substr($bin,0,2)}; + if (length($msg) == 7) { + if (substr($bin,0,2) != "10") { + $msgcode=$msgcode.$bintotristate{substr($bin,0,2)}; + } else { + Log3 undef,4,"unknown tristate in \"$bin\""; + return "unknown tristate in \"$bin\"" + } } else { - Log3 undef,4,"unknown tristate in \"$bin\""; - return "unknown tristate in \"$bin\"" + $msgcode=$msgcode.$bintotristateV3{substr($bin,0,2)}; } $bin=substr($bin,2,length($bin)-2); } - $housecode=substr($msgcode,0,length($msgcode)-2); - $onoffcode=substr($msgcode,length($msgcode)-2,2); - - #Log3 $hash,3,$msg."->".$msgcode."->".$housecode." ".$onoffcode; - if(!defined($modules{IT}{defptr}{lc($housecode)})) { - Log3 undef,4,"$housecode not defined (Switch code: $onoffcode)"; - return "$housecode not defined (Switch code: $onoffcode)!"; + if (length($msg) == 7) { + $housecode=substr($msgcode,0,length($msgcode)-2); + $onoffcode=substr($msgcode,length($msgcode)-2,2); + } elsif (length($msg) == 17) { + $groupBit=substr($msgcode,26,1); + $onoffcode=substr($msgcode,27,1); + $unitCode=substr($msgcode,28,4); + $housecode=substr($msgcode,0,26).$groupBit.$unitCode; + } else { + Log3 undef,4,"Wrong IT message received: $msgcode"; + return "Wrong IT message received: $msgcode"; + } + + if(!defined($modules{IT}{defptr}{lc("$housecode")})) { + if(length($msg) == 7) { + Log3 undef,4,"$housecode not defined (Switch code: $onoffcode)"; + #return "$housecode not defined (Switch code: $onoffcode)!"; + if ($onoffcode eq "F0") { # on code IT + Log3 undef,4,"For autocreate please use the on button."; + return "$housecode not defined (Switch code: $onoffcode)! \n For autocreate please use the on button."; + } + my $tmpOffCode = "F0"; + my $tmpOnCode = "0F"; + if ($onoffcode eq "FF") { # on code IT + $tmpOnCode = "FF"; + } + return "UNDEFINED IT_$housecode IT $housecode $tmpOnCode $tmpOffCode" if(!$def); + } else { + Log3 undef,4,"$housecode not defined (Address: ".substr($msgcode,0,26)." Group: $groupBit Unit: $unitCode Switch code: $onoffcode)"; + #return "$housecode not defined (Address: ".substr($msgcode,0,26)." Group: $groupBit Unit: $unitCode Switch code: $onoffcode)!"; + return "UNDEFINED IT_$housecode IT " . substr($msgcode,0,26) . " $groupBit $unitCode" if(!$def); + } } $def=$modules{IT}{defptr}{lc($housecode)}; foreach my $name (keys %{$def}) { + if (length($msg) == 17) { + if ($def->{$name}->{$it_c2b{"group"}} != $groupBit || $def->{$name}->{$it_c2b{"unit"}} != $unitCode) { + next; + } + } if ($def->{$name}->{$it_c2b{"on"}} eq lc($onoffcode)) { $newstate="on"; } elsif ($def->{$name}->{$it_c2b{"off"}} eq lc($onoffcode)) { @@ -362,9 +464,13 @@ IT_Parse($$)

IT - InterTechno


@@ -553,10 +673,13 @@ IT_Parse($$)
diff --git a/MAINTAINER.txt b/MAINTAINER.txt index cf386f80c..b9da546b7 100644 --- a/MAINTAINER.txt +++ b/MAINTAINER.txt @@ -50,7 +50,7 @@ FHEM/10_FBDECT.pm rudolfkoenig http://forum.fhem.de FRITZ!Box FHEM/10_FRM.pm ntruchsess http://forum.fhem.de Sonstige Systeme FHEM/10_FS20.pm rudolfkoenig http://forum.fhem.de SlowRF FHEM/00_HXBDevice.pm borisneubert http://forum.fhem.de Sonstige Systeme -FHEM/10_IT.pm justme1968 http://forum.fhem.de InterTechno +FHEM/10_IT.pm dancer0705/bjoernh http://forum.fhem.de InterTechno FHEM/10_Itach_IR ulimaass http://forum.fhem.de Sonstige Systeme FHEM/10_MAX.pm mgehre http://forum.fhem.de MAX FHEM/10_MQTT_BRIDGE ntruchsess http://forum.fhem.de Sonstige Systeme @@ -67,7 +67,7 @@ FHEM/11_OWDevice.pm borisneubert/mfr69bs http://forum.fhem.de 1Wire FHEM/12_HMS.pm rudolfkoenig http://forum.fhem.de SlowRF FHEM/13_KS300.pm rudolfkoenig http://forum.fhem.de SlowRF FHEM/14_CUL_MAX.pm mgehre http://forum.fhem.de MAX -FHEM/14_CUL_TCM97001.pm dancer0705 http://forum.fhem.de Sonstiges +FHEM/14_CUL_TCM97001.pm dancer0705/bjoernh http://forum.fhem.de Sonstiges FHEM/14_CUL_TX.pm rudolfkoenig http://forum.fhem.de SlowRF FHEM/14_CUL_WS.pm rudolfkoenig http://forum.fhem.de SlowRF FHEM/15_CUL_EM.pm rudolfkoenig http://forum.fhem.de SlowRF