support virtual dimmer level

git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@2818 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
martinp876
2013-02-26 19:36:57 +00:00
parent a50ec5a960
commit c07e8948fb

View File

@@ -2,6 +2,9 @@
# CUL HomeMatic handler # CUL HomeMatic handler
# $Id$ # $Id$
#peerlisten check
#virtual channel for dimmer check
package main; package main;
# update regRaw warnings "#todo Updt2 remove" # update regRaw warnings "#todo Updt2 remove"
@@ -263,7 +266,6 @@ sub CUL_HM_autoReadConfig($){
while(@{$modules{CUL_HM}{helper}{updtCfgLst}}){ while(@{$modules{CUL_HM}{helper}{updtCfgLst}}){
my $name = shift(@{$modules{CUL_HM}{helper}{updtCfgLst}}); my $name = shift(@{$modules{CUL_HM}{helper}{updtCfgLst}});
my $hash = CUL_HM_name2Hash($name); my $hash = CUL_HM_name2Hash($name);
if (1 == AttrVal($name,"autoReadReg","0")){ if (1 == AttrVal($name,"autoReadReg","0")){
CUL_HM_Set($hash,$name,"getConfig"); CUL_HM_Set($hash,$name,"getConfig");
CUL_HM_Set($hash,$name,"statusRequest"); CUL_HM_Set($hash,$name,"statusRequest");
@@ -296,6 +298,75 @@ sub CUL_HM_updateConfig($){
delete $attr{$name}{devInfo}; delete $attr{$name}{devInfo};
delete $attr{$name}{hmClass}; delete $attr{$name}{hmClass};
if ("dimmer" eq CUL_HM_Get($hash,$name,"param","subType")) {
#configure Dimmer virtual channel assotiation
my $id = CUL_HM_hash2Id($hash);
if (length($id) == 8 || !$hash->{"channel_01"}){
my $chn = substr($id,6,2);
my $devId = substr($id,0,6);
$chn = "01" if (!$chn); # device acts as channel 01
my $model = CUL_HM_Get($hash,$name,"param","model");
my $mId = CUL_HM_getMId($hash);
my $chSet = $culHmModel{$mId}{chn};
$hash->{helper}{vDim}{chnSet} = $chSet;
my @chnPh = (grep{$_ =~ m/Sw:/ } split ',',$chSet);
@chnPh = split ':',$chnPh[0] if (@chnPh);
my $chnPhyMax = $chnPh[2]?$chnPh[2]:1; # max Phys channels
my $chnPhy = int(($chn-$chnPhyMax+1)/2); # my phys chn
my $idPhy = $devId.sprintf("%02X",$chnPhy);
my $pHash = CUL_HM_id2Hash($idPhy);
$idPhy = CUL_HM_hash2Id($pHash);
if ($pHash){
$pHash->{helper}{vDim}{idPhy} = $idPhy;
my $vHash = CUL_HM_id2Hash($devId.sprintf("%02X",$chnPhyMax+2*$chnPhy-1));
if ($vHash){
$pHash->{helper}{vDim}{idV2} = CUL_HM_hash2Id($vHash);
$vHash->{helper}{vDim}{idPhy} = $idPhy;
}
else{
delete $pHash->{helper}{vDim}{idV2};
}
$vHash = CUL_HM_id2Hash($devId.sprintf("%02X",$chnPhyMax+2*$chnPhy));
if ($vHash){
$pHash->{helper}{vDim}{idV3} = CUL_HM_hash2Id($vHash);
$vHash->{helper}{vDim}{idPhy} = $idPhy;
}
else{
delete $pHash->{helper}{vDim}{idV3};
}
}
my %logicCombination=(
inactive=>'$val=$val',
or =>'$val=$in>$val ?$in :$val' ,#max
and =>'$val=$in<$val ?$in :$val' ,#min
xor =>'$val=($in!=0&&$val!=0) ?0 :($in>$val?$in:$val)',#0 if both are != 0, else max
nor =>'$val=100-($in>$val ?$in :$val)',#100-max
nand =>'$val=100-($in<$val ?$in :$val)',#100-min
orinv =>'$val=(100-$in)>$val ?(100-$in) :$val' ,#max((100-chn),other)
andinv =>'$val=(100-$in)<$val ?(100-$in) :$val' ,#min((100-chn),other)
plus =>'$val=($in + $val)<100 ?($in + $val) :100' ,#other + chan
minus =>'$val=($in - $val)>0 ?($in + $val) :0' ,#other - chan
mul =>'$val=($in * $val)<100 ?($in + $val) :100' ,#other * chan
plusinv =>'$val=($val+100-$in)<100 ?($val+100-$in) :100' ,#other + 100 - chan
minusinv=>'$val=($val-100+$in)>0 ?($val-100+$in) : 0' ,#other - 100 + chan
mulinv =>'$val=((100-$in)*$val)<100?(100-$in)*$val):100' ,#other * (100 - chan)
invPlus =>'$val=(100-$val-$in)>0 ?(100-$val-$in) :0' ,#100 - other - chan
invMinus=>'$val=(100-$val+$in)<100 ?(100-$val-$in) :100' ,#100 - other + chan
invMul =>'$val=(100-$val*$in)>0 ?(100-$val*$in) :0' ,#100 - other * chan
);
if ($pHash->{helper}{vDim}{idPhy}){
my $vName = CUL_HM_id2Name($pHash->{helper}{vDim}{idPhy});
$pHash->{helper}{vDim}{oper1} = ReadingsVal($vName,"logicCombination","inactive");
$pHash->{helper}{vDim}{operExe1} = $logicCombination{$pHash->{helper}{vDim}{oper1}} ;
}
}
}
# add default web-commands # add default web-commands
my $webCmd; my $webCmd;
my $st = AttrVal(($hash->{device}?$hash->{device}:$name), "subType", ""); my $st = AttrVal(($hash->{device}?$hash->{device}:$name), "subType", "");
@@ -318,7 +389,7 @@ sub CUL_HM_updateConfig($){
my ($old,$new) = split":",$_; my ($old,$new) = split":",$_;
my $nW = $webCmd; my $nW = $webCmd;
$nW =~ s/^$old:/$new:/; $nW =~ s/^$old:/$new:/;
$nW =~ s/$old:$/$new:/; $nW =~ s/$old$/$new/;#General check
$nW =~ s/:$old:/:$new:/; $nW =~ s/:$old:/:$new:/;
$webCmd = $nW; $webCmd = $nW;
} }
@@ -399,10 +470,10 @@ sub CUL_HM_Rename($$$) {#############################
$devHash->{"channel_".$hash->{chanNo}} = $name; $devHash->{"channel_".$hash->{chanNo}} = $name;
} }
else{# we are a device - inform channels if exist else{# we are a device - inform channels if exist
for (my$chn = 1; $chn <25;$chn++){ foreach (grep {$_ =~m/^channel_/} keys%{$hash}){
my $chnName = $hash->{sprintf("channel_%02X",$chn)}; Log 1,"General notify channel:".$hash->{$_}." for:".$name;
my $chnHash = CUL_HM_name2Hash($chnName); my $chnHash = CUL_HM_name2Hash($hash->{$_});
$chnHash->{device} = $name if ($chnName); $chnHash->{device} = $name;
} }
} }
return; return;
@@ -791,12 +862,18 @@ sub CUL_HM_Parse($$) {#############################
if (($msgType eq "02" && $p =~ m/^01/) || # handle Ack_Status if (($msgType eq "02" && $p =~ m/^01/) || # handle Ack_Status
($msgType eq "10" && $p =~ m/^06/)) { # or Info_Status message here ($msgType eq "10" && $p =~ m/^06/)) { # or Info_Status message here
my ($subType,$chn,$level,$err) = ($1,$2,$3,hex($4)) my ($subType,$chn,$val,$err) = ($1,$2,hex($3)/2,hex($4))
if($p =~ m/^(..)(..)(..)(..)/); if($p =~ m/^(..)(..)(..)(..)/);
my ($x,$pl) = ($1,hex($2)/2) if($p =~ m/^........(..)(..)/);
if (defined $pl){# device with virtual channels...
$val = ($val == 100 ? "on" : ($val == 0 ? "off" : "$val %"));
push @event, "virtLevel:$val";
$val = $pl;
}
# Multi-channel device: Use channel if defined # Multi-channel device: Use channel if defined
$shash = $modules{CUL_HM}{defptr}{"$src$chn"} $shash = $modules{CUL_HM}{defptr}{"$src$chn"}
if($modules{CUL_HM}{defptr}{"$src$chn"}); if($modules{CUL_HM}{defptr}{"$src$chn"});
my $val = hex($level)/2;
$val = ($val == 100 ? "on" : ($val == 0 ? "off" : "$val %")); $val = ($val == 100 ? "on" : ($val == 0 ? "off" : "$val %"));
push @event, "deviceMsg:$val$target" if($chn ne "00"); push @event, "deviceMsg:$val$target" if($chn ne "00");
@@ -2154,11 +2231,9 @@ sub CUL_HM_getMId($) {#in: hash(chn or dev) out:model key (key for %culHmModel).
my $mId = $hash->{helper}{mId}; my $mId = $hash->{helper}{mId};
if (!$mId){ if (!$mId){
my $model = AttrVal($hash->{NAME}, "model", ""); my $model = AttrVal($hash->{NAME}, "model", "");
foreach my $mIdKey(keys%culHmModel){ foreach my $mIdKey(grep {$culHmModel{$_}{name} eq $model}keys%culHmModel){
if ($culHmModel{$mIdKey}{name} && $culHmModel{$mIdKey}{name} eq $model){ $mId = $hash->{helper}{mId} = $mIdKey;
$mId = $hash->{helper}{mId} = $mIdKey; return $mIdKey;
return $mIdKey;
}
} }
} }
return $mId; return $mId;
@@ -2348,7 +2423,7 @@ sub CUL_HM_Set($@) {
if($culHmSubTypeSets{$st}{devicepair}|| if($culHmSubTypeSets{$st}{devicepair}||
$culHmModelSets{$md}{devicepair}|| $culHmModelSets{$md}{devicepair}||
$culHmChanSets{$mdCh}{devicepair}){ $culHmChanSets{$mdCh}{devicepair}){
$pCh2 = "00"; $pCh2 = "00"; # button behavior
} }
CUL_HM_PushCmdStack($hash,'++'.$flag.'01'.$id.$dst.$chn.'01'. CUL_HM_PushCmdStack($hash,'++'.$flag.'01'.$id.$dst.$chn.'01'.
substr($pID,0,6).$pCh1.$pCh2); substr($pID,0,6).$pCh1.$pCh2);
@@ -3411,8 +3486,7 @@ sub CUL_HM_getAssChnIds($) { #in: name out:ID list of assotiated channels
my ($name) = @_; my ($name) = @_;
my @chnIdList; my @chnIdList;
my $hash = CUL_HM_name2Hash($name); my $hash = CUL_HM_name2Hash($name);
foreach my $channel (keys %{$hash}){ foreach my $channel (grep {$_ =~m/^channel_/} keys %{$hash}){
next if ($channel !~ m/^channel_/);
my $chnHash = CUL_HM_name2Hash($hash->{$channel}); my $chnHash = CUL_HM_name2Hash($hash->{$channel});
push @chnIdList,$chnHash->{DEF} if ($chnHash); push @chnIdList,$chnHash->{DEF} if ($chnHash);
} }
@@ -4140,6 +4214,7 @@ sub CUL_HM_ActGetCreateHash() {# return hash of ActionDetector - create one if n
if (!$modules{CUL_HM}{defptr}{"000000"}){ if (!$modules{CUL_HM}{defptr}{"000000"}){
DoTrigger("global", "UNDEFINED ActionDetector CUL_HM 000000"); DoTrigger("global", "UNDEFINED ActionDetector CUL_HM 000000");
$attr{ActionDetector}{actCycle} = 600; $attr{ActionDetector}{actCycle} = 600;
$attr{ActionDetector}{"event-on-change-reading"} = ".*";
} }
my $actHash = $modules{CUL_HM}{defptr}{"000000"}; my $actHash = $modules{CUL_HM}{defptr}{"000000"};
my $actName = $actHash->{NAME} if($actHash); my $actName = $actHash->{NAME} if($actHash);
@@ -4293,7 +4368,7 @@ sub CUL_HM_ActCheck() {# perform supervision
." unkn:".$cntUnkn ." unkn:".$cntUnkn
." off:" .$cntOff; ." off:" .$cntOff;
CUL_HM_UpdtReadBulk($actHash,0,@event); CUL_HM_UpdtReadBulk($actHash,1,@event);
$attr{$actName}{actCycle} = 600 if($attr{$actName}{actCycle}<30); $attr{$actName}{actCycle} = 600 if($attr{$actName}{actCycle}<30);
$actHash->{helper}{actCycle} = $attr{$actName}{actCycle}; $actHash->{helper}{actCycle} = $attr{$actName}{actCycle};