From ef278ca11d1cde1d9a3491e9e4c0f47cc054614a Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sat, 12 May 2012 06:54:30 +0000 Subject: [PATCH] threeState rewrite according to tobi73's observations git-svn-id: https://svn.fhem.de/fhem/trunk@1553 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/10_CUL_HM.pm | 77 ++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/fhem/FHEM/10_CUL_HM.pm b/fhem/FHEM/10_CUL_HM.pm index 7c362003f..bcbeb13e5 100755 --- a/fhem/FHEM/10_CUL_HM.pm +++ b/fhem/FHEM/10_CUL_HM.pm @@ -672,52 +672,47 @@ CUL_HM_Parse($$) push @event, "unknownMsg:$p" if(!@event); } elsif($st eq "threeStateSensor") { ##################################### - $p =~ m/^....(..)$/; - my $lst = defined($1) ? $1 : "00"; - my $chn = "01"; - #tobi73: modified 0601.. ->> 06.. - # for multichannel Alive Message - Bytes 3/4=channel ID to be ignored... - if($p =~ m/^06....00$/) { - push @event, "alive:yes"; + if($p =~ m/^(..)(..)(..)(..)?$/) { + #tobi73 + # "Normal": Byte1/2:chn, 3/4:counter, 5/6:State + # "State": Byte1/2: 06, 3/4:channel, 5/6:State, 7/8:additional info + my ($b12, $b34, $b56, $b78) = ($1, $2, $3, $4); + my $lst = $b56; # Local state; + my $chn; + my $addState = ""; + + if($b12 eq "06") { + push @event, "alive:yes"; + $chn = $b34; + if($b78) { + push(@event, "battery:". (hex($b78) & 0x80) ? "empty" : "ok"); + $addState = " sabotage" if($b78 =~ m/^.E/); + } + + } else { + $chn = $b12; - #tobi73: For Alive Message of SCI: Bytes 5/6 used for status - if($model eq "HM-SCI-3-FM") { - $p =~ m/^....(..)..$/; - $lst = defined($1) ? $1 : "00"; } - } - # Multi-channel device: Switch to the shadow source hash - # for the HM-SCI-3-FM - if($p =~ m/^(..)(..)/) { - #tobi73: For Alive Message of SCI channel ID in byte 3/4 - $chn = ($model eq "HM-SCI-3-FM") ? $2 : $1; + + # Multi-channel device: Switch to the shadow source hash + if($chn && $chn ne "01" && $chn ne "00") { + my $sshash = $modules{CUL_HM}{defptr}{"$src$chn"}; + $shash = $sshash if($sshash); + $name = $shash->{NAME}; + } + + my %txt; + %txt = ("C8"=>"open", "64"=>"tilted", "00"=>"closed"); + %txt = ("C8"=>"wet", "64"=>"damp", "00"=>"dry") # by peterp + if($model eq "HM-SEC-WDS"); + my $txt = $txt{$lst}; + $txt = "unknown:$lst" if(!$txt); + push @event, "state:$txt$addState$target"; + CUL_HM_SendCmd($shash, "++8002$id$src${chn}00",1,0) # Send Ack + if($id eq $dst); } - if($chn && $chn ne "01" && $chn ne "00") { - my $sshash = $modules{CUL_HM}{defptr}{"$src$chn"}; - $shash = $sshash if($sshash); - $name = $shash->{NAME}; - } - - my %txt; - %txt = ("C8"=>"open", "64"=>"tilted", "00"=>"closed"); - %txt = ("C8"=>"wet", "64"=>"damp", "00"=>"dry") # by peterp - if($model eq "HM-SEC-WDS"); - - if($txt{$lst}) { - push @event, "state:$txt{$lst}$target"; - - } else { - $lst = "00"; # for the ack - } - - if($p =~ m/^0601..0E$/) { - push @event, "state:sabotage"; - } - - CUL_HM_SendCmd($shash, "++8002$id$src${chn}01${lst}00",1,0) # Send Ack - if($id eq $dst); push @event, "unknownMsg:$p" if(!@event);