ActionDetect startup change, virtual actor,weather Reading WCD7000...

git-svn-id: https://svn.fhem.de/fhem/trunk@2043 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
martinp876
2012-10-30 20:08:27 +00:00
parent 0a9e4c6669
commit ad0f30a8ac

View File

@@ -208,7 +208,7 @@ CUL_HM_Initialize($)
"showtime:1,0 loglevel:0,1,2,3,4,5,6 ". "showtime:1,0 loglevel:0,1,2,3,4,5,6 ".
"hmClass:receiver,sender serialNr firmware devInfo ". "hmClass:receiver,sender serialNr firmware devInfo ".
"rawToReadable unit ". "rawToReadable unit ".
"chanNo device peerList ". "chanNo device peerList peerIDs ".
"actCycle actStatus ". "actCycle actStatus ".
"protCmdPend protLastRcv protSndCnt protSndLast protCmdDel protNackCnt protNackLast ". "protCmdPend protLastRcv protSndCnt protSndLast protCmdDel protNackCnt protNackLast ".
"protResndFailLast protResndLast protResndFailCnt protResndCnt protToutRespLast protToutRespCnt ". "protResndFailLast protResndLast protResndFailCnt protResndCnt protToutRespLast protToutRespCnt ".
@@ -259,7 +259,7 @@ CUL_HM_Define($$)
$modules{CUL_HM}{defptr}{$HMid} = $hash; $modules{CUL_HM}{defptr}{$HMid} = $hash;
AssignIoPort($hash); AssignIoPort($hash);
} }
CUL_HM_ActGetCreateHash() if($HMid eq '000000');#startTimer
if(int(@a) == 4) { if(int(@a) == 4) {
$hash->{DEF} = $a[2]; $hash->{DEF} = $a[2];
CUL_HM_Parse($hash, $a[3]); CUL_HM_Parse($hash, $a[3]);
@@ -809,20 +809,30 @@ CUL_HM_Parse($$)
elsif($st eq "motionDetector") { ##################################### elsif($st eq "motionDetector") { #####################################
# Code with help of Bassem # Code with help of Bassem
my $state; my $state;
if($msgType eq "10" && $p =~ m/^06..(..)(..)/) {#InfoLevel if(($msgType eq "10" ||$msgType eq "02") && $p =~ m/^0601(..)(..)/) {
my $err; my $err;
($state, $err) = ($1, hex($2)); ($state, $err) = ($1, hex($2));
my $cmpVal = defined($shash->{helper}{addVal})?$shash->{helper}{addVal}:0xff; my $cmpVal = defined($shash->{helper}{addVal})?
$shash->{helper}{addVal}:0xff;
$cmpVal = (($cmpVal ^ $err)|$err); # all error,only one goto normal $cmpVal = (($cmpVal ^ $err)|$err); # all error,only one goto normal
$shash->{helper}{addVal} = $err;#store to handle changes $shash->{helper}{addVal} = $err;#store to handle changes
push @event, "brightness:".hex($state); my $bright = hex($state);
push @event, "brightness:".$bright
if (ReadingsVal($name,"brightness","") != $bright);# post if changed
push @event, "cover:". (($err&0x0E)?"open" :"closed") if ($cmpVal&0x0E); push @event, "cover:". (($err&0x0E)?"open" :"closed") if ($cmpVal&0x0E);
push @event, "battery:". (($err&0x80)?"low" :"ok" ) if ($cmpVal&0x80); push @event, "battery:". (($err&0x80)?"low" :"ok" ) if ($cmpVal&0x80);
} }
elsif($msgType eq "41" && $p =~ m/^..(......)/) { elsif($msgType eq "41" && $p =~ m/^..(..)(..)(..)/) {
$state = $1; my($cnt, $bright,$nextTr) = (hex($1), hex($2),(hex($3)>>4));
push @event, "state:motion"; push @event, "state:motion";
push @event, "motion:on$target"; #added peterp push @event, "motion:on$target"; #added peterp
push @event, "motionCount:".$cnt."_next:".$nextTr;
push @event, "brightness:".$bright
if (ReadingsVal($name,"brightness","") != $bright);# post if changed
}
elsif($msgType eq "70" && $p =~ m/^7F(..)(.*)/) {
my($d1, $d2) = ($1, $2);
push @event, 'devState_raw'.$d1.':'.$d2;
} }
CUL_HM_SendCmd($shash, $msgcnt."8002".$id.$src."0101${state}00",1,0) CUL_HM_SendCmd($shash, $msgcnt."8002".$id.$src."0101${state}00",1,0)
@@ -867,7 +877,9 @@ CUL_HM_Parse($$)
#AckStatus: msgType=0x02 p(..)(..)(..)(..) subty=01, chn, state,err (3bit) #AckStatus: msgType=0x02 p(..)(..)(..)(..) subty=01, chn, state,err (3bit)
if($p =~ m/^(..)(..)(..)(..)?$/) { if($p =~ m/^(..)(..)(..)(..)?$/) {
my ($b12, $b34, $state, $err) = ($1, $2, $3, hex($4)); my ($b12, $b34, $state) = ($1, $2, $3);
my $err;
$err = hex($4) if(defined($4));
my $chn = ($msgType eq "41")?$b12:$b34; my $chn = ($msgType eq "41")?$b12:$b34;
# Multi-channel device: Switch to channel hash # Multi-channel device: Switch to channel hash
$shash = $modules{CUL_HM}{defptr}{"$src$chn"} $shash = $modules{CUL_HM}{defptr}{"$src$chn"}
@@ -875,7 +887,7 @@ CUL_HM_Parse($$)
if ($msgType eq "02"||$msgType eq "10"){ if ($msgType eq "02"||$msgType eq "10"){
my $cmpVal = defined($shash->{helper}{addVal})?$shash->{helper}{addVal}:0xff; my $cmpVal = defined($shash->{helper}{addVal})?$shash->{helper}{addVal}:0xff;
$cmpVal = (($cmpVal ^ $err)|$err); # all error,only one goto normal $cmpVal = (defined($err))?(($cmpVal ^ $err)|$err):0; # all error,one normal
$shash->{helper}{addVal} = $err;#store to handle changes $shash->{helper}{addVal} = $err;#store to handle changes
push @event, "alive:yes"; push @event, "alive:yes";
@@ -901,9 +913,9 @@ CUL_HM_Parse($$)
push @event, "3SSunknownMsg:$p" if(!@event); push @event, "3SSunknownMsg:$p" if(!@event);
} }
elsif($model eq "HM-WDC7000" ||$st eq "THSensor") { #################### elsif($model eq "HM-WDC7000" ||$st eq "THSensor") { ####################
my $t = hex(substr($p,0,4));
my $t = hex(substr($p,0,4))/10; $t -= 32768 if($t > 1638.4);
$t -= 3276.8 if($t > 1638.4); $t = sprintf("%0.1f", $t/10);
my $h = hex(substr($p,4,2)); my $h = hex(substr($p,4,2));
my $ap = hex(substr($p,6,4)); my $ap = hex(substr($p,6,4));
my $statemsg = "state:T: $t"; my $statemsg = "state:T: $t";
@@ -979,6 +991,30 @@ CUL_HM_Parse($$)
else{##################################### else{#####################################
; # no one wants the message ; # no one wants the message
} }
#------------ parse for virtual destination ------------------
if (AttrVal($dname, "subType", "none") eq "virtual"){# see if need for answer
if($msgType =~ m/^4./ && $p =~ m/^(..)/) {
my ($recChn) = ($1);# button number/event count
my $recId = $src.$recChn;
for (my $cnt=1;$cnt<25;$cnt++) {#need to check each channel
my $dChNo = sprintf("%02X",$cnt);
my $dChName = AttrVal($dname,"channel_".$dChNo,"");
if (!$dChName){next;} # not channel provisioned
my @peerIDs = split(',',AttrVal($dChName,"peerIDs",""));
foreach my $pId (@peerIDs){
if ($pId eq $recId){ #match: we have to ack
my $dChHash = CUL_HM_name2hash($dChName);
my $state = ReadingsVal($dChName,"virtActState","C8");
$state = ($state eq "00")?"C8":"00";
setReadingsVal($dChHash,"virtActState",$state,$tn);
setReadingsVal($dChHash,"virtActTrigger",$name,$tn);
CUL_HM_SendCmd($dChHash,$msgcnt."8002".$dst.$src.'01'.$dChNo.
$state."00", 1, 0);
}
}
}
}
}
#------------ send default ACK if not applicable------------------ #------------ send default ACK if not applicable------------------
# ack if we are destination, anyone did accept the message (@event) # ack if we are destination, anyone did accept the message (@event)
# parser did not supress # parser did not supress
@@ -1006,7 +1042,7 @@ CUL_HM_Parse($$)
} }
} }
else { else {
push @changed, "$vn: $vv"; push @changed, "$vn: ".($vv)?$vv:"-";
} }
$shash->{READINGS}{$vn}{TIME} = $tn; $shash->{READINGS}{$vn}{TIME} = $tn;
$shash->{READINGS}{$vn}{VAL} = $vv; $shash->{READINGS}{$vn}{VAL} = $vv;
@@ -1113,6 +1149,9 @@ my %culHmRegDefine = (
DecalDay =>{a=>1.5 ,s=>0.3,l=>5,min=>0 ,max=>7 ,c=>'' ,f=>'' ,u=>'d' ,t=>"Decalc weekday 0=Sat...6=Fri"}, DecalDay =>{a=>1.5 ,s=>0.3,l=>5,min=>0 ,max=>7 ,c=>'' ,f=>'' ,u=>'d' ,t=>"Decalc weekday 0=Sat...6=Fri"},
DecalHr =>{a=>8.3 ,s=>0.5,l=>5,min=>0 ,max=>23 ,c=>'' ,f=>'' ,u=>'h' ,t=>"Decalc hour"}, DecalHr =>{a=>8.3 ,s=>0.5,l=>5,min=>0 ,max=>23 ,c=>'' ,f=>'' ,u=>'h' ,t=>"Decalc hour"},
DecalMin =>{a=>8 ,s=>0.3,l=>5,min=>0 ,max=>50 ,c=>'factor' ,f=>0.1 ,u=>'min' ,t=>"Decalc min"}, DecalMin =>{a=>8 ,s=>0.3,l=>5,min=>0 ,max=>50 ,c=>'factor' ,f=>0.1 ,u=>'min' ,t=>"Decalc min"},
#Thermal-cc-VD
ValveOffset =>{a=>9 ,s=>0.5,l=>5,min=>0 ,max=>25 ,c=>'' ,f=>'' ,u=>'%' ,t=>"Valve offset"}, # size actually 0.5
ValveError =>{a=>10 ,s=>1 ,l=>5,min=>0 ,max=>99 ,c=>'' ,f=>'' ,u=>'%' ,t=>"Valve position when error"},# size actually 0.7
#output Unit #output Unit
ActTypeSh =>{a=>36 ,s=>1 ,l=>3,min=>0 ,max=>255 ,c=>'' ,f=>'' ,u=>'' ,t=>"Short:Action type(LED or Tone)"}, ActTypeSh =>{a=>36 ,s=>1 ,l=>3,min=>0 ,max=>255 ,c=>'' ,f=>'' ,u=>'' ,t=>"Short:Action type(LED or Tone)"},
ActNumSh =>{a=>37 ,s=>1 ,l=>3,min=>1 ,max=>255 ,c=>'' ,f=>'' ,u=>'' ,t=>"Short:Action Number"}, ActNumSh =>{a=>37 ,s=>1 ,l=>3,min=>1 ,max=>255 ,c=>'' ,f=>'' ,u=>'' ,t=>"Short:Action Number"},
@@ -1175,6 +1214,7 @@ my %culHmRegSupported = (
TempWinOpen =>1, TempWinOpen =>1,
DecalHr =>1,DecalMin =>1, DecalHr =>1,DecalMin =>1,
BacklOnTime =>1,BacklOnMode =>1,BtnLock =>1, BacklOnTime =>1,BacklOnMode =>1,BtnLock =>1,
ValveOffset =>1,ValveError =>1,
}, },
outputUnit=>{ outputUnit=>{
OnDlySh =>1,OnTimeSh =>1,OffDlySh =>1,OffTimeSh =>1, OnDlySh =>1,OnTimeSh =>1,OffDlySh =>1,OffTimeSh =>1,
@@ -1421,6 +1461,8 @@ my %culHmModelSets = (
"displayTempUnit" => "[celsius|fahrenheit]", "displayTempUnit" => "[celsius|fahrenheit]",
"controlMode" => "[manual|auto|central|party]", "controlMode" => "[manual|auto|central|party]",
"decalcDay" => "day", }, "decalcDay" => "day", },
"HM-CC-VD"=>{
valvePos => "position",},
"HM-RC-19"=> { "HM-RC-19"=> {
service => "<count>", service => "<count>",
alarm => "<count>", alarm => "<count>",
@@ -1468,7 +1510,7 @@ CUL_HM_getRxType($)
# Will store result in device helper # Will store result in device helper
my ($hash) = @_; my ($hash) = @_;
$hash = CUL_HM_getDeviceHash($hash); $hash = CUL_HM_getDeviceHash($hash);
no warnings; #cnvert regardless of content no warnings; #convert regardless of content
my $rxtEntity = int($hash->{helper}{rxType}); my $rxtEntity = int($hash->{helper}{rxType});
use warnings; use warnings;
if (!$rxtEntity){ #at least one bit must be set if (!$rxtEntity){ #at least one bit must be set
@@ -1698,8 +1740,9 @@ CUL_HM_Set($@)
$dLen = int($dLen)*8+(($dLen*10)%10); $dLen = int($dLen)*8+(($dLen*10)%10);
# only allow it level if length less then one byte!! # only allow it level if length less then one byte!!
return "partial Word error: ".$dLen if($dLen != 8*int($dLen/8) && $dLen>7); return "partial Word error: ".$dLen if($dLen != 8*int($dLen/8) && $dLen>7);
no warnings qw(overflow portable);
my $mask = (0xffffffff>>(32-$dLen)); my $mask = (0xffffffff>>(32-$dLen));
use warnings qw(overflow portable);
my $dataStr = substr(sprintf("%08X",($data & $mask) << $bit), my $dataStr = substr(sprintf("%08X",($data & $mask) << $bit),
8-int($reg->{s}+0.99)*2,); 8-int($reg->{s}+0.99)*2,);
@@ -1998,6 +2041,11 @@ CUL_HM_Set($@)
$hash->{READINGS}{$vn}{TIME} = TimeNow(); $hash->{READINGS}{$vn}{TIME} = TimeNow();
$hash->{READINGS}{$vn}{VAL} = $msg; $hash->{READINGS}{$vn}{VAL} = $msg;
} }
elsif($cmd eq "valvePos") { ##################
my $vp = ($a[2]+0.5)*2.56;
my $d1 = 0;
CUL_HM_PushCmdStack($hash,sprintf("++A258%s%s%02X%02X",$id,$dst,$d1,$vp));
}
elsif($cmd eq "matic") { ##################################### elsif($cmd eq "matic") { #####################################
# Trigger pre-programmed action in the winmatic. These actions must be # Trigger pre-programmed action in the winmatic. These actions must be
# programmed via the original software. # programmed via the original software.
@@ -2096,11 +2144,11 @@ CUL_HM_Set($@)
} }
elsif($cmd eq "devicepair") { ############################################### elsif($cmd eq "devicepair") { ###############################################
#devicepair => "<btnNumber> device ... [single|dual] [set|unset] [actor|remote|both]" #devicepair => "<btnNumber> device ... [single|dual] [set|unset] [actor|remote|both]"
my ($bNo,$dev,$single,$set,$target) = ($a[2],$a[3],$a[4],$a[5],$a[6]); my ($bNo,$peerN,$single,$set,$target) = ($a[2],$a[3],$a[4],$a[5],$a[6]);
$state = ""; $state = "";
return "$bNo is not a button number" if(($bNo < 1) && !$chn); return "$bNo is not a button number" if(($bNo < 1) && !$chn);
my $peerHash = $defs{$dev} if ($dev); my $peerHash = $defs{$peerN} if ($peerN);
return "$dev not a CUL_HM device" return "$peerN not a CUL_HM device"
if(!$peerHash ||$peerHash->{TYPE} ne "CUL_HM"); if(!$peerHash ||$peerHash->{TYPE} ne "CUL_HM");
return "$single must be single or dual" return "$single must be single or dual"
if(defined($single) && (($single ne"single") &&($single ne"dual"))); if(defined($single) && (($single ne"single") &&($single ne"dual")));
@@ -2159,10 +2207,23 @@ CUL_HM_Set($@)
} }
} }
if (!$target || $target eq "actor" || $target eq "both"){ if (!$target || $target eq "actor" || $target eq "both"){
if (AttrVal( CUL_HM_id2Name($peerDst), "subType", "") eq "virtual"){
my $peerIDs = AttrVal($peerN,"peerIDs","");
my $pId = $dst.sprintf("%02X",$b1);
$peerIDs .= $pId."," if($peerIDs !~ m/$pId,/);
$attr{$peerN}{peerIDs} = $peerIDs;
my $peerList = "";
foreach my$tmpId (split(",",$peerIDs)){
$peerList .= CUL_HM_id2Name($tmpId);
}
$attr{$peerN}{peerList} = $peerList;
}
else{
my $peerFlag = CUL_HM_getFlag($peerHash); my $peerFlag = CUL_HM_getFlag($peerHash);
CUL_HM_PushCmdStack($peerHash, sprintf("++%s01%s%s%s%s%s%02X%02X", CUL_HM_PushCmdStack($peerHash, sprintf("++%s01%s%s%s%s%s%02X%02X",
$peerFlag,$id,$peerDst,$peerChn,$cmd,$dst,$b2,$b1 )); $peerFlag,$id,$peerDst,$peerChn,$cmd,$dst,$b2,$b1 ));
} }
}
$devHash = $peerHash; # Exchange the hash, as the switch is always alive. $devHash = $peerHash; # Exchange the hash, as the switch is always alive.
} }
@@ -2260,10 +2321,12 @@ CUL_HM_getConfig($$$$$){
my $flag = CUL_HM_getFlag($hash); my $flag = CUL_HM_getFlag($hash);
foreach my $readEntry (keys %{$chnhash->{READINGS}}){ foreach my $readEntry (keys %{$chnhash->{READINGS}}){
if ($readEntry =~ m/^RegL_/){ if ($readEntry =~ m/^RegL_/){#remove old lists, no longer valid
delete $chnhash->{READINGS}{$readEntry}; delete $chnhash->{READINGS}{$readEntry};
} }
} }
#get Peer-list in any case - it is part of the config
CUL_HM_PushCmdStack($hash,sprintf("++%s01%s%s%s03",$flag,$id,$dst,$chn));
my $lstAr = $culHmModel{CUL_HM_getMId($hash)}{lst}; my $lstAr = $culHmModel{CUL_HM_getMId($hash)}{lst};
my @list = split(",",$lstAr); #get valid lists e.g."1, 5:2:3.p ,6:2" my @list = split(",",$lstAr); #get valid lists e.g."1, 5:2:3.p ,6:2"
foreach my$listEntry (@list){# each list that is define for this channel foreach my$listEntry (@list){# each list that is define for this channel
@@ -2286,7 +2349,7 @@ CUL_HM_getConfig($$$$$){
#$listNo,$chnValid $peerReq #$listNo,$chnValid $peerReq
if ($chnValid){# yes, we will go for a list if ($chnValid){# yes, we will go for a list
if ($peerReq){# need to get the peers first if ($peerReq){# need to get the peers first
CUL_HM_PushCmdStack($hash,sprintf("++%s01%s%s%s03",$flag,$id,$dst,$chn)); # CUL_HM_PushCmdStack($hash,sprintf("++%s01%s%s%s03",$flag,$id,$dst,$chn));
$chnhash->{helper}{getCfgList} = "all";# peers first $chnhash->{helper}{getCfgList} = "all";# peers first
$chnhash->{helper}{getCfgListNo} = $listNo; $chnhash->{helper}{getCfgListNo} = $listNo;
} }
@@ -3135,7 +3198,7 @@ CUL_HM_secSince2000()
# verify that devices are seen in a certain period of time # verify that devices are seen in a certain period of time
# It will generate events if no message is seen sourced by the device during # It will generate events if no message is seen sourced by the device during
# that period. # that period.
# ActionDetector will use the fixed HMid 100100 # ActionDetector will use the fixed HMid 000000
sub sub
CUL_HM_ActGetCreateHash() CUL_HM_ActGetCreateHash()
{# return hash of ActionDetector - create one if not existant {# return hash of ActionDetector - create one if not existant
@@ -3143,9 +3206,27 @@ CUL_HM_ActGetCreateHash()
DoTrigger("global", "UNDEFINED ActionDetector CUL_HM 000000"); DoTrigger("global", "UNDEFINED ActionDetector CUL_HM 000000");
$attr{ActionDetector}{actCycle} = 600; $attr{ActionDetector}{actCycle} = 600;
} }
my $actName = CUL_HM_id2Name("000000"); my $defPtr = $modules{CUL_HM}{defptr};
my $actName = $defPtr->{"000000"}{NAME} if($defPtr->{"000000"});
my $actHash = $modules{CUL_HM}{defptr}{"000000"}; my $actHash = $modules{CUL_HM}{defptr}{"000000"};
if (!$actHash->{helper}{first}){ # if called first time arrributes are no yet
#recovered
InternalTimer(gettimeofday()+3, "CUL_HM_ActGetCreateHash", "ActionDetector", 0);
$actHash->{helper}{first} = 1;
return;
}
if (!$actHash->{helper}{actCycle} ){ #This is the first call
my $peerList = $attr{$actName}{peerList};
$peerList = "" if (!$peerList);
my $tn = TimeNow();
foreach my $devId (split(",",$peerList)){
$actHash->{helper}{$devId}{start} = $tn;
my $devName = CUL_HM_id2Name($devId);
setReadingsVal($actHash,"status_".$devName,"unknown",$tn);
$attr{$devName}{actStatus}=""; # force trigger
CUL_HM_setAttrIfCh($devName,"actStatus","unknown","Activity");
}
}
if (!$actHash->{helper}{actCycle} || if (!$actHash->{helper}{actCycle} ||
$actHash->{helper}{actCycle} != $attr{$actName}{actCycle}){ $actHash->{helper}{actCycle} != $attr{$actName}{actCycle}){
$attr{$actName}{actCycle} = 30 if(!$attr{$actName}{actCycle} || $attr{$actName}{actCycle} = 30 if(!$attr{$actName}{actCycle} ||
@@ -3153,6 +3234,7 @@ CUL_HM_ActGetCreateHash()
$actHash->{helper}{actCycle} = $attr{$actName}{actCycle}; $actHash->{helper}{actCycle} = $attr{$actName}{actCycle};
RemoveInternalTimer("ActionDetector"); RemoveInternalTimer("ActionDetector");
$actHash->{STATE} = "active"; $actHash->{STATE} = "active";
InternalTimer(gettimeofday()+$attr{$actName}{actCycle}, InternalTimer(gettimeofday()+$attr{$actName}{actCycle},
"CUL_HM_ActCheck", "ActionDetector", 0); "CUL_HM_ActCheck", "ActionDetector", 0);
} }
@@ -3176,20 +3258,21 @@ CUL_HM_ActAdd($$)
return $devId." is not an HM device - action detection cannot be added" return $devId." is not an HM device - action detection cannot be added"
if (length($devId) != 6); if (length($devId) != 6);
my ($cycleString,undef)=CUL_HM_time2sec($timeout); my ($cycleString,undef)=CUL_HM_time2sec($timeout);
my $devName = CUL_HM_id2Name($devId); my $devName = CUL_HM_id2Name($devId);
$attr{$devName}{actCycle} = $cycleString; $attr{$devName}{actCycle} = $cycleString;
$attr{$devName}{actStatus} = "unknown"; $attr{$devName}{actStatus}=""; # force trigger
CUL_HM_setAttrIfCh($devName,"actStatus","unknown","Activity");
my $acthash = CUL_HM_ActGetCreateHash(); my $actHash = CUL_HM_ActGetCreateHash();
my $actName = $acthash->{NAME}; # could have been renamed my $actName = $actHash->{NAME}; # could have been renamed
my $peerList = (!defined($attr{$actName}{peerList}))?"":$attr{$actName}{peerList}; my $peerList = (!defined($attr{$actName}{peerList}))?"":$attr{$actName}{peerList};
$peerList .= $devId."," if($peerList !~ m/$devId,/);#add if not in $peerList .= $devId."," if($peerList !~ m/$devId,/);#add if not in
$attr{$actName}{peerList} = $peerList; $attr{$actName}{peerList} = $peerList;
$acthash->{READINGS}{"status_".$devName}{TIME} = TimeNow(); # update new value my $tn = TimeNow();
$acthash->{READINGS}{"status_".$devName}{VAL} = "unknown"; $actHash->{helper}{$devId}{start} = $tn;
setReadingsVal($actHash,"status_".$devName,"unknown",$tn);
Log GetLogLevel($actName,3),"Device ".$devName." added to ActionDetector with " Log GetLogLevel($actName,3),"Device ".$devName." added to ActionDetector with "
.$cycleString." time"; .$cycleString." time";
} }
@@ -3203,16 +3286,18 @@ CUL_HM_ActDel($)
my $devName = CUL_HM_id2Name($devId); my $devName = CUL_HM_id2Name($devId);
delete ($attr{$devName}{actCycle}); delete ($attr{$devName}{actCycle});
CUL_HM_setAttrIfCh($devName,"actStatus","deleted","Activity");#post trigger
delete ($attr{$devName}{actStatus}); delete ($attr{$devName}{actStatus});
my $acthash = CUL_HM_ActGetCreateHash(); my $acthash = CUL_HM_ActGetCreateHash();
my $actName = $acthash->{NAME}; my $actName = $acthash->{NAME};
delete ($acthash->{helper}{$devId});
$attr{$actName}{peerList} = "" if (!defined($attr{$actName}{peerList})); $attr{$actName}{peerList} = "" if (!defined($attr{$actName}{peerList}));
$attr{$actName}{peerList} =~ s/$devId,//g; $attr{$actName}{peerList} =~ s/$devId,//g;
Log GetLogLevel($actName,3),"Device ".$devName." removed from ActionDetector"; Log GetLogLevel($actName,3),"Device ".$devName." removed from ActionDetector";
} }
sub sub
CUL_HM_ActCheck() CUL_HM_ActCheck()
{# perform supervision {# perform supervision
@@ -3229,30 +3314,29 @@ CUL_HM_ActCheck()
CUL_HM_ActDel($devId); CUL_HM_ActDel($devId);
next; next;
} }
my $rdName = "status_".$devName;
$actHash->{READINGS}{"status_".$devName}{TIME} = $tn;
my (undef,$tSec)=CUL_HM_time2sec($attr{$devName}{actCycle}); my (undef,$tSec)=CUL_HM_time2sec($attr{$devName}{actCycle});
if ($tSec == 0){# detection switched off if ($tSec == 0){# detection switched off
$attr{$devName}{actStatus} = "switchedOff"; CUL_HM_setRdIfCh($actHash,$rdName,"switchedOff",$tn);
$actHash->{READINGS}{"status_".$devName}{VAL} = "switchedOff"; CUL_HM_setAttrIfCh($devName,"actStatus","switchedOff","Activity");
next; next;
} }
my $tLast = $attr{$devName}{"protLastRcv"}; my $tLast = $attr{$devName}{"protLastRcv"};
my @t = localtime($tod - $tSec); #time since when a trigger is expected my @t = localtime($tod - $tSec); #time since when a trigger is expected
my $tSince = sprintf("%04d-%02d-%02d %02d:%02d:%02d", my $tSince = sprintf("%04d-%02d-%02d %02d:%02d:%02d",
$t[5]+1900, $t[4]+1, $t[3], $t[2], $t[1], $t[0]); $t[5]+1900, $t[4]+1, $t[3], $t[2], $t[1], $t[0]);
if (!$tLast || $tSince gt $tLast){#no message received in timeframe if ((!$tLast || $tSince gt $tLast)){ #no message received in timeframe
$actHash->{READINGS}{"status_".$devName}{VAL}="timedOut - last: ".$tLast; if ($tSince gt $actHash->{helper}{$devId}{start}){
DoTrigger($devName,"Activity: dead") CUL_HM_setRdIfCh($actHash,$rdName,"timedOut - last: ".$tLast,$tn);
if($attr{$devName}{actStatus} ne "dead"); CUL_HM_setAttrIfCh($devName,"actStatus","dead","Activity");
$attr{$devName}{actStatus} = "dead";
Log GetLogLevel($actName,2),"Device ".$devName." is dead"; Log GetLogLevel($actName,2),"Device ".$devName." is dead";
} }
# no action otherwise
}
else{ else{
$actHash->{READINGS}{"status_".$devName}{VAL} = "alive"; CUL_HM_setRdIfCh($actHash,$rdName,"alive",$tn);
DoTrigger($devName,"Activity: alive") CUL_HM_setAttrIfCh($devName,"actStatus","alive","Activity");
if($attr{$devName}{actStatus} ne "alive");
$attr{$devName}{actStatus} = "alive";
Log GetLogLevel($actName,5),"Device ".$devName." is alive"; Log GetLogLevel($actName,5),"Device ".$devName." is alive";
} }
} }
@@ -3262,6 +3346,22 @@ CUL_HM_ActCheck()
InternalTimer(gettimeofday()+$attr{$actName}{actCycle}, InternalTimer(gettimeofday()+$attr{$actName}{actCycle},
"CUL_HM_ActCheck", "ActionDetector", 0); "CUL_HM_ActCheck", "ActionDetector", 0);
} }
sub
CUL_HM_setRdIfCh($$$$)
{
my ($hash,$rd,$val,$ts) = @_;
$ts = TimeNow() if (!$ts);
setReadingsVal($hash,$rd,$val,$ts)
if(ReadingsVal($hash->{NAME},$rd,"") ne $val);
}
sub
CUL_HM_setAttrIfCh($$$$)
{
my ($name,$att,$val,$trig) = @_;
if($attr{$name}{$att} ne $val){
DoTrigger($name,$trig.":".$val) if($trig);
$attr{$name}{$att} = $val;
}
}
1; 1;