diff --git a/fhem/CHANGED b/fhem/CHANGED index e1f0e12d5..c2c4aaa10 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - changed: 09_CUL_FHTTK: adapted battery reading to new common reading + Forum #87575 - change: 98_dewpoint: adjust log level for FAN/ALARM on/off to 4 - bugfix: 82_LGTV_WebOS: fix current program list readings - change: 74_Unifi: changed readings -UC_newClients and -AP_utilization diff --git a/fhem/FHEM/09_CUL_FHTTK.pm b/fhem/FHEM/09_CUL_FHTTK.pm index 47debe629..81c6859a2 100644 --- a/fhem/FHEM/09_CUL_FHTTK.pm +++ b/fhem/FHEM/09_CUL_FHTTK.pm @@ -128,13 +128,13 @@ CUL_FHTTK_Initialize($) $hash->{SetFn} = "CUL_FHTTK_Set"; $hash->{DefFn} = "CUL_FHTTK_Define"; $hash->{UndefFn} = "CUL_FHTTK_Undef"; + $hash->{AttrFn} = "CUL_FHTTK_Attr"; $hash->{ParseFn} = "CUL_FHTTK_Parse"; $hash->{AttrList} = "IODev do_not_notify:1,0 ignore:0,1 showtime:0,1 " . - "model:FHT80TF,FHT80TF-2,dummy ". + "model:FHT80TF,FHT80TF-2,virtual ". $readingFnAttributes; $hash->{AutoCreate}= { "CUL_FHTTK.*" => { GPLOT => "fht80tf:Window,", FILTER => "%NAME" } }; - } ############################# @@ -152,7 +152,11 @@ CUL_FHTTK_Set($@) # suppress SET option if(defined($attr{$name}) && defined($attr{$name}{"model"})) { - if($attr{$name}{"model"} ne "dummy") { + if($attr{$name}{"model"} eq "dummy") { + Log3 $name, 5, "CUL_FHTTK ($name) Attribute was renamed from dummy to virtual! No functional lack."; + $attr{$name}{"model"} = "virtual"; + } + if($attr{$name}{"model"} ne "virtual") { return $ret; } } @@ -188,10 +192,11 @@ CUL_FHTTK_Set($@) } elsif($opt eq "ReSync" ) { Log3 $name, 3, "CUL_FHTTK ($name) resyncing with FHT80b."; - IOWrite($hash, "", sprintf("T%s%s", $hash->{CODE}, $fhttfk_c2b{$opt})); # 0xff - ReSync - # window state switch to closed through cul FW implementation - $opt = "Closed"; + CUL_FHTTK_ReSync($hash); + # return, because readingsupdate is perfomred by sub function + return $ret; + } else { return "Unknown argument $a[1], choose one of Pair ReSync Open Closed" } @@ -213,7 +218,7 @@ CUL_FHTTK_Define($$) my $u= "wrong syntax: define CUL_FHTTK "; return $u if((int(@a)< 3) || (int(@a)>3)); - my $name = $a[0]; + my $name = $hash->{NAME}; my $sensor = lc($a[2]); if($sensor !~ /^[0-9a-f]{6}$/) { return "wrong sensor specification $sensor, need a 6 digit hex number!"; @@ -221,7 +226,7 @@ CUL_FHTTK_Define($$) $hash->{CODE} = $sensor; $modules{CUL_FHTTK}{defptr}{$sensor} = $hash; - + AssignIoPort($hash); return undef; } @@ -232,10 +237,24 @@ sub CUL_FHTTK_Undef($$) { my ($hash, $name) = @_; + + RemoveInternalTimer($hash); + delete($modules{CUL_FHTTK}{defptr}{$hash->{CODE}}) if($hash && $hash->{CODE}); + return undef; } +############################# +sub CUL_FHTTK_Attr($$$) { + my ($cmd, $name, $attrName, $attrVal) = @_; + + if( $attrName eq "model" && $attrVal eq "dummy") { + $attr{$name}{$attrName} = "virtual"; + return "$name - Renamed attrubte model from dummy to virtual! No functional lack!"; + } + return undef; +} ############################# sub @@ -253,6 +272,8 @@ CUL_FHTTK_Parse($$) my $name = $def->{NAME}; my $state = lc(substr($msg, 7, 2)); + Log3 $hash, 4, "CUL_FHTTK $sensor RAW message: $msg"; + return "" if(IsIgnored($name)); if(!defined($fhttfk_translatedcodes{$state})) { @@ -270,7 +291,7 @@ CUL_FHTTK_Parse($$) if($defs{$name}{PREV}{TIMESTAMP} > time()-5) { if(defined($defs{$name}{PREV}{STATE})) { if($defs{$name}{PREV}{STATE} eq $state) { - Log3 $name, 4, sprintf("FHTTK skipping state $state as last similar telegram was received less than 5 (%s) secs ago", time()-$defs{$name}{PREV}{TIMESTAMP}); + Log3 $name, 4, sprintf("FHTTK skipping state $state as last similar telegram was received less than 5 (%s) secs ago", $defs{$name}{PREV}{STATE}, time()-$defs{$name}{PREV}{TIMESTAMP}); return ""; } } @@ -316,12 +337,26 @@ CUL_FHTTK_Parse($$) } else { readingsBulkUpdate($def, "Reliability", "ok"); } - # Flag the battery warning separately + + # set battery state - Forum #87575 + my $batteryReading = "batteryState"; + my $batteryState = "ok"; + if($state eq "11" || $state eq "12") { - readingsBulkUpdate($def, "Battery", "Low"); - } else { - readingsBulkUpdate($def, "Battery", "ok"); + $batteryState = "low"; } + + if(exists($defs{$name}{READINGS}{"Battery"})) { + if(defined($featurelevel) && $featurelevel <= 5.8) { + readingsBulkUpdate($def, "Battery", $batteryState); + } else { + # delete reading + readingsDelete($def, "Battery"); + } + } + + readingsBulkUpdate($def, $batteryReading, $batteryState); + #CHANGED readingsBulkUpdate($def, "state", $val); @@ -336,6 +371,66 @@ CUL_FHTTK_Parse($$) return $def->{NAME}; } +############################# +sub +CUL_FHTTK_ReSync($) +{ + my ($hash) = @_; + + RemoveInternalTimer($hash); + + Log3 undef, 3, "CUL_FHTTK_ReSync() - ReSync for $hash->{NAME} started!"; + + # set resync + IOWrite($hash, "", sprintf("T%sff", $hash->{CODE})); # 0xff - ReSync + + # update new state + readingsSingleUpdate($hash, "state", "ReSync", 1); + readingsSingleUpdate($hash, "Window", "ReSync", 1); + + # finish timer + InternalTimer( gettimeofday() + 64, "CUL_FHTTK_ReSyncDone", $hash, 0 ); +} + +############################# +sub +CUL_FHTTK_ReSyncDone($) +{ + my ($hash) = @_; + + RemoveInternalTimer($hash); + + # update new state + readingsSingleUpdate($hash, "state", "Closed", 1); + readingsSingleUpdate($hash, "Window", "Closed", 1); + + Log3 undef, 3, "CUL_FHTTK_ReSyncDone() - ReSync for $hash->{NAME} done!"; +} + +############################# +sub +CUL_FHTTK_ReSyncAll() +{ + my $timeOffset = 0; + + foreach my $culFhtTk ( sort keys %{$modules{CUL_FHTTK}{defptr}} ) { + my $hash = $modules{CUL_FHTTK}{defptr}{$culFhtTk}; + my $name = $hash->{NAME}; + + Log3 undef, 4, "CUL_FHTTK_ReSyncAll - Possible device ($hash->{NAME}) found."; + + # check for model virtual + if(AttrVal($name, "model", "") eq "virtual") { + my $timerRaised = gettimeofday() + $timeOffset; + InternalTimer( $timerRaised, "CUL_FHTTK_ReSync", $hash, 0 ); + Log3 undef, 3, "CUL_FHTTK_ReSyncAll() - ReSync for $hash->{NAME} starts at ".localtime($timerRaised)."!"; + + $timeOffset += 3600; # one hour later, the next one, because of LOVF + } + } + Log3 undef, 3, "CUL_FHTTK_ReSyncAll done! Devices will be synchronized in steps!"; +} + ############################# 1; @@ -362,7 +457,7 @@ CUL_FHTTK_Parse($$) or next official version 1.62 or higher, it is possible to send out FHT80 TF data with a CUL or simular devices. So it can be simulate up to four window sensor with one device (see FHEM Wiki). To setup a window sensor, you have to - add and/or change the attribute "model" to dummy. The 6 digit hex number must not equal to FHTID.

+ add and/or change the attribute "model" to virtual. The 6 digit hex number must not equal to FHTID.

Define @@ -383,21 +478,27 @@ CUL_FHTTK_Parse($$) Set -