diff --git a/fhem/FHEM/00_CUL.pm b/fhem/FHEM/00_CUL.pm index 14600c975..b6037afcb 100755 --- a/fhem/FHEM/00_CUL.pm +++ b/fhem/FHEM/00_CUL.pm @@ -34,8 +34,17 @@ sub CUL_Ready($$); my %msghist; # Used when more than one CUL is attached my $msgcount = 0; my %gets = ( - "ccreg" => "C", - "version" => "V", + "ccreg" => "C", + "readeeprom" => "R", + "version" => "V", + "time" => "t", +); + +my %sets = ( + "writeeeprom" => "W", + "sendrawFS20" => "F", + "sendrawFHT" => "T", + "verbose" => "X", ); sub @@ -46,7 +55,7 @@ CUL_Initialize($) # Provider $hash->{ReadFn} = "CUL_Read"; $hash->{WriteFn} = "CUL_Write"; - $hash->{Clients} = ":CUL:FS20:FHT:"; + $hash->{Clients} = ":FS20:FHT:KS300:CUL_EM:CUL_WS:"; $hash->{ReadyFn} = "CUL_Ready" if ($^O eq 'MSWin32'); # Normal devices @@ -127,7 +136,14 @@ sub CUL_Set($@) { my ($hash, @a) = @_; - return "NYI"; + + return "\"set CUL\" needs at least one parameter" if(@a < 2); + return "Unknown argument $a[1], choose one of " . join(",", sort keys %sets) + if(!defined($sets{$a[1]})); + + my $arg = ($a[2] ? $a[2] : ""); + CUL_Write($hash, $sets{$a[1]}, $arg) if(!IsDummy($hash->{NAME})); + return undef; } ##################################### @@ -136,7 +152,7 @@ CUL_Get($@) { my ($hash, @a) = @_; - return "\"get CUL\" needs at leass one parameter" if(@a < 2); + return "\"get CUL\" needs at least one parameter" if(@a < 2); return "Unknown argument $a[1], choose one of " . join(",", sort keys %gets) if(!defined($gets{$a[1]})); @@ -149,7 +165,6 @@ CUL_Get($@) $hash->{READINGS}{$a[1]}{TIME} = TimeNow(); return "$a[0] $a[1] => $msg"; - return "NYI" } ##################################### @@ -157,7 +172,7 @@ sub CUL_SetState($$$$) { my ($hash, $tim, $vt, $val) = @_; - return "NYI"; + return undef; } ##################################### @@ -183,7 +198,7 @@ CUL_DoInit($) Log 1, $msg; return $msg; } - $hash->{PortObj}->write("XFE\n"); # Enable message reporting + $hash->{PortObj}->write("X01\n"); # Enable message reporting # Reset the counter delete($hash->{XMIT_TIME}); @@ -276,7 +291,6 @@ CUL_Write($$$) return; } - ############### # insert value into the msghist. At the moment this only makes sense for FS20 # devices. As the transmitted value differs from the received one, we have to @@ -407,6 +421,7 @@ CUL_Read($) $msgcount++; Log 1, "CUL: $dmsg"; + ########################################### #Translate Message from CUL to FHZ my $fn = substr($dmsg,0,1); if($fn eq "F") { # FS20 @@ -424,8 +439,22 @@ Log 1, "CUL: $dmsg"; substr($dmsg,1,6), substr($dmsg,7)); $dmsg = lc($dmsg); + } elsif($fn eq "K" && length($dmsg) == 15) { # KS300 + + # K17815254024C82 -> 810d04f94027a0011718254520C428 + my $n = ""; + my @a = split("", $dmsg); + for(my $i = 0; $i < 14; $i+=2) { # Swap nibbles. + $n .= $a[$i+2] . $a[$i+1]; + } + $dmsg = sprintf("81%02x04xx4027a001%s", length($dmsg)/2+6, $n); + + } elsif($fn eq "K" && length($dmsg) == 9) { # CUL_WS / Native + ; + } elsif($fn eq "E") { # CUL_EM / Native + ; } else { - Log 5, "CUL: unknown message $dmsg"; + Log 4, "CUL: unknown message $dmsg"; goto NEXTMSG; } diff --git a/fhem/FHEM/13_KS300.pm b/fhem/FHEM/13_KS300.pm index 4d6ecac0b..09348530e 100755 --- a/fhem/FHEM/13_KS300.pm +++ b/fhem/FHEM/13_KS300.pm @@ -7,9 +7,6 @@ use warnings; my %defptr; my $negcount = 0; -###################### -# Note: this is just an empty hull. - ##################################### sub KS300_Initialize($) @@ -20,7 +17,7 @@ KS300_Initialize($) # 810d04f94027a00171212730000008 # 81 0d 04 f9 4027a00171 212730000008 - $hash->{Match} = "^810.04..402.a001"; + $hash->{Match} = "^810d04..4027a001"; $hash->{DefFn} = "KS300_Define"; $hash->{UndefFn} = "KS300_Undef"; $hash->{ParseFn} = "KS300_Parse"; @@ -67,11 +64,6 @@ KS300_Parse($$) { my ($hash,$msg) = @_; - if($msg !~ m/^810d04..4027a001/) { - Log 4, "KS300 unknown message $msg"; - return ""; - } - ############################### # 1 2 #0123456789012345 67890123456789 diff --git a/fhem/FHEM/14_CUL_WS.pm b/fhem/FHEM/14_CUL_WS.pm new file mode 100755 index 000000000..a7a90847d --- /dev/null +++ b/fhem/FHEM/14_CUL_WS.pm @@ -0,0 +1,96 @@ +############################################## +package main; + +use strict; +use warnings; + +my %defptr; + +##################################### +sub +CUL_WS_Initialize($) +{ + my ($hash) = @_; + + # Message is like + # K41350270 + + $hash->{Match} = "^K........\$"; + $hash->{DefFn} = "CUL_WS_Define"; + $hash->{UndefFn} = "CUL_WS_Undef"; + $hash->{ParseFn} = "CUL_WS_Parse"; + $hash->{AttrList} = "do_not_notify:0,1 showtime:0,1 model:S300TH loglevel"; +} + +##################################### +sub +CUL_WS_Define($$) +{ + my ($hash, $def) = @_; + my @a = split("[ \t][ \t]*", $def); + + return "wrong syntax: define CUL_WS [corr1 [corr2]]" + if(int(@a) < 3 || int(@a) > 5); + $a[2] = lc($a[2]); + return "Define $a[0]: wrong CODE format: valid is 1-7" + if($a[2] !~ m/^[1-7]$/); + + $hash->{CODE} = $a[2]; + $hash->{corr1} = ((int(@a) > 3) ? $a[3] : 0); + $hash->{corr2} = ((int(@a) > 4) ? $a[4] : 0); + $defptr{$a[2]} = $hash; + return undef; +} + +##################################### +sub +CUL_WS_Undef($$) +{ + my ($hash, $name) = @_; + delete($defptr{$hash->{CODE}}); + return undef; +} + + +##################################### +sub +CUL_WS_Parse($$) +{ + my ($hash,$msg) = @_; + + # 012345678 + # K41505268 -> Code 5, T: 25.0 H: 68.5 + + my @a = split("", $msg); + my $cde = (($a[1]+0)&7) + 1; + my $sgn = (($a[1]+0)&8) ? -1 : 1; + my $tmp = $sgn * ($a[6].$a[3].".".$a[4]); + my $hum = $a[7].$a[8].".".$a[5]; + my $val = "T: $tmp H: $hum"; + + if($defptr{$cde}) { + $hash = $defptr{$cde}; + $tmp += $hash->{corr1}; + $hum += $hash->{corr2}; + $val = "T: $tmp H: $hum"; + my $n = $hash->{NAME}; + Log GetLogLevel($n,1), "CUL_WS $n: $val"; + $hash->{STATE} = $val; + + $hash->{CHANGED}[0] = $val; + $hash->{STATE} = $val; + $hash->{READINGS}{state}{TIME} = TimeNow(); + $hash->{READINGS}{state}{VAL} = $val; + + return $hash->{NAME}; + + } else { + + Log 1, "CUL_WS detected, Code $cde $val"; + + } + + return ""; +} + +1; diff --git a/fhem/FHEM/15_CUL_EM.pm b/fhem/FHEM/15_CUL_EM.pm new file mode 100755 index 000000000..15d2c28e1 --- /dev/null +++ b/fhem/FHEM/15_CUL_EM.pm @@ -0,0 +1,98 @@ +############################################## +package main; + +use strict; +use warnings; + +my %defptr; + +##################################### +sub +CUL_EM_Initialize($) +{ + my ($hash) = @_; + + # Message is like + # K41350270 + + $hash->{Match} = "^E0.................\$"; + $hash->{DefFn} = "CUL_EM_Define"; + $hash->{UndefFn} = "CUL_EM_Undef"; + $hash->{ParseFn} = "CUL_EM_Parse"; + $hash->{AttrList} = "do_not_notify:0,1 showtime:0,1 model:S300TH loglevel"; +} + +##################################### +sub +CUL_EM_Define($$) +{ + my ($hash, $def) = @_; + my @a = split("[ \t][ \t]*", $def); + + return "wrong syntax: define CUL_EM [corr]" + if(int(@a) < 3 || int(@a) > 4); + $a[2] = lc($a[2]); + return "Define $a[0]: wrong CODE format: valid is 1-12" + if($a[2] !~ m/^\d$/ || $a[2] < 1 || $a[2] > 12); + + $hash->{CODE} = $a[2]; + $hash->{corr} = ((int(@a) > 3) ? $a[3] : 1); + $defptr{$a[2]} = $hash; + return undef; +} + +##################################### +sub +CUL_EM_Undef($$) +{ + my ($hash, $name) = @_; + delete($defptr{$hash->{CODE}}); + return undef; +} + + +##################################### +sub +CUL_EM_Parse($$) +{ + my ($hash,$msg) = @_; + + # 0123456789012345678 + # E01012471B80100B80B -> Type 01, Code 01, Cnt 10 + my @a = split("", $msg); + my $tpe = ($a[1].$a[2])+0; + my $cde = ($a[3].$a[4])+0; + my $cnt = hex($a[5].$a[6]); + my $cum = hex($a[ 7].$a[ 8].$a[ 9].$a[10]); + my $lst = hex($a[11].$a[12].$a[13].$a[14]); + my $top = hex($a[15].$a[16].$a[17].$a[18]); + my $val = sprintf("CUM: %d 5MIN: %d TOP: %d", $cum, $lst, $top); + + if($defptr{$cde}) { + $hash = $defptr{$cde}; + my $corr = $hash->{corr}; + $cum *= $corr; + $lst *= $corr; + $top *= $corr; + $val = sprintf("CUM: %d 5MIN: %d TOP: %d", $cum, $lst, $top); + my $n = $hash->{NAME}; + Log GetLogLevel($n,1), "CUL_EM $n: $val"; + $hash->{STATE} = $val; + + $hash->{CHANGED}[0] = $val; + $hash->{STATE} = $val; + $hash->{READINGS}{state}{TIME} = TimeNow(); + $hash->{READINGS}{state}{VAL} = $val; + + return $hash->{NAME}; + + } else { + + Log 1, "CUL_EM detected, Code $cde $val"; + + } + + return ""; +} + +1; diff --git a/fhem/FHEM/90_at.pm b/fhem/FHEM/90_at.pm index 0d18e21f8..88c3c4278 100755 --- a/fhem/FHEM/90_at.pm +++ b/fhem/FHEM/90_at.pm @@ -68,6 +68,7 @@ at_Define($$) InternalTimer($nt, "at_Exec", $name, 0); $hash->{STATE} = "Next: " . FmtTime($nt); + if(!($attr{$name} && $attr{$name}{disable})); return undef; } @@ -79,11 +80,12 @@ at_Exec($) my ($skip, $disable); if(defined($attr{$name})) { - $skip = 1 if(defined($attr{$name}{skip_next})); - $disable = 1 if(defined($attr{$name}{disable})); + $skip = 1 if($attr{$name} && $attr{$name}{skip_next}); + $disable = 1 if($attr{$name} && $attr{$name}{disable}); } delete $attr{$name}{skip_next} if($skip); + return if(!$defs{$name}{DEF}); # Just deleted my (undef, $command) = split("[ \t]+", $defs{$name}{DEF}, 2); $command = SemicolonEscape($command); AnalyzeCommandChain(undef, $command) if(!$skip && !$disable);