diff --git a/fhem/FHEM/10_CUL_HM.pm b/fhem/FHEM/10_CUL_HM.pm index 5c7376e73..daf435220 100755 --- a/fhem/FHEM/10_CUL_HM.pm +++ b/fhem/FHEM/10_CUL_HM.pm @@ -337,12 +337,13 @@ CUL_HM_Parse($$) } elsif($model eq "KS550") { + if($cmd eq "8670" && $p =~ m/^(....)(..)(....)(....)(..)(..)(..)/) { my ( $t, $h, $r, $w, $wd, $s, $b ) = (hex($1), hex($2), hex($3), hex($4), hex($5), hex($6), hex($7)); my $tsgn = ($t & 0x4000); # not tested $t = ($t & 0x3fff)/10; - $t = -$t if($tsgn); + $t = sprintf("%0.1f", $t-1638.4) if($tsgn); my $ir = $r & 0x8000; $r = ($r & 0x7fff) * 0.295; my $wdr = ($w>>14)*22.5; @@ -361,6 +362,9 @@ CUL_HM_Parse($$) push @event, "sunshine:$s"; push @event, "brightness:$b"; + } else { + push @event, "KS550 unknown: $p"; + } } elsif($st eq "KFM" && $model eq "KFM-Sensor") { @@ -610,7 +614,6 @@ CUL_HM_Pair(@) $attr{$name}{serialNr} = pack('H*', substr($p, 6, 20)); $attr{$name}{firmware} = sprintf("%d.%d", hex(substr($p,0,1)),hex(substr($p,1,1))); $attr{$name}{devInfo} = substr($p,28); - my $stn = $attr{$name}{subType}; # subTypeName my $stt = $stn eq "unknown" ? "subType unknown" : "is a $stn"; @@ -695,9 +698,11 @@ CUL_HM_SendCmd($$$$) $cmd = sprintf("As%02X%02x%s", length($cmd2)/2+1, $mn, $cmd2); IOWrite($hash, "", $cmd); if($waitforack) { - $hash->{ackWaiting} = $cmd; - $hash->{ackCmdSent} = 1; - InternalTimer(gettimeofday()+0.4, "CUL_HM_Resend", $hash, 0); + if($hash->{IODev} && $hash->{IODev}{TYPE} ne "HMLAN") { + $hash->{ackWaiting} = $cmd; + $hash->{ackCmdSent} = 1; + InternalTimer(gettimeofday()+0.4, "CUL_HM_Resend", $hash, 0) + } } $cmd =~ m/As(..)(..)(....)(......)(......)(.*)/; CUL_HM_DumpProtocol("CUL_HM SND", $io, ($1,$2,$3,$4,$5,$6)); @@ -738,8 +743,8 @@ sub CUL_HM_Id($) { my ($io) = @_; - return "123456" if(!$io || !defined($io->{FHTID})); - return AttrVal($io->{NAME}, "hmId", "F1".$io->{FHTID}); + my $fhtid = defined($io->{FHTID}) ? $io->{FHTID} : "0000"; + return AttrVal($io->{NAME}, "hmId", "F1$fhtid"); } my %culHmBits = ( diff --git a/fhem/FHEM/92_FileLog.pm b/fhem/FHEM/92_FileLog.pm index 21124c265..6989d9e42 100755 --- a/fhem/FHEM/92_FileLog.pm +++ b/fhem/FHEM/92_FileLog.pm @@ -167,7 +167,7 @@ FileLog_Get($@) " is without direcory, - means the current file\n" . " is a prefix, - means stdout\n" if(int(@a) < 5); - +Log 1, join("/", @a); shift @a; my $inf = shift @a; my $outf = shift @a; diff --git a/fhem/FHEM/98_autocreate.pm b/fhem/FHEM/98_autocreate.pm index 219e7eab0..0182bbeab 100644 --- a/fhem/FHEM/98_autocreate.pm +++ b/fhem/FHEM/98_autocreate.pm @@ -24,7 +24,9 @@ my %flogpar = ( "HMS:HMS100T._.*" => { GPLOT => "hms:Temp/Hum,", FILTER => "%NAME:T:.*" }, "KS300:.*" - => { GPLOT => "ks300:Temp/Rain,ks300_2:Wind/Hum,", FILTER => "%NAME:T:.*" }, + => { GPLOT => "ks300:Temp/Rain,ks300_2:Wind/Hum,", + FILTER => "%NAME:T:.*" }, + # Oregon sensors: # * temperature "OREGON:(THR128|THWR288A|THN132N).*" @@ -42,6 +44,14 @@ my %flogpar = ( # * Oregon sensors: Rain gauge "OREGON:(PCR800|RGR918).*" => { GPLOT => "oregon_rain:RainRate", FILTER => "%NAME" }, + + # HomeMatic + "CUL_HM:THSensor" + => { GPLOT => "hms:Temp/Hum,", + FILTER => "%NAME:T:.*" }, + "CUL_HM:KS550" + => { GPLOT => "ks300:Temp/Rain,ks300_2:Wind/Hum,", + FILTER => "%NAME:T:.*" }, ); ##################################### @@ -52,7 +62,11 @@ autocreate_Initialize($) $hash->{DefFn} = "autocreate_Define"; $hash->{NotifyFn} = "autocreate_Notify"; $hash->{AttrList}= "loglevel:0,1,2,3,4,5,6 " . - "autosave filelog device_room weblink weblink_room"; + "autosave filelog device_room weblink weblink_room " . + "disable"; + my %ahash = ( Fn=>"CommandCreateLog", + Hlp=>",create log/weblink for " ); + $cmds{createlog} = \%ahash; } ##################################### @@ -83,6 +97,7 @@ autocreate_Notify($$) my ($ntfy, $dev) = @_; my $me = $ntfy->{NAME}; + my ($ll1, $ll2) = (GetLogLevel($me,1), GetLogLevel($me,2)); my $max = int(@{$dev->{CHANGED}}); my $ret = ""; my $nrcreated; @@ -95,17 +110,23 @@ autocreate_Notify($$) ################ if($s =~ m/^UNDEFINED ([^ ]*) ([^ ]*) (.*)$/) { my ($name, $type, $arg) = ($1, $2, $3); + next if(AttrVal($me, "disable", undef)); + my $lctype = lc($type); + my ($cmd, $ret); + my $hash = $defs{$name}; # Called from createlog #################### - my $cmd = "$name $type $arg"; - Log GetLogLevel($me,2), "autocreate: define $cmd"; - my $ret = CommandDefine(undef, $cmd); - if($ret) { - Log GetLogLevel($me,1), "ERROR: $ret"; - last; + if(!$hash) { + $cmd = "$name $type $arg"; + Log $ll2, "autocreate: define $cmd"; + $ret = CommandDefine(undef, $cmd); + if($ret) { + Log $ll1, "ERROR: $ret"; + last; + } } - my $hash = $defs{$name}; + $hash = $defs{$name}; $nrcreated++; my $room = replace_wildcards($hash, $attr{$me}{device_room}); $attr{$name}{room} = $room if($room); @@ -114,17 +135,20 @@ autocreate_Notify($$) my $fl = replace_wildcards($hash, $attr{$me}{filelog}); next if(!$fl); my $flname = "FileLog_$name"; + delete($defs{$flname}); # If we are re-creating it with createlog. my ($gplot, $filter) = ("", $name); foreach my $k (keys %flogpar) { - next if("$type:$name" !~ m/^$k$/); + my $model = AttrVal($name, "model", ""); + next if("$type:$name" !~ m/^$k$/ && + "$type:$model" !~ m/^$k$/); $gplot = $flogpar{$k}{GPLOT}; $filter = replace_wildcards($hash, $flogpar{$k}{FILTER}); } $cmd = "$flname FileLog $fl $filter"; - Log GetLogLevel($me,2), "autocreate: define $cmd"; + Log $ll2, "autocreate: define $cmd"; $ret = CommandDefine(undef, $cmd); if($ret) { - Log GetLogLevel($me,1), "ERROR: $ret"; + Log $ll1, "ERROR: $ret"; last; } $attr{$flname}{room} = $room if($room); @@ -134,20 +158,26 @@ autocreate_Notify($$) #################### next if(!$attr{$me}{weblink} || !$gplot); $room = replace_wildcards($hash, $attr{$me}{weblink_room}); - my $wlname = "weblink_$name"; - my $gplotfile; - my $stuff; - ($gplotfile, $stuff) = split(/:/, $gplot); - $cmd = "$wlname weblink fileplot $flname:$gplotfile:CURRENT"; - Log GetLogLevel($me,2), "autocreate: define $cmd"; - $ret = CommandDefine(undef, $cmd); - if($ret) { - Log GetLogLevel($me,1), "ERROR: $ret"; - last; - } - $attr{$wlname}{room} = $room if($room); - $attr{$wlname}{label} = '"' . $name . + my $wnr = 1; + foreach my $wdef (split(/,/, $gplot)) { + next if(!$wdef); + my ($gplotfile, $stuff) = split(/:/, $wdef); + next if(!$gplotfile); + my $wlname = "weblink_$name"; + $wlname .= "_$wnr" if($wnr > 1); + $wnr++; + delete($defs{$wlname}); # If we are re-creating it with createlog. + $cmd = "$wlname weblink fileplot $flname:$gplotfile:CURRENT"; + Log $ll2, "autocreate: define $cmd"; + $ret = CommandDefine(undef, $cmd); + if($ret) { + Log $ll1, "ERROR: $ret"; + last; + } + $attr{$wlname}{room} = $room if($room); + $attr{$wlname}{label} = '"' . $name . ' Min $data{min1}, Max $data{max1}, Last $data{currval1}"'; + } } @@ -166,8 +196,7 @@ autocreate_Notify($$) $hash->{DEF} =~ s/$old/$new/g; rename($oldlogfile, $hash->{currentlogfile}); - Log GetLogLevel($me,2), - "autocreate: renamed FileLog_$old to FileLog_$new"; + Log $ll2, "autocreate: renamed FileLog_$old to FileLog_$new"; $nrcreated++; } @@ -177,8 +206,7 @@ autocreate_Notify($$) $hash->{LINK} =~ s/$old/$new/g; $hash->{DEF} =~ s/$old/$new/g; $attr{"weblink_$new"}{label} =~ s/$old/$new/g; - Log GetLogLevel($me,2), - "autocreate: renamed weblink_$old to weblink_$new"; + Log $ll2, "autocreate: renamed weblink_$old to weblink_$new"; $nrcreated++; } } @@ -188,13 +216,31 @@ autocreate_Notify($$) return $ret; } -##################################### -# Test code. Use {dp "xxx"} to fake a device specific message -# FS20: 81xx04yy0101a00180c1020013 sub -dp($) +CommandCreateLog($$) { - Dispatch($defs{CUL}, shift, undef); + my ($cl, $n) = @_; + my $ac; + + foreach my $d (keys %defs) { + next if($defs{$d}{TYPE} ne "autocreate"); + $ac = $d; + last; + } + return "Please define an autocreate device with attributes first " . + "(it may be disabled)" if(!$ac); + + return "No device named $n found" if(!$defs{$n}); + + my $acd = $defs{$ac}; + my $disabled = AttrVal($ac, "disable", undef); + delete $attr{$ac}{disable} if($disabled); + + $acd->{CHANGED}[0] = "UNDEFINED $n $defs{$n}{TYPE} none"; + autocreate_Notify($acd, $acd); + delete $acd->{CHANGED}; + + $attr{$ac}{disable} = 1 if($disabled); } 1;