Twilight attr disable

Begonnen von Amenophis86, 11 September 2018, 20:15:23

Vorheriges Thema - Nächstes Thema

Amenophis86

Ist es möglich bei Twilight das Attr disable einzubauen? Hintergrund ist, dass ich bei Ausfall des Internets sämtliche Module, welche Daten aus dem Internet holen deaktivieren will. Dazu gehört ja auch Twilight.
Aktuell dabei unser neues Haus mit KNX am einrichten. Im nächsten Schritt dann KNX mit FHEM verbinden. Allein zwei Dinge sind dabei selten: Zeit und Geld...

Markus M.

Maintainer ist igami

Lustigerweise hatte ich sowas mal angefangen, nicht nur disable sondern auch offline um nur die Kommunikation zeiweise abzuschalten.
Ist allerdings nicht wirklich getestet, hier ist der diff:
Index: 59_Twilight.pm
===================================================================
--- 59_Twilight.pm (revision 17326)
+++ 59_Twilight.pm (working copy)
@@ -53,7 +53,11 @@
   $hash->{DefFn}   = "Twilight_Define";
   $hash->{UndefFn} = "Twilight_Undef";
   $hash->{GetFn}   = "Twilight_Get";
-  $hash->{AttrList}= "$readingFnAttributes " ."useExtWeather";
+  $hash->{AttrList}= "$readingFnAttributes ".
+                     "useExtWeather ".
+                     "offline:0,1 ".
+                     "disable:0,1 ";
+
   return undef;
}
################################################################################
@@ -128,6 +132,10 @@
   $attr{$name}{verbose} = 4    if ($name =~ /^tst.*$/ );

   my $mHash = { HASH=>$hash };
+
+  my $name = $mHash->{NAME};
+  return undef if(IsDisabled($name));
+
   Twilight_sunpos($mHash);
   Twilight_Midnight($mHash);

@@ -379,6 +387,12 @@
   my $hash = myGetHashIndirekt($myHash, (caller(0))[3]);
   return if (!defined($hash));

+  my $name = $hash->{NAME};
+  if(IsDisabled($name) || AttrVal($name, "offline", 0) eq 1) {
+    Twilight_StandardTimerSet($hash);
+    return undef;
+  }
+
   my $location = $hash->{WEATHER};
   my $verbose  = AttrVal($hash->{NAME}, "verbose", 3 );

@@ -457,6 +471,10 @@

   myRemoveInternalTimer       ("Midnight", $hash);
   myInternalTimer             ("Midnight", $midnight, "Twilight_Midnight", $hash, 0);
+
+  my $name = $hash->{NAME};
+  return undef if(AttrVal($name, "offline", 0) eq 1);
+
   Twilight_WeatherTimerSet    ($hash);
}
################################################################################
@@ -528,6 +546,17 @@
           $cond_code  = $resHash->{query}{results}{channel}{item}{condition}{code};
           $cond_txt   = $resHash->{query}{results}{channel}{item}{condition}{text};
           $temperatur = $resHash->{query}{results}{channel}{item}{condition}{temp};
+
+          if (defined($cond_code) ) {
+            readingsBeginUpdate($hash);
+            readingsBulkUpdate ($hash,  "temperature", $resHash->{query}{results}{channel}{item}{condition}{temp}) if(defined($resHash->{query}{results}{channel}{item}{condition}{temp}));
+            readingsBulkUpdate ($hash,  "humidity", $resHash->{query}{results}{channel}{atmosphere}{humidity}) if(defined($resHash->{query}{results}{channel}{atmosphere}{humidity}));
+            readingsBulkUpdate ($hash,  "visibility", $resHash->{query}{results}{channel}{atmosphere}{visibility}) if(defined($resHash->{query}{results}{channel}{atmosphere}{visibility}));
+            readingsBulkUpdate ($hash,  "wind", $resHash->{query}{results}{channel}{wind}{speed}) if(defined($resHash->{query}{results}{channel}{wind}{speed}));
+            readingsBulkUpdate ($hash,  "fc_high", $resHash->{query}{results}{channel}{item}{forecast}[0]{high}) if(defined($resHash->{query}{results}{channel}{item}{forecast}[0]{high}));
+            readingsBulkUpdate ($hash,  "fc_low", $resHash->{query}{results}{channel}{item}{forecast}[0]{low}) if(defined($resHash->{query}{results}{channel}{item}{forecast}[0]{low}));
+            readingsEndUpdate($hash,1);
+          }
        }
      }
   }
@@ -562,10 +591,9 @@
   my $hash = myGetHashIndirekt($myHash, (caller(0))[3]);
   return if (!defined($hash));

-  my $hashName = $hash->{NAME};
+  my $name = $hash->{NAME};
+  return undef if(IsDisabled($name));

-  return "" if(AttrVal($hashName, "disable", undef));
-
   my $tn = TimeNow();
   my ($dSeconds,$dMinutes,$dHours,$iDay,$iMonth,$iYear,$wday,$yday,$isdst) = gmtime(time);
   $iMonth++;
@@ -644,7 +672,7 @@

   my $twilight_weather ;

-  if( (my $ExtWeather = AttrVal($hashName, "useExtWeather", "")) eq "") {
+  if( (my $ExtWeather = AttrVal($name, "useExtWeather", "")) eq "") {
      $twilight_weather = int(($dElevation-$hash->{WEATHER_HORIZON}+12.0)/18.0 * 1000)/10;
    Log3 $hash, 5, "[$hash->{NAME}] " . "Original weather readings";
   } else {
FHEM dev + HomeBridge + Lenovo Flex15 + HM-CFG-USB + RFXtrx433 + Fritz!Box 7590/7580/546E

HM Aktor/Sensor/Winmatic/Keymatic/Thermostat, HUE, Netatmo Weather/Security/Heating, Xiaomi AirPurifier/Vacuum, Withings Aura/BPM/Cardio/Go/Pulse/Thermo, VSX828, Harmony, Siro ERB15LE
https://paypal.me/mm0

Amenophis86

Schau ich mir mal an. Dank dir.
Aktuell dabei unser neues Haus mit KNX am einrichten. Im nächsten Schritt dann KNX mit FHEM verbinden. Allein zwei Dinge sind dabei selten: Zeit und Geld...