[OpenWeatherAPI.pm] Neue Version API Modul für 59_Weather.pm

Begonnen von CoolTux, 13 Februar 2022, 11:33:05

Vorheriges Thema - Nächstes Thema

didi-fritz

#15
bei forecast hourly und forecastLimit 15 erhalte ich die hfc*-readings
die fc*-readings fehlen leider

DeeSPe

Zitat von: didi-fritz am 07 April 2023, 17:51:50die fc*-readings fehlen leider

Das ist bei mir leider auch so nach Umstellung von DarkSkyAPI auf OpenWeatherMapAPI.

Evtl. findet Marko ja das Problem.

Gruß
Dan
MAINTAINER: 22_HOMEMODE, 98_Hyperion, 98_FileLogConvert, 98_serviced

Als kleine Unterstützung für meine Programmierungen könnt ihr mir gerne einen Kaffee spendieren: https://buymeacoff.ee/DeeSPe

MadMax-FHEM

FHEM PI3B+ Bullseye: HM-CFG-USB, 40x HM, ZWave-USB, 13x ZWave, EnOcean-PI, 15x EnOcean, HUE/deCONZ, CO2, ESP-Multisensor, Shelly, alexa-fhem, ...
FHEM PI2 Buster: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, Shelly, ha-bridge, ...
FHEM PI3 Buster (Test)

CoolTux

Meines Erachtens ist das kein Problem vom Modul sondern die API liefert in dieser 2.5 Version nur stündlichen Forecast alle 3 Stunden auf 5 Tagebasis oder so.
Du musst nicht wissen wie es geht! Du musst nur wissen wo es steht, wie es geht.
Support me to buy new test hardware for development: https://www.paypal.com/paypalme/MOldenburg
My FHEM Git: https://git.cooltux.net/FHEM/
Das TuxNet Wiki:
https://www.cooltux.net

fred_feuerstein

#19
Mit der Api 3 erhalte ich bzgl. Regenwahrscheinlichkeit nur die Niederschlagsmenge in mm (reading fcX_rain) aber nicht die eigentliche Wahrscheinlichkeit in Prozent.
geliefert wird also nur die "precipitation" aber es fehlt "probability of precipitation".

Scheinbar kommt keine regenwahrwcheiichkeit mehr über die api. Das ist sehr schade. Nur noch die Niederschlagmenge in mm/h.

Oder gibt es noch eine andere Möglichkeit?

Gruß, Fred

FHEM auf Raspberry PI 3B+ im 7Zoll TouchDisplay Gehäuse, OS: Bullseye, mit Z-Wave RaZberry-Modul, 868CUL (WMBUS), LaCrosseCUL (Temp) und knapp 300 Devices aller Art

didi-fritz

