From 5b09d230a92949138abbfa42f0818ef6a8de6bf7 Mon Sep 17 00:00:00 2001 From: Matscher Date: Thu, 26 Jul 2018 18:52:50 +0000 Subject: [PATCH] 09_CUL_FHTTK.pm: use new battery readings - Forum #87575 git-svn-id: https://svn.fhem.de/fhem/trunk@17032 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 + fhem/FHEM/09_CUL_FHTTK.pm | 176 ++++++++++++++++++++++++++++++-------- 2 files changed, 144 insertions(+), 34 deletions(-) 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 -
    Only available, if model is set to dummy.

    +
      Only available, if model is set to virtual.

      set <name> <value>

      where value is one of:
      -
        - Pair # start pairing with FHT80B (activate FHT80B sync mode before) - state after pairing is Closed
        - Closed # set window state to Closed
        - Open # set window state to Open
        - ReSync # resync virtual sensor with FHT80b after a reset of CUL device. In other words, perform a virtual +
          +
        • Closed
          set window state to Closed

        • +
        • Open
          set window state to Open

        • +
        • Pair
          start pairing with FHT80B (activate FHT80B sync mode before) - state after pairing is Closed

        • +
        • ReSync
          resync virtual sensor with FHT80b after a reset of CUL device. In other words, perform a virtual battery exchange to synchronize the sensor with FHT80b device again. (at the moment, only - available with prototype cul_fw - see forum 55774)
          -
        + available with prototype cul fw - see forum 55774)
        +

    + Special to the "ReSync" of existing FHT80TFs after a CUL firmware reset:
    + After a reset or restart of a CUL device, the connection between the FHT80B and the virtual FHT80TFs is interrupted. This is equivalent to a battery change. + The contacts are still registered at the FHT80B. No new pairing is required. If multiple virtual contacts are used, it is recommended to synchronize them at large intervals!
    + Calling the CUL_FHTTK_ReSyncAll() function synchronizes all virtual window contacts successively with the FHT80B. + The time interval between the individual sensors is 1 hour. This is determined by the 1% rule, since per contact 480 credits are consumed within 64 seconds!

    + Get
      No get implemented yet ...

    @@ -407,7 +508,7 @@ CUL_FHTTK_Parse($$)
    • do_not_notify

    • verbose

    • -
    • model
      Possible values are: FHT80TF, FHT80TF-2, dummy (value, which allow to simulate a window sensor)

    • +
    • model
      Possible values are: FHT80TF, FHT80TF-2, virtual (value, which allow to simulate a window sensor)

    • showtime

    • IODev

    • ignore

    • @@ -438,7 +539,7 @@ CUL_FHTTK_Parse($$) oder mit der nächsten offiziellen Version 1.62 oder höher, ist es möglich, FHT80 TF Daten zu senden. Möglich mit einem CUL oder ähnlichen Geräten. So können bis zu vier Fenstersensoren mit einem Gerät simuliert werden (siehe FHEM Wiki). Es muss lediglich das Attribut model mit dem - Wert "dummy" hinzugefügt oder geändert werden. Wichtig: Der Devicecode sollte nicht der FHTID entsprechen.

      + Wert "virtual" hinzugefügt oder geändert werden. Wichtig: Der Devicecode sollte nicht der FHTID entsprechen.

      D @@ -459,20 +560,27 @@ CUL_FHTTK_Parse($$) Set -
        Nur vorhanden, wenn das Attribut model mit dummy definiert wurde.

        +
          Nur vorhanden, wenn das Attribut model mit virtual definiert wurde.

          set <name> <value>

          wobei value folgendes sein kann:
          -
            - Pair # startet das Anlernen an das FHT80B (FHT80B muss sich im Sync mode befinden) - danach wird der state auf "Closed" gesetzt
            - Closed # setzt den Fensterstatus zu Closed
            - Open # setzt den Fensterstatus zu Open
            - ReSync # neu synchronisieren des virtuellen Sensor mit dem FHT80b Module. Damit wird ein virtueller Batteriewechsel symuliert und der angelernte - Sensor wieder aufsynchronisiert. (aktuell nur mit Prototyp CUL FW verfügbar Forum 55774)
            -
          +
            +
          • Closed
            setzt den Fensterstatus zu Closed

          • +
          • Open
            setzt den Fensterstatus zu Open

          • +
          • Pair
            startet das Anlernen an das FHT80B (FHT80B muss sich im Sync mode befinden) - danach wird der state auf "Closed" gesetzt

          • +
          • ReSync
            neu synchronisieren des virtuellen Sensor mit dem FHT80b Module. Damit wird ein virtueller Batteriewechsel simuliert und der angelernte + Sensor wieder aufsynchronisiert. (aktuell nur mit Prototyp CUL FW verfügbar Forum 55774)

          • +

        - + + Spezielles zum "ReSync" von vorhanden FHT80TFs nach einem CUL Firmware Reset:
        + Nach einem Reset bzw. Neustart eines CUL Devices ist die Verbindung zwischen dem FHT80B und den virtuellen FHT80TFs unterbrochen. Dies kommt einem Batteriewechsel gleich. + Die Kontakte sind weiterhin am FHT80B angelernt. Ein neues Pairen entfällt. Wenn mehrere vitruelle Kontakte verwendet werden, empfiehlt es sich diese in großen Abständen + wieder zu synchronisieren!
        + Mithilfe des Aufrufes der Funktion CUL_FHTTK_ReSyncAll() werden alle virtuellen Fensterkontakte nacheinander mit den FHT80B wieder synchronisiert. + Der Abstand beträgt zwischen den einzelnen Sensoren 1 Stunde. Dies wird durch die 1% Regeln bestimmt, da pro Kontakt 480 credits innerhalb von 64 Sekunden verbraucht werden!

        + Get
          N/A

        @@ -482,7 +590,7 @@ CUL_FHTTK_Parse($$)