diff --git a/controls_Weather.txt b/controls_Weather.txt index 74f16bc..4f5d0b7 100644 --- a/controls_Weather.txt +++ b/controls_Weather.txt @@ -1,5 +1,5 @@ -UPD 2024-10-11_12:02:22 25848 FHEM/59_Weather.pm -UPD 2024-10-11_11:59:21 34293 lib/FHEM/Core/Weather.pm +UPD 2024-10-11_19:46:40 25848 FHEM/59_Weather.pm +UPD 2025-02-04_20:50:25 34419 lib/FHEM/Core/Weather.pm UPD 2023-01-29_16:14:48 50106 lib/FHEM/APIs/Weather/DarkSkyAPI.pm UPD 2023-07-11_14:08:00 33779 lib/FHEM/APIs/Weather/OpenWeatherMapAPI.pm -UPD 2024-10-11_12:02:42 37627 lib/FHEM/APIs/Weather/wundergroundAPI.pm +UPD 2025-02-04_20:47:55 38751 lib/FHEM/APIs/Weather/wundergroundAPI.pm diff --git a/lib/FHEM/APIs/Weather/wundergroundAPI.pm b/lib/FHEM/APIs/Weather/wundergroundAPI.pm index 5e51e42..e8ac120 100644 --- a/lib/FHEM/APIs/Weather/wundergroundAPI.pm +++ b/lib/FHEM/APIs/Weather/wundergroundAPI.pm @@ -15,9 +15,9 @@ return "$@" if ($@); return $ret if ($ret); $::packages{wundergroundAPI}{META} = $META; -use version 0.80; our $VERSION = $META->{version}; +use version 0.77; our $VERSION = $META->{version}; -use Data::Dumper; +#use Data::Dumper; # for Debug only # try to use JSON::MaybeXS wrapper # for chance of better performance + open code @@ -84,7 +84,6 @@ eval { use Readonly; 1 } or $missingModul .= 'Readonly '; # apt install libreadonly-perl ## use critic -# use Data::Dumper; # for Debug only ## API URL Readonly my $DEMODATA => '{"daily":{"dayOfWeek":["Freitag","Samstag","Sonntag","Montag","Dienstag","Mittwoch"],"expirationTimeUtc":[1555688120,1555688120,1555688120,1555688120,1555688120,1555688120],"moonPhase":["Vollmond","abnehmender Halbmond","abnehmender Halbmond","abnehmender Halbmond","abnehmender Halbmond","abnehmender Halbmond"],"moonPhaseCode":["F","WNG","WNG","WNG","WNG","WNG"],"moonPhaseDay":[15,16,17,18,19,20],"moonriseTimeLocal":["2019-04-19T20:09:54+0200","2019-04-20T21:30:54+0200","2019-04-21T22:48:07+0200","","2019-04-23T00:00:38+0200","2019-04-24T01:05:27+0200"],"moonriseTimeUtc":[1555697394,1555788654,1555879687,null,1555970438,1556060727],"moonsetTimeLocal":["2019-04-19T06:31:01+0200","2019-04-20T06:54:19+0200","2019-04-21T07:20:19+0200","2019-04-22T07:50:19+0200","2019-04-23T08:25:54+0200","2019-04-24T09:09:28+0200"],"moonsetTimeUtc":[1555648261,1555736059,1555824019,1555912219,1556000754,1556089768],"narrative":["Meistens klar. Tiefsttemperatur 5C.","Meistens klar. Höchsttemperaturen 19 bis 21C und Tiefsttemperaturen 4 bis 6C.","Meistens klar. Höchsttemperaturen 20 bis 22C und Tiefsttemperaturen 6 bis 8C.","Meistens klar. Höchsttemperaturen 20 bis 22C und Tiefsttemperaturen 9 bis 11C.","Teilweise bedeckt und windig. Höchsttemperaturen 21 bis 23C und Tiefsttemperaturen 11 bis 13C.","Teilweise bedeckt. Höchsttemperaturen 22 bis 24C und Tiefsttemperaturen 12 bis 14C."],"qpf":[0.0,0.0,0.0,0.0,0.0,0.0],"qpfSnow":[0.0,0.0,0.0,0.0,0.0,0.0],"sunriseTimeLocal":["2019-04-19T06:00:46+0200","2019-04-20T05:58:38+0200","2019-04-21T05:56:31+0200","2019-04-22T05:54:25+0200","2019-04-23T05:52:20+0200","2019-04-24T05:50:15+0200"],"sunriseTimeUtc":[1555646446,1555732718,1555818991,1555905265,1555991540,1556077815],"sunsetTimeLocal":["2019-04-19T20:11:02+0200","2019-04-20T20:12:46+0200","2019-04-21T20:14:29+0200","2019-04-22T20:16:13+0200","2019-04-23T20:17:56+0200","2019-04-24T20:19:40+0200"],"sunsetTimeUtc":[1555697462,1555783966,1555870469,1555956973,1556043476,1556129980],"temperatureMax":[null,20,21,21,22,23],"temperatureMin":[5,5,7,10,12,13],"validTimeLocal":["2019-04-19T07:00:00+0200","2019-04-20T07:00:00+0200","2019-04-21T07:00:00+0200","2019-04-22T07:00:00+0200","2019-04-23T07:00:00+0200","2019-04-24T07:00:00+0200"],"validTimeUtc":[1555650000,1555736400,1555822800,1555909200,1555995600,1556082000],"daypart":[{"cloudCover":[null,0,25,8,0,0,7,26,55,46,62,44],"dayOrNight":[null,"N","D","N","D","N","D","N","D","N","D","N"],"daypartName":[null,"Heute Abend","Morgen","Morgen Abend","Sonntag","Sonntagnacht","Montag","Montagnacht","Dienstag","Dienstagnacht","Mittwoch","Mittwochnacht"],"iconCode":[null,31,34,33,32,31,34,33,24,29,30,29],"iconCodeExtend":[null,3100,3400,3300,3200,3100,3400,3300,3010,2900,3000,2900],"narrative":[null,"Meistens klar. Tiefsttemperatur 5C. Wind aus NO mit 2 bis 4 m/s.","Meistens klar. Höchsttemperatur 20C. Wind aus NNO mit 2 bis 4 m/s.","Meistens klar. Tiefsttemperatur 5C. Wind aus NO mit 2 bis 4 m/s.","Meistens klar. Höchsttemperatur 21C. Wind aus O und wechselhaft.","Meistens klar. Tiefsttemperatur 7C. Wind aus ONO und wechselhaft.","Meistens klar. Höchsttemperatur 21C. Wind aus O mit 4 bis 9 m/s.","Meistens klar. Tiefsttemperatur 10C. Wind aus O mit 4 bis 9 m/s.","Teilweise bedeckt und windig. Höchsttemperatur 22C. Wind aus OSO mit 9 bis 13 m/s.","Teilweise bedeckt. Tiefsttemperatur 12C. Wind aus SO mit 4 bis 9 m/s.","Teilweise bedeckt. Höchsttemperatur 23C. Wind aus SO mit 4 bis 9 m/s.","Teilweise bedeckt. Tiefsttemperatur 13C. Wind aus SO mit 2 bis 4 m/s."],"precipChance":[null,0,0,0,0,0,20,20,0,0,0,10],"precipType":[null,"rain","rain","rain","rain","rain","rain","rain","rain","rain","rain","rain"],"qpf":[null,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"qpfSnow":[null,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"qualifierCode":[null,null,null,null,null,null,null,null,null,null,null,null],"qualifierPhrase":[null,null,null,null,null,null,null,null,null,null,null,null],"relativeHumidity":[null,50,44,55,41,55,42,48,45,55,53,64],"snowRange":[null,"","","","","","","","","","",""],"temperature":[null,5,20,5,21,7,21,10,22,12,23,13],"temperatureHeatIndex":[null,21,20,18,20,18,20,18,22,20,23,22],"temperatureWindChill":[null,5,5,5,6,6,7,8,8,10,10,13],"thunderCategory":[null,null,null,null,null,null,null,null,null,null,null,null],"thunderIndex":[null,0,0,0,0,0,0,0,0,0,0,0],"uvDescription":[null,"Niedrig","Mittel","Niedrig","Mittel","Niedrig","Mittel","Niedrig","Mittel","Niedrig","Mittel","Niedrig"],"uvIndex":[null,0,4,0,4,0,4,0,4,0,4,0],"windDirection":[null,45,18,41,85,74,95,98,114,124,139,131],"windDirectionCardinal":[null,"NO","NNO","NO","O","ONO","O","O","OSO","SO","SO","SO"],"windPhrase":[null,"Wind aus NO mit 2 bis 4 m/s.","Wind aus NNO mit 2 bis 4 m/s.","Wind aus NO mit 2 bis 4 m/s.","Wind aus O und wechselhaft.","Wind aus ONO und wechselhaft.","Wind aus O mit 4 bis 9 m/s.","Wind aus O mit 4 bis 9 m/s.","Wind aus OSO mit 9 bis 13 m/s.","Wind aus SO mit 4 bis 9 m/s.","Wind aus SO mit 4 bis 9 m/s.","Wind aus SO mit 2 bis 4 m/s."],"windSpeed":[null,4,3,3,2,2,6,6,9,7,6,4],"wxPhraseLong":[null,"Klar","Meist sonnig","Meist klar","Sonnig","Klar","Meist sonnig","Meist klar","Teilweise bedeckt/Wind","Wolkig","Wolkig","Wolkig"],"wxPhraseShort":[null,"","","","","","","","","","",""]}]},"observations":[{"stationID":"IMUNICH344","obsTimeUtc":"2019-04-19T15:24:22Z","obsTimeLocal":"2019-04-19 17:24:22","neighborhood":"Am Hartmannshofer Baechl 34","softwareType":"weewx-3.8.2","country":"DE","solarRadiation":null,"lon":11.49312592,"realtimeFrequency":null,"epoch":1555687462,"lat":48.18364716,"uv":null,"winddir":null,"humidity":27,"qcStatus":1,"metric_si":{"temp":23,"heatIndex":22,"dewpt":3,"windChill":23,"windSpeed":0,"windGust":1,"pressure":1025.84,"precipRate":0.0,"precipTotal":0.0,"elev":502}}]}'; @@ -214,6 +213,8 @@ sub _RetrieveDataFromWU { my $paramRef; my $options; + #my $datestring; ## for debugging + $self->{cached}->{lat} = $self->{lat} unless ( $self->{cached}->{lat} == $self->{lat} ); $self->{cached}->{long} = $self->{long} @@ -243,6 +244,8 @@ sub _RetrieveDataFromWU { } else { # Get the complete data station and forecast + #$datestring = localtime(); ## for debugging + #print Dumper "$datestring WunderAPI get complete"; ## for debugging $paramRef = { timeout => 15, self => $self, @@ -291,7 +294,12 @@ sub _RetrieveDataFromWU { if ( lc( $self->{key} ) eq 'demo' ) { _RetrieveDataFinished( $paramRef, undef, 'DEMODATA' . $DEMODATA ); } - else { ::HttpUtils_NonblockingGet($paramRef); } + else { + #$datestring = localtime(); ## for debugging + #print Dumper "$datestring Wunderground API HTTP call"; ## for debugging + #print Dumper $paramRef; ## for debugging + ::HttpUtils_NonblockingGet($paramRef); + } } return; @@ -305,6 +313,8 @@ sub _RetrieveDataFromPWS { my $response = shift; my $self = $paramRef->{self}; + #my $datestring; ## for debugging + my $paramRefPWS = { timeout => 15, self => $self, @@ -324,6 +334,8 @@ sub _RetrieveDataFromPWS { $paramRefPWS->{url} = $URL . 'v2/pws/observations/current?' . $options; + #$datestring = localtime(); + #print Dumper "$datestring Wunderground PWS API HTTP call"; ## for debugging return ::HttpUtils_NonblockingGet($paramRefPWS); } @@ -662,6 +674,13 @@ sub _ProcessingRetrieveData { $self->{uvIndex} = $data->{uvIndex}[$i] unless ( !$data->{uvIndex}[$i] || defined( $self->{uvIndex} ) ); + + if ( $part eq 'day' ) { + $self->{codeDay} = $data->{iconCode}[$i] + unless ( !$data->{iconCode}[$i] + || defined( $self->{codeDay} ) ); + } + } # if this is today, copy some values to current @@ -696,6 +715,12 @@ sub _ProcessingRetrieveData { $self->{uvIndex} = $data->{uvIndex}[$i] unless ( !$data->{uvIndex}[$i] || defined( $self->{uvIndex} ) ); + + if ( $i eq '0' ) { + $self->{codeDay} = $data->{iconCode}[$i] + unless ( !$data->{iconCode}[$i] + || defined( $self->{codeDay} ) ); + } } push( @@ -840,7 +865,7 @@ sub _strftimeWrapper { "abstract": "Wetter API für Weather Underground" } }, - "version": "v1.3.0", + "version": "v1.2.0", "author": [ "Julian Pawlowski " ], diff --git a/lib/FHEM/Core/Weather.pm b/lib/FHEM/Core/Weather.pm index e039981..e74b577 100644 --- a/lib/FHEM/Core/Weather.pm +++ b/lib/FHEM/Core/Weather.pm @@ -434,8 +434,13 @@ sub _Writereadings { && ref( $dataRef->{$r} ) ne 'ARRAY' ); } - ::readingsBulkUpdate( $hash, 'icon', - $iconlist[ $dataRef->{current}->{code} ] ); + if ( defined( $dataRef->{current}->{code} ) + && $dataRef->{current}->{code} ) + { + ::readingsBulkUpdate( $hash, 'icon', + $iconlist[ $dataRef->{current}->{code} ] ); + } + if ( defined( $dataRef->{current}->{wind_direction} ) && $dataRef->{current}->{wind_direction} && defined( $dataRef->{current}->{wind_speed} )