From 8e8d46ff10f087f37eda0e9671c737ee1d98a70a Mon Sep 17 00:00:00 2001 From: tpoitzsch <> Date: Wed, 19 Nov 2014 21:34:51 +0000 Subject: [PATCH] OPENWEATHER: docu git-svn-id: https://svn.fhem.de/fhem/trunk@7022 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/59_OPENWEATHER.pm | 127 ++++++++++++++++++++++++------------ 1 file changed, 84 insertions(+), 43 deletions(-) diff --git a/fhem/FHEM/59_OPENWEATHER.pm b/fhem/FHEM/59_OPENWEATHER.pm index 993f5f50c..998069728 100644 --- a/fhem/FHEM/59_OPENWEATHER.pm +++ b/fhem/FHEM/59_OPENWEATHER.pm @@ -63,9 +63,9 @@ get_wday($) { my ($date) = @_; my @wday_txt = qw(So Mo Di Mi Do Fr Sa); - my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $date; - - return $wday_txt [$wday]; + my @th=localtime $date; + + return $wday_txt [$th[6]]; } sub text @@ -181,6 +181,7 @@ OPENWEATHER_Initialize($) $hash->{GetFn} = "OPENWEATHER_Get"; $hash->{AttrFn} = "OPENWEATHER_Attr"; $hash->{AttrList} = "disable:0,1 " + ."INTERVAL " .$readingFnAttributes; } # end OPENWEATHER_Initialize @@ -195,18 +196,16 @@ OPENWEATHER_Define($$) return "Usage: define OPENWEATHER [language]" if(@args <5 || @args >6); my $name = $args[0]; - my $interval = 3600; $hash->{NAME} = $name; - $hash->{STATE} = "Initializing" if $interval > 0; - $hash->{STATE} = "Manual mode" if $interval == 0; - $hash->{INTERVAL} = $interval; - $hash->{PROJECT} = $args[2]; - $hash->{CITYCODE} = $args[3]; - $hash->{APIKEY} = $args[4]; - $hash->{LANGUAGE} = $args[5] if defined $args[5]; - $hash->{CREDIT} = "Powered by wetter.com"; + $hash->{STATE} = "Initializing"; + $hash->{INTERVAL} = 3600; + $hash->{PROJECT} = $args[2]; + $hash->{CITYCODE} = $args[3]; + $hash->{APIKEY} = $args[4]; + $hash->{LANGUAGE} = $args[5] if defined $args[5]; + $hash->{CREDIT} = "Powered by wetter.com"; my $checkSum = md5_hex( $args[2] . $args[4] . $args[3] ); @@ -218,13 +217,14 @@ OPENWEATHER_Define($$) $hash->{URL} = $URL; + $hash->{fhem}{LOCAL} = 0; + $hash->{fhem}{modulVersion} = '$Date$'; + RemoveInternalTimer($hash); # Get first data after 7 seconds - InternalTimer(gettimeofday() + 7, "OPENWEATHER_Start", $hash, 0) if $interval > 0; - - $hash->{fhem}{modulVersion} = '$Date$'; + InternalTimer(gettimeofday() + 7, "OPENWEATHER_Start", $hash, 0); - return undef; + return undef; } #end OPENWEATHER_Define @@ -245,22 +245,41 @@ sub ########################################## OPENWEATHER_Attr($@) { my ($cmd,$name,$aName,$aVal) = @_; - # $cmd can be "del" or "set" - # $name is device name - # aName and aVal are Attribute name and value - if ($cmd eq "set") + # $cmd can be "del" or "set" + # $name is device name + # aName and aVal are Attribute name and value + my $hash = $defs{$name}; + + if ($cmd eq "set") { - if ($aName eq "1allowSetParameter") + if ($aName eq "INTERVAL") { - eval { qr/$aVal/ }; - if ($@) + if ($aVal < 3600 && $aVal != 0) { - OPENWEATHER_Log $name, 3, "Invalid allowSetParameter in attr $name $aName $aVal: $@"; - return "Invalid allowSetParameter $aVal"; + OPENWEATHER_Log $name, 3, "Error: Minimum of attribute INTERVAL is 3600 or 0"; + return "Minimum of attribute INTERVAL is 3600 or 0"; + } + else + { + # Internal Timer neu starten + RemoveInternalTimer($hash); + if ($aVal >0) + { + InternalTimer(gettimeofday()+7, "OPENWEATHER_Start", $hash, 0); + } } } } - + elsif ($cmd eq "del") + { + if ($aName eq "INTERVAL") + { + # Internal Timer neu starten + RemoveInternalTimer($hash); + InternalTimer(gettimeofday()+1, "OPENWEATHER_Start", $hash, 0); + } + } + return undef; } # OPENWEATHER_Attr ende @@ -273,9 +292,9 @@ OPENWEATHER_Set($$@) if(lc $cmd eq 'update') { - $hash->{LOCAL} = 1; + $hash->{fhem}{LOCAL} = 1; OPENWEATHER_Start($hash); - $hash->{LOCAL} = 0; + $hash->{fhem}{LOCAL} = 0; return undef; } my $list = "update:noArg"; @@ -326,9 +345,11 @@ OPENWEATHER_Start($) { my ($hash) = @_; my $name = $hash->{NAME}; - - - if(!$hash->{LOCAL} && $hash->{INTERVAL} > 0) { + + $hash->{INTERVAL} = AttrVal( $name, "INTERVAL", 3600 ); + + if( $hash->{fhem}{LOCAL} != 1 && $hash->{INTERVAL} > 0 ) + { RemoveInternalTimer($hash); InternalTimer(gettimeofday()+$hash->{INTERVAL}, "OPENWEATHER_Start", $hash, 1); return undef if( AttrVal($name, "disable", 0 ) == 1 ); @@ -467,7 +488,7 @@ OPENWEATHER_Html($) for(my $i=0; $i<=2; $i++) { - $ret .= sprintf('%s%s
min. %s °C max. %s °C
Niederschlagsrisiko: %s %
Wind: %s km/h aus %s', + $ret .= sprintf('%s%s
min. %s °C max. %s °C
Nieders.risiko: %s %
Wind: %s km/h aus %s', $i==0 ? "heute" : ReadingsVal($d, "fc".$i."_wday", "") , ReadingsVal($d, "fc".$i."_weather", "") , ReadingsVal($d, "fc".$i."_tempMin", ""), ReadingsVal($d, "fc".$i."_tempMax", "") @@ -476,7 +497,7 @@ OPENWEATHER_Html($) ); } - $ret .= "powered by wetter.com"; + $ret .= sprintf ('powered by wetter.com', ReadingsVal($d, "url", "") ); $ret .= ""; return $ret; @@ -530,9 +551,11 @@ OPENWEATHER_Html($)
Optional. Default language of weather description is German. Change with en to English or es to Spanish.
- The function OPENWEATHER_Html creates a HTML code for a vertically arranged weather forecast. + The function OPENWEATHER_Html creates a HTML code for a vertically arranged weather forecast.
- Example: define MyWeatherWeblink weblink htmlCode { OPENWEATHER_Html("MyWeather") } + Example: +
+ define MyForecast weblink htmlCode { OPENWEATHER_Html("MyWeather") }