#20
ich habe mir in meiner 99_myUtils.pm eine Funktion "calcWeather" geschrieben, die aus den 3-stündlichen hfc*-daten von Version 2.5 versucht, daily-daten (fc*) zu "errechnen"...
sub calcWeather
{
    my ($w, $rest) = @_;

    #Log 2, "calcWeather(\"$w\")";

    my $debug="";
    my $hfcCnt=0;
    my $fcCnt=0;

    my $Dcnt=0;
    my $Dday="init";
    my $Ddate="";
    my $Dcode="";
    my $Dcondition="";
    my $Dpressure="";
    my $Dhumidity=0;
    my $DcloudCover=0;
    my $Drain=0;
    my $Dhigh_c=0;
    my $Dlow_c=0;
    my $Dicon="";
    my $DiconAPI="";
    my $Dwind=0;
    my $Dwind_gust=0;
    my $p1=0;
    my $p2=0;
    my %cnt_code;
    my %cnt_condition;
    my %cnt_icon;
    my %cnt_iconAPI;

    #my $pubDate=ReadingsVal($w, "hfc${hfcCnt}_pubDate",0);
    #my $d=substr($pubDate,0,3);

    my $max_hfcCnt =40;
    for ($hfcCnt=1; $hfcCnt<=$max_hfcCnt+1; $hfcCnt++)
    {
        my $pubDate  =ReadingsVal($w, "hfc${hfcCnt}_pubDate","None");
        next if $pubDate eq "None"  &&  $hfcCnt <= $max_hfcCnt;  # beim letzten trotzdem durchlaufen
        my $code      =ReadingsVal($w, "hfc${hfcCnt}_code",0);
        my $condition =ReadingsVal($w, "hfc${hfcCnt}_condition",0);
        my $pressure  =ReadingsVal($w, "hfc${hfcCnt}_pressure",0);
        my $rain      =ReadingsVal($w, "hfc${hfcCnt}_rain3h",0);
        my $cloudCover=ReadingsVal($w, "hfc${hfcCnt}_cloudCover",0);
        my $humidity  =ReadingsVal($w, "hfc${hfcCnt}_humidity",0);
        my $icon      =ReadingsVal($w, "hfc${hfcCnt}_icon",0);
        my $iconAPI   =ReadingsVal($w, "hfc${hfcCnt}_iconAPI",0);
        $iconAPI      =~ s/n/d/; # nur tagesicon
        my $high_c    =ReadingsVal($w, "hfc${hfcCnt}_high_c",0);
        my $low_c     =ReadingsVal($w, "hfc${hfcCnt}_low_c",0);
        my $wind      =ReadingsVal($w, "hfc${hfcCnt}_wind",0);
        my $wind_gust =ReadingsVal($w, "hfc${hfcCnt}_wind_gust",0);
       
        my $day =substr($pubDate,0,3);
        my $date=substr($pubDate,5);

        if ( $day ne $Dday  || $hfcCnt > $max_hfcCnt )
        {
            if ($fcCnt > 0)
            {
                $Dpressure=int($Dpressure/$Dcnt);
                $Dhumidity=int($Dhumidity/$Dcnt);
                $DcloudCover=int($DcloudCover/$Dcnt);
               
                my $m=0; my $v="";
                for my $y (keys %cnt_code) {
                    if ( $cnt_code{$y} > $m )
                    { $m=$cnt_code{$y}; $v=$y; }
                }
                $Dcode=$v;
                #$debug .= "$Dday $Dcode=$m # ";
               
                $m=0; $v="";
                for my $y (keys %cnt_condition) {
                    if ( $cnt_condition{$y} > $m )
                    { $m=$cnt_condition{$y}; $v=$y; }
                }
                $Dcondition=$v;
                #$debug .= "$Dday $Dcondition=$m # \n";
               
                $m=0; $v="";
                for my $y (keys %cnt_icon) {
                    if ( $cnt_icon{$y} > $m )
                    { $m=$cnt_icon{$y}; $v=$y; }
                }
                $Dicon=$v;
               
                $m=0; $v="";
                for my $y (keys %cnt_iconAPI) {
                    if ( $cnt_iconAPI{$y} > $m )
                    { $m=$cnt_iconAPI{$y}; $v=$y; }
                }
                $DiconAPI=$v;
       
               
                $Ddate      =~ s/ \d\d:\d\d//;   

                fhem( "setreading $w fc${fcCnt}_high_c $Dhigh_c; setreading $w fc${fcCnt}_low_c $Dlow_c; setreading $w fc${fcCnt}_icon $Dicon; setreading $w fc${fcCnt}_iconAPI $DiconAPI; setreading $w fc${fcCnt}_code $Dcode; setreading $w fc${fcCnt}_rain $Drain; ");
                fhem( "setreading $w fc${fcCnt}_condition $Dcondition; setreading $w fc${fcCnt}_date $Ddate; setreading $w fc${fcCnt}_day_of_week $Dday; setreading $w fc${fcCnt}_pressure $Dpressure; ");
                fhem( "setreading $w fc${fcCnt}_wind $Dwind; setreading $w fc${fcCnt}_wind_gust $Dwind_gust; setreading $w fc${fcCnt}_cloudCover $DcloudCover; setreading $w fc${fcCnt}_humidity $Dhumidity; ");
            }

            $fcCnt++;
            $Dcnt=1;
            %cnt_code=();
            %cnt_condition=();
            %cnt_icon=();
            %cnt_iconAPI=();

            $Dday       =$day;   
            $Ddate      =$date;
            # # #
            $Dhigh_c    =$high_c;
            $Dlow_c     =$low_c;
            $Dwind_gust =$wind_gust;
            $Dwind      =$wind;
            #
            $Drain      =0;
            $Dhumidity  =0;
            $DcloudCover=0;
            $Dpressure  =0;
        }else{
            $Dcnt       ++;
            # # #
            $Dhigh_c    = $high_c  if ( $high_c > $Dhigh_c );
            $Dlow_c     = $low_c   if ( $low_c < $Dlow_c );
            $Dwind_gust = $wind_gust  if ( $wind_gust > $Dwind_gust );
            $Dwind      = $wind   if ( $wind  > $Dwind  );
        }
         
        $Drain      +=$rain;
        $Dhumidity  +=$humidity;
        $DcloudCover+=$cloudCover;
        $Dpressure  +=$pressure;
       
        my $gewichtung=1;
        $gewichtung = 1.25 if ( $date =~  / 1[0123]:\d\d/ ); # mehr einfluss mittags
        $gewichtung = 0.55 if ( $date =~  / (0[0123]|2[23]):\d\d/ ); # kaum einfluss in der nacht
        $gewichtung = 0.75 if ( $date =~  / (0[45]|2[01]):\d\d/ ); # weniger einfluss in der frueh/abend
        #$debug .= "$date $gewichtung # ";
        $cnt_code{$code} += $gewichtung;
        $cnt_condition{$condition} += $gewichtung;
        $cnt_icon{$icon} += $gewichtung;
        $cnt_iconAPI{$iconAPI} += $gewichtung;
       
        # drucktrend 24h
        $p1=$pressure if ($hfcCnt==1);
        $p2=$pressure if ($hfcCnt==9);

    }

    my $Dp= $p2 - $p1;
    my $pTxt="";
    if ( $Dp > 24 )
  {  $pTxt="stark steigend"; }
    elsif ( $Dp > 6 )
  {  $pTxt="steigend"; }
    elsif ( $Dp > -6 )
  {  $pTxt="gleichbleibend"; }
    elsif ( $Dp > -24 )
  {  $pTxt="fallend"; }
    else
  {  $pTxt="stark fallend"; }

    fhem( "setreading $w pressure_trend_txt $pTxt ");

    return($debug);
}


