From 1d875b01431790567c6fa7edd7b8b0e4200757f8 Mon Sep 17 00:00:00 2001 From: tpoitzsch <> Date: Sat, 1 Nov 2014 17:11:39 +0000 Subject: [PATCH] proplanta: new readings git-svn-id: https://svn.fhem.de/fhem/trunk@6851 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/59_PROPLANTA.pm | 174 +++++++++++++++++++++++++++----------- 1 file changed, 125 insertions(+), 49 deletions(-) diff --git a/fhem/FHEM/59_PROPLANTA.pm b/fhem/FHEM/59_PROPLANTA.pm index 3cdfc2873..db7d940b2 100644 --- a/fhem/FHEM/59_PROPLANTA.pm +++ b/fhem/FHEM/59_PROPLANTA.pm @@ -21,6 +21,19 @@ my $curCol = 0; my $curTextPos = 0; my $curReadingType = 0; + my %url_start =( "de" => "http://www.proplanta.de/Wetter/" + , "at" => "http://www.proplanta.de/Agrarwetter-Oesterreich/" + , "ch" => "http://www.proplanta.de/Agrarwetter-Schweiz/" + , "fr" => "http://www.proplanta.de/Agrarwetter-Frankreich/" + , "it" => "http://www.proplanta.de/Agrarwetter-Italien/" + ); + my %url_end = ( "de" => "-Wetter.html" + , "at" => "/" + , "ch" => "/" + , "fr" => "/" + , "it" => "/" + ); + my %intensity = ( "keine" => 0 ,"nein" => 0 ,"gering" => 1 @@ -29,32 +42,50 @@ my $curReadingType = 0; ,"stark" => 3 ); - my @knownNoneIDs = ( ["Temperatur", "temperature"] - ,["relative Feuchte", "humidity"] - ,["Sichtweite", "visibility"] - ,["Windgeschwindigkeit", "wind"] - ,["Luftdruck", "pressure"] - ,["Taupunkt", "dewpoint"] + # 1 = Span Text, 2 = readingName, 3 = Tag-Type + # Tag-Types: + # 1 = Number Col 3 + # 2 = Number Col 2-5 + # 3 = Number Col 2|4|6|8 + # 4 = Intensity-Text Col 2-5 + # 5 = Time Col 2-5 + # 6 = Time Col 3 + my @knownNoneIDs = ( ["Temperatur", "temperature", 1] + ,["relative Feuchte", "humidity", 1] + ,["Sichtweite", "visibility", 1] + ,["Windgeschwindigkeit", "wind", 1] + ,["Luftdruck", "pressure", 1] + ,["Taupunkt", "dewPoint", 1] + ,["Uhrzeit", "time", 6] ); - # 1 = Tag-ID, 2 = readingName, 3 = Tag-Type - # Tag-Types: 1 = Number Col 2, 2 = Number Col 2-5, 3 = Number Col 2|4|6|8, 4 = Intensity-Text Col 2-5 + # 1 = Tag-ID, 2 = readingName, 3 = Tag-Type (see above) my @knownIDs = ( ["GS", "rad", 3] ,["UV", "uv", 2] ,["SD", "sun", 2] - ,["TMAX", "high_c", 2] - ,["TMIN", "low_c", 2] + ,["TMAX", "tempMaxC", 2] + ,["TMIN", "tempMinC", 2] ,["VERDUNST", "evapor", 4] ,["TAUBILDUNG", "dew", 4] ,["BF", "frost", 4] - ,["T_0", "t00_c", 2] - ,["T_3", "t03_c", 2] - ,["T_6", "t06_c", 2] - ,["T_9", "t09_c", 2] - ,["T_12", "t12_c", 2] - ,["T_15", "t15_c", 2] - ,["T_18", "t18_c", 2] - ,["T_21", "t21_c", 2] + ,["MA", "moonRise", 5] + ,["MU", "moonSet", 5] + ,["T_0", "temp00C", 2] + ,["T_3", "temp03C", 2] + ,["T_6", "temp06C", 2] + ,["T_9", "temp09C", 2] + ,["T_12", "temp12C", 2] + ,["T_15", "temp15C", 2] + ,["T_18", "temp18C", 2] + ,["T_21", "temp21C", 2] + ,["BD_0", "cloud00", 2] + ,["BD_3", "cloud03", 2] + ,["BD_6", "cloud06", 2] + ,["BD_9", "cloud09", 2] + ,["BD_12", "cloud12", 2] + ,["BD_15", "cloud15", 2] + ,["BD_18", "cloud18", 2] + ,["BD_21", "cloud21", 2] ); # here HTML::text/start/end are overridden @@ -69,6 +100,8 @@ sub text $text =~ s/^\s+//; # trim string $text =~ s/\s+$//; + $text =~ s/0/0/g; # replace 0 + # Tag-Type 0 = Check for readings without tag-ID if ($curReadingType == 0) { @@ -79,13 +112,13 @@ sub text if ( $$r[0] eq $text ) { $curReadingName = $$r[1]; - $curReadingType = 1; + $curReadingType = $$r[2]; last; } } } } - # Tag-Type 1 = Number Col 2 + # Tag-Type 1 = Number Col 3 elsif ($curReadingType == 1) { if ( $curCol == 3 ) @@ -105,8 +138,8 @@ sub text { if ( 1 < $curCol && $curCol <= 5 ) { - $readingName = "fc".($curCol-1)."_".$curReadingName; - if ( $text =~ m/([-,\+]?\d+[,\.]?\d*)/ ) + $readingName = "fc".($curCol-2)."_".$curReadingName; + if ( $text =~ m/([-+]?\d+[,.]?\d*)/ ) { $text = $1; $text =~ tr/,/./; # komma durch punkt ersetzen @@ -121,23 +154,55 @@ sub text { if ( $curTextPos % 2 == 1 ) { - $readingName = "fc".($curCol-1)."_".$curReadingName; + $readingName = "fc".($curCol-2)."_".$curReadingName; $text =~ tr/,/./; # komma durch punkt ersetzen push( @texte, $readingName."|".$text ); } } } # Tag-Type 4 = Intensity-Text Col 2-5 - elsif ($curReadingType == 4) { + elsif ($curReadingType == 4) + { if ( 1 < $curCol && $curCol <= 5 ) { - $readingName = "fc".($curCol-1)."_".$curReadingName; - push( @texte, $readingName."|".$intensity{$text} ); + $readingName = "fc".($curCol-2)."_".$curReadingName; + $text = $intensity{$text} if defined $intensity{$text}; + push( @texte, $readingName . "|" . $text ); + } + } + # Tag-Type 5 = Time Col 2-5 + elsif ($curReadingType == 5) + { + if ( 2 <= $curCol && $curCol <= 5 ) + { + $readingName = "fc".($curCol-2)."_".$curReadingName; + if ( $text =~ m/([012]?\d[.:][0-5]\d)/ ) + { + $text = $1; + $text =~ tr/./:/; # Punkt durch Doppelpunkt ersetzen + } + push( @texte, $readingName."|".$text ); + } + } + # Tag-Type 6 = Time Col 3 + elsif ($curReadingType == 6) + { + if ( $curCol == 3 ) + { + $readingName = $curReadingName; + if ( $text =~ m/([012]?\d[.:][0-5]\d)/ ) + { + $text = $1; + $text =~ tr/./:/; # Punkt durch Doppelpunkt ersetzen + } + push( @texte, $readingName."|".$text ); } } } } +#{"50 %" =~ m/([-+]?\d+[,.]?\d*)/;;return $1;;} + sub start { my ( $self, $tagname, $attr, $attrseq, $origtext ) = @_; @@ -221,14 +286,18 @@ sub PROPLANTA_Define($$) { my ( $hash, $def ) = @_; my $name = $hash->{NAME}; + my $lang = ""; my @a = split( "[ \t][ \t]*", $def ); - if ( int(@a) > 4 ) + + return "Wrong syntax: use define PROPLANTA [City] [CountryCode]" if int(@a) > 4; + + $lang = "de" if int(@a) == 3; + $lang = lc( $a[3] ) if int(@a) == 4; + + if ( $lang ne "") { - return "Wrong syntax: use define PROPLANTA [City] [Country]"; - } - elsif ( int(@a) == 3 ) - { - $hash->{URL} = "http://www.proplanta.de/Wetter/".$a[2]."-Wetter.html"; + return "Wrong country code '$lang': use " . join(" | ", keys( %url_start ) ) unless defined( $url_start{$lang} ); + $hash->{URL} = $url_start{$lang} . $a[2] . $url_end{$lang}; } $hash->{STATE} = "Initializing"; @@ -401,7 +470,7 @@ sub PROPLANTA_Done($) # Wetterdaten speichern readingsBeginUpdate($hash); - readingsBulkUpdate($hash,"state","T: ".$values{temperature}." H: ".$values{humidity}." W: ".$values{wind} ); + readingsBulkUpdate($hash, "state", sprintf "T: %.1f H: %.1f W: %.1f P: %.0f ", $values{temperature}, $values{humidity}, $values{wind}, $values{pressure} ); my $x = 0; while (my ($rName, $rValue) = each(%values) ) @@ -429,18 +498,20 @@ sub PROPLANTA_Aborted($)

PROPLANTA