@@ -560,6 +583,14 @@ OPENWEATHER_Html($) Attributes

    +
  • disable <0 | 1> +
    + Automatic update is stopped if set to 1. +

  • +
  • INTERVAL <seconds> +
    + Polling interval for weather data in seconds (default and smallest value is 3600 = 1 hour). 0 will stop automatic updates. +

  • readingFnAttributes

@@ -568,8 +599,8 @@ OPENWEATHER_Html($) Forecast readings
    Note! The forecast values (in brackets) have first to be selected on the project setup page on wetter.com. -
    -

  • fc0|1|2_... - forecast values for today|tommorrow|in 2 days
  • +
     
    +
  • fc0|1|2_... - forecast values for today|tommorrow|in 2 days
  • fc0_...06|11|17|23 - forecast values for today at 06|11|17|23 o'clock
  • fc1_tempMin|Max - minimal|maximal temperature for tommorrow in °C (tn,tx)
  • fc0_tempMin06 - minimal temperatur today at 06:00 o'clock in °C
  • @@ -631,9 +662,11 @@ OPENWEATHER_Html($)
    Optional. Standardsprache für die Wettersituation ist Deutsch. Mit en kann man zu Englisch und mit es zu Spanisch wechseln.
    - Über die Funktion OPENWEATHER_Html wird ein HTML-Code für ein vertikal arrangierte Wettervorhersage erzeugt. + Über die Funktion OPENWEATHER_Html wird ein HTML-Code für ein vertikal arrangierte Wettervorhersage erzeugt.
    - Beispiel: define MyWeatherWeblink weblink htmlCode { OPENWEATHER_Html("MyWeather") } + Beispiel: +
    + define MyForecast weblink htmlCode { OPENWEATHER_Html("MyWeather") }

@@ -661,6 +694,14 @@ OPENWEATHER_Html($) Attribute

    +
  • disable <0 | 1> +
    + Automatische Aktuallisierung ist angehalten, wenn der Wert auf 1 gesetzt wird. +

  • +
  • INTERVAL <Abfrageinterval> +
    + Abfrageinterval in Sekunden (Standard und kleinster Wert ist 3600 = 1 Stunde). 0 stoppt die automatische Aktualisierung +

  • readingFnAttributes

@@ -668,11 +709,11 @@ OPENWEATHER_Html($) Vorhersagewerte
    - Wichtig! Die Vorhersagewerte müssen zuerst in den Vorhersageeinstellungen (in Klammern) des Projektes auf wetter.com ausgewählt werden. - -

  • fc0|1|2_... - Vorhersagewerte für heute|morgen|übermorgen
  • + Wichtig! Die Vorhersagewerte (in Klammern) müssen zuerst in den Vorhersageeinstellungen des Projektes auf wetter.com ausgewählt werden. +
     
    +
  • fc0|1|2_... - Vorhersagewerte für heute|morgen|übermorgen
  • fc0_...06|11|17|23 - Vorhersagewerte für heute um 06|11|17|23 Uhr
  • -
  • fc0_chOfRain - heutige Niederschlagswahrscheinlichkeit in % (PC)
  • +
  • fc0_chOfRain - heutige Niederschlagswahrscheinlichkeit in % (pc)
  • fc0_tempMin|Max - Mindest|Maximaltemperatur heute in °C (tn, tx)
  • fc0_tempMin06 - Mindesttemperatur heute um 06:00 Uhr in °C
  • fc0_valHours06 - Gültigkeitszeitraum der Prognose von heute ab 6:00 Uhr in Stunden (p)