die Funktion triggere ich mit einem notify
Internals:
   DEF        WetterVorschau:pubDate.* { calcWeather($NAME) }
   FUUID      5c435e5e-f33f-2a7c-40a7-7e6881c2ed2fa3a4
   NAME       n_WetterVorschau
   NOTIFYDEV  WetterVorschau
   NR         1584
   NTFY_ORDER 50-n_WetterVorschau
   REGEXP     WetterVorschau:pubDate.*
   STATE      2023-04-09 17:14:40
   TRIGGERTIME 1681053280.7808
   TYPE       notify
   eventCount 4
   READINGS:
     2023-04-08 08:13:49   state           active
     2023-04-09 17:14:40   triggeredByDev  WetterVorschau
     2023-04-09 17:14:40   triggeredByEvent pubDate: Sun,  9 Apr 2023 17:14
Attributes:
   group      Wetter
   icon       message_attention
   room       Wetter

N3M3SIS

Zitat von: didi-fritz am 09 April 2023, 18:12:29ich habe mir in meiner 99_myUtils.pm eine Funktion "calcWeather" geschrieben, die aus den 3-stündlichen hfc*-daten von Version 2.5 versucht, daily-daten (fc*) zu "errechnen"...
sub calcWeather
{
    my ($w, $rest) = @_;

    my $hfcCnt=0;
    my $fcCnt=0;

    my $Dcnt=0;
    my $Dday="init";
    my $Ddate="";
    my $Dcode="";
    my $Dcondition="";
    my $Dpressure="";
    my $Dhumidity=0;
    my $DcloudCover=0;
    my $Drain=0;
    my $Dhigh_c=0;
    my $Dlow_c=0;
    my $Dicon="";
    my $Dwind=0;
    my $Dwind_gust=0;
    my $p1=0;
    my $p2=0;


    for ($hfcCnt=1; $hfcCnt<=40; $hfcCnt++)
    {
        my $pubDate  =ReadingsVal($w, "hfc${hfcCnt}_pubDate","None");
        next if $pubDate eq "None";
        my $code      =ReadingsVal($w, "hfc${hfcCnt}_code",0);
        my $condition =ReadingsVal($w, "hfc${hfcCnt}_condition",0);
        my $pressure  =ReadingsVal($w, "hfc${hfcCnt}_pressure",0);
        my $rain      =ReadingsVal($w, "hfc${hfcCnt}_rain3h",0);
        my $cloudCover=ReadingsVal($w, "hfc${hfcCnt}_cloudCover",0);
        my $humidity  =ReadingsVal($w, "hfc${hfcCnt}_humidity",0);
        #my $icon      =ReadingsVal($w, "hfc${hfcCnt}_icon",0);
        my $icon      =ReadingsVal($w, "hfc${hfcCnt}_iconAPI",0);
        my $high_c    =ReadingsVal($w, "hfc${hfcCnt}_high_c",0);
        my $low_c    =ReadingsVal($w, "hfc${hfcCnt}_low_c",0);
        my $wind      =ReadingsVal($w, "hfc${hfcCnt}_wind",0);
        my $wind_gust =ReadingsVal($w, "hfc${hfcCnt}_wind_gust",0);
       
        my $day =substr($pubDate,0,3);
        my $date=substr($pubDate,5);

        if ( $day ne $Dday )
        {

            if ($fcCnt > 0)
            {
            $Dpressure=int($Dpressure/$Dcnt);
            $Dhumidity=int($Dhumidity/$Dcnt);
            $DcloudCover=int($DcloudCover/$Dcnt);
            fhem( "setreading $w fc${fcCnt}_high_c $Dhigh_c; setreading $w fc${fcCnt}_low_c $Dlow_c; setreading $w fc${fcCnt}_icon $Dicon; setreading $w fc${fcCnt}_code $Dcode; setreading $w fc${fcCnt}_rain $Drain; ");
            fhem( "setreading $w fc${fcCnt}_condition $Dcondition; setreading $w fc${fcCnt}_date $Ddate; setreading $w fc${fcCnt}_day_of_week $Dday; setreading $w fc${fcCnt}_pressure $Dpressure; ");
            fhem( "setreading $w fc${fcCnt}_wind $Dwind; setreading $w fc${fcCnt}_wind_gust $Dwind_gust; setreading $w fc${fcCnt}_cloudCover $DcloudCover; setreading $w fc${fcCnt}_humidity $Dhumidity; ");
            }

            $fcCnt++;
            $Dcnt=1;

            $Dday      =$day ;
            $Ddate      =$date;
            $Dcode      =$code;
            $Dcondition =$condition;
            $Dpressure  =$pressure;
            $Drain      =$rain;
            $Dhumidity  =$humidity;
            $DcloudCover=$cloudCover;
            $Dicon      =$icon;
            $Dhigh_c    =$high_c;
            $Dlow_c    =$low_c;
            $Dwind_gust = $wind_gust;
            $Dwind      = $wind;

            $p1=$pressure if ($fcCnt==1);
            $p2=$pressure if ($fcCnt==2);

        }else{
            $Dcnt      ++;
            $Dhigh_c    = $high_c  if ( $high_c > $Dhigh_c );
            $Dlow_c    = $low_c  if ( $low_c < $Dlow_c );
            $Drain      +=$rain;
            $Dhumidity  +=$humidity;
            $DcloudCover+=$cloudCover;
            $Dpressure  +=$pressure;
            $Dwind_gust = $wind_gust  if ( $wind_gust > $Dwind_gust );
            $Dwind      = $wind  if ( $wind  > $Dwind  );
            if ( $date =~ /1[123]:00/ )
            {
                $Ddate    =$date;
                $Dcode    =$code;
                $Dcondition=$condition;
                $Dicon    =$icon;

                $p1=$pressure if ($fcCnt==1);
                $p2=$pressure if ($fcCnt==2);
            }
        }

    }

    $Dpressure=int($Dpressure/$Dcnt);
    $Dhumidity=int($Dhumidity/$Dcnt);
    $DcloudCover=int($DcloudCover/$Dcnt);
    fhem( "setreading $w fc${fcCnt}_high_c $Dhigh_c; setreading $w fc${fcCnt}_low_c $Dlow_c; setreading $w fc${fcCnt}_icon $Dicon; setreading $w fc${fcCnt}_code $Dcode; setreading $w fc${fcCnt}_rain $Drain; ");
    fhem( "setreading $w fc${fcCnt}_condition $Dcondition; setreading $w fc${fcCnt}_date $Ddate; setreading $w fc${fcCnt}_day_of_week $Dday; setreading $w fc${fcCnt}_pressure $Dpressure; ");
    fhem( "setreading $w fc${fcCnt}_wind $Dwind; setreading $w fc${fcCnt}_wind_gust $Dwind_gust; setreading $w fc${fcCnt}_cloudCover $DcloudCover; setreading $w fc${fcCnt}_humidity $Dhumidity; ");

    my $Dp= $p2 - $p1;
    my $pTxt="";
    if ( $Dp > 24 )
      {  $pTxt="stark steigend"; }
    elsif ( $Dp > 6 )
      {  $pTxt="steigend"; }
    elsif ( $Dp > -6 )
      {  $pTxt="gleichbleibend"; }
    elsif ( $Dp > -24 )
      {  $pTxt="fallend"; }
    else
      {  $pTxt="stark fallend"; }

    fhem( "setreading $w pressure_trend_txt $pTxt ");

}


die Funktion triggere ich mit einem notify
Internals:
  DEF        WetterVorschau:pubDate.* { calcWeather($NAME) }
  FUUID      5c435e5e-f33f-2a7c-40a7-7e6881c2ed2fa3a4
  NAME      n_WetterVorschau
  NOTIFYDEV  WetterVorschau
  NR        1584
  NTFY_ORDER 50-n_WetterVorschau
  REGEXP    WetterVorschau:pubDate.*
  STATE      2023-04-09 17:14:40
  TRIGGERTIME 1681053280.7808
  TYPE      notify
  eventCount 4
  READINGS:
    2023-04-08 08:13:49  state          active
    2023-04-09 17:14:40  triggeredByDev  WetterVorschau
    2023-04-09 17:14:40  triggeredByEvent pubDate: Sun,  9 Apr 2023 17:14
Attributes:
  group      Wetter
  icon      message_attention
  room      Wetter


@didi-fritz kannst du bitte hier näher drauf eingehen. Wie ich das auch bei mir machen kann.
Der erste Teil 99_myUtils.pm einfügen verstehe ich.
Der Notify Teil macht mir ein wenig Schwierigkeiten was zutun ist.
Danke LG
Raspberry Pi 3 | CC1101 USB-Lite 868Mhz | CUL 433

didi-fritz

"WetterVorschau" ist der Name meines Wetter-Devices vom Type "OpenWeatherMapAPI".

wenn sich nun das Wetter-Device updated wird mein notify getriggert ( WetterVorschau:pubDate.* ) und die Funktion calcWeather($NAME) gestartet

betateilchen

Nur mal interessehalber: Was spricht denn dagegen, einfach die Version 3 in der API zu verwenden?
-----------------------
Formuliere die Aufgabe möglichst einfach und
setze die Lösung richtig um - dann wird es auch funktionieren.
-----------------------
Lesen gefährdet die Unwissenheit!