Skip to content
  • Home
  • Aktuell
  • Tags
  • 0 Ungelesen 0
  • Kategorien
  • Unreplied
  • Beliebt
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Standard: (Kein Skin)
  • Kein Skin
Einklappen
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. Wetterdaten abrufen per API-Call mit dem Javascript Adapter

NEWS

  • UPDATE 31.10.: Amazon Alexa - ioBroker Skill läuft aus ?
    apollon77A
    apollon77
    48
    3
    8.6k

  • Monatsrückblick – September 2025
    BluefoxB
    Bluefox
    13
    1
    2.1k

  • Neues Video "KI im Smart Home" - ioBroker plus n8n
    BluefoxB
    Bluefox
    16
    1
    2.8k

Wetterdaten abrufen per API-Call mit dem Javascript Adapter

Geplant Angeheftet Gesperrt Verschoben Skripten / Logik
42 Beiträge 8 Kommentatoren 3.6k Aufrufe 10 Watching
  • Älteste zuerst
  • Neuste zuerst
  • Meiste Stimmen
Antworten
  • In einem neuen Thema antworten
Anmelden zum Antworten
Dieses Thema wurde gelöscht. Nur Nutzer mit entsprechenden Rechten können es sehen.
  • Ro75R Ro75

    @wendy2702 ja die ersten 1000 pro Tag sind kostenfrei, danach 14 Cent pro 100

    df6e4b6b-6b94-43eb-b4a3-8404742ad55d-image.png

    Ro75.

    wendy2702W Online
    wendy2702W Online
    wendy2702
    schrieb am zuletzt editiert von
    #13

    @ro75 danke für die Erklärung und den screenshot.

    Bitte keine Fragen per PN, die gehören ins Forum!

    Benutzt das Voting rechts unten im Beitrag wenn er euch geholfen hat.

    1 Antwort Letzte Antwort
    0
    • Frederik BussF Frederik Buss

      @itze242 Hast Du die direkte URL schon probiert:

      https://api.openweathermap.org/data/3.0/onecall?lat=50.xxxxx&lon=8.xxxx&appid=XXXXXX&units=metric&lang=de&exclude=minutely
      

      Und natürlich die "XXX" durch die eigenen Werte ersetzen - Länge/Breitengrad und API Key (man muss die One Call Api bestellen)...

      I Offline
      I Offline
      itze242
      schrieb am zuletzt editiert von
      #14

      @frederik-buss Ich bin zu doof dafür.
      Der Aufruf mit der URL klappt jetzt und ich sehe die Daten im Browser.

      Nur iobroker will nicht.
      Ich habe die selben infos (lat, long, id) im skript und in der url.
      Im javascript adapter ist axios Addtional npm Modul eingetragen.
      Beim starten der instanz kommt im log zu Thema axios:
      Screenshot 2025-07-27 154249.jpg

      Ich verstehe es nicht :-(

      Frederik BussF 1 Antwort Letzte Antwort
      0
      • I itze242

        @frederik-buss Ich bin zu doof dafür.
        Der Aufruf mit der URL klappt jetzt und ich sehe die Daten im Browser.

        Nur iobroker will nicht.
        Ich habe die selben infos (lat, long, id) im skript und in der url.
        Im javascript adapter ist axios Addtional npm Modul eingetragen.
        Beim starten der instanz kommt im log zu Thema axios:
        Screenshot 2025-07-27 154249.jpg

        Ich verstehe es nicht :-(

        Frederik BussF Offline
        Frederik BussF Offline
        Frederik Buss
        schrieb am zuletzt editiert von
        #15

        @itze242 Da kann ich Dir leider auch nicht weiter helfen, mit dem Axios Modul kenne ich mich Null aus... Sorry.

        I 1 Antwort Letzte Antwort
        0
        • Frederik BussF Frederik Buss

          @itze242 Da kann ich Dir leider auch nicht weiter helfen, mit dem Axios Modul kenne ich mich Null aus... Sorry.

          I Offline
          I Offline
          itze242
          schrieb am zuletzt editiert von
          #16

          @frederik-buss

          Herrjeh, ich bin so doof :-)
          Habe die erste Zeile des Skripts gelöscht und wundere mich, dass axios nicht funktioniert.
          Immerhin habe ich mich das erste mal ein wenig mit js beschäftigt.

          Nun kommen die Daten rein.

          Danke nochmal.

          1 Antwort Letzte Antwort
          0
          • Ro75R Offline
            Ro75R Offline
            Ro75
            schrieb am zuletzt editiert von Ro75
            #17

            So ich habe das Skript noch einmal modifiziert. Es beinhaltet jetzt auch eine Zähler, damit die freien API-Calls überwacht werden und es somit nicht kostenpflichtig werden kann. Zusätzlich habe ich noch die Zeitzone implementiert. Aüßerdem werden bestimmte Zahlenwerte (Niederschlag, Temperaturen) auf eine Nachkommstelle gerundet. Die Wingeschwindigkeiten werden jetzt in km/h gespeichert und nicht mehr in m/s. Von daher ggfs. die alten Datenpunkte nochmal löschen und automatisch neu anlegen lassen.

            Weiterhin habe ich die Icons von Accuweather mit den Werten von OpenWeatherMap gemappt. Der Pfad für die Icons ist auf VIS 1 voreingestellt, kann aber angepasst werden.

            Hier die Icons: wettericon.zip

            const axios = require('axios'); // Stelle sicher, dass axios installiert ist
             
            const apiUrl = "https://api.openweathermap.org/data/3.0/onecall";
            const apiParams = {
                lat: 50.xxxxxxxxx, 
                lon: 14.xxxxxxxxxxxx,
                appid: "xxxxxxxxxxxxxxxxxxxxxxxxxx",
                units: "metric",
                lang: "de",
                timezone: "Europe/Berlin",
                exclude: "minutely,hourly"
            };
             
            const basePath = "0_userdata.0.Wetter.Openweathermap."; //kann angepasst werden
            const baseVisPath = 'http://192.168.10.99:8082/vis.0/wetter/'; //muss angepasst werden
            
            createState(`${basePath}APICalls`, 0, {name: 'APICalls' ,type: 'number', read: true, write: false});
            
            // Funktion, um Wetterdaten abzurufen
            async function fetchWeatherData() {
                if (getState(`${basePath}APICalls`).val <= 990) {
                    try {
                        const response = await axios.get(apiUrl, { params: apiParams });
                        const weatherData = response.data;
                        const date = new Date(weatherData.current.dt * 1000);
            
                        //Zähler aktualisieren - maximal 1000 kostenfrei pro Tag
                        setState(`${basePath}APICalls`, getState(`${basePath}APICalls`).val + 1, true);
            
                        // DP erstellen und aktuelle Daten speichern
                        createAndSetState(`${basePath}current.date`, date.toLocaleDateString('de-DE', {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: 'Europe/Berlin'}), "string");
                        createAndSetState(`${basePath}current.day`, date.toLocaleDateString('de-DE', { weekday: 'long' }), "string");
            
                        createAndSetState(`${basePath}current.temperatur`,  DATARound(weatherData.current.temp), "number", "°C");
                        createAndSetState(`${basePath}current.temperatur_feels`,  DATARound(weatherData.current.feels_like) || 0, "number", "°C");
                        createAndSetState(`${basePath}current.humidity`, weatherData.current.humidity, "number", "%");
                        createAndSetState(`${basePath}current.weather`, weatherData.current.weather[0].description, "string");
                        createAndSetState(`${basePath}current.wind_speed`, DATARound(weatherData.current.wind_speed * 3.6), "number", "km/h");
                        createAndSetState(`${basePath}current.wind_gust`, DATARound(weatherData.current.wind_gust * 3.6) || 0, "number", "km/h");
                        createAndSetState(`${basePath}current.wind_deg`, weatherData.current.wind_deg, "number", "°");
                        createAndSetState(`${basePath}current.wind_direction`, getWindDirection(weatherData.current.wind_deg), "string");
                        createAndSetState(`${basePath}current.uv-index`, Math.round(weatherData.current.uvi) || 0, "number");
                        createAndSetState(`${basePath}current.visibility`, weatherData.current.visibility || 0, "number", "m");
                        createAndSetState(`${basePath}current.icon`, weatherData.current.weather[0].icon, "string");
                        createAndSetState(`${basePath}current.icon_id`, weatherData.current.weather[0].id, "number");
                        createAndSetState(`${basePath}current.icon_url`, getWeatherIcon(weatherData.current.weather[0].id, getState('javascript.0.variables.isDayTime').val), "string");
                        createAndSetState(`${basePath}current.clouds`, weatherData.current.clouds, "number", "%");
                        const isRaining = weatherData.current.weather[0].description.toLowerCase().includes("rain");
                        createAndSetState(`${basePath}current.raining`, isRaining, "boolean");
                
                        // DP erstellen und tägliche Daten speichern
                        weatherData.daily.forEach((day, index) => {
                            const date = new Date(day.dt * 1000);
                            createAndSetState(`${basePath}daily.${index}.date`, date.toLocaleDateString('de-DE', {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: 'Europe/Berlin'}), "string");
                            createAndSetState(`${basePath}daily.${index}.day`, date.toLocaleDateString('de-DE', { weekday: 'long' }), "string");
            
                            createAndSetState(`${basePath}daily.${index}.temperatur_min`, DATARound(day.temp.min), "number", "°C");
                            createAndSetState(`${basePath}daily.${index}.temperatur_max`, DATARound(day.temp.max), "number", "°C");
                            createAndSetState(`${basePath}daily.${index}.probability`, day.pop*100, "number", "%");
                            createAndSetState(`${basePath}daily.${index}.rain`, day.rain !== undefined ? DATARound(day.rain) : 0, "number", "mm");
                            createAndSetState(`${basePath}daily.${index}.snow`, day.snow !== undefined ? DATARound(day.snow) : 0, "number", "mm");
                            createAndSetState(`${basePath}daily.${index}.icon`, day.weather[0].icon, "string");
                            createAndSetState(`${basePath}daily.${index}.icon_id`, day.weather[0].id, "number");
                            createAndSetState(`${basePath}daily.${index}.icon_url`, getWeatherIcon(day.weather[0].id, true), "string");
                            createAndSetState(`${basePath}daily.${index}.weather`, day.weather[0].description, "string");
                            createAndSetState(`${basePath}daily.${index}.wind_speed`, DATARound(day.wind_speed * 3.6), "number", "km/h");
                            createAndSetState(`${basePath}daily.${index}.wind_gust`, DATARound(day.wind_gust * 3.6) || 0, "number", "km/h");
                            createAndSetState(`${basePath}daily.${index}.wind_deg`, day.wind_deg, "number", "°");
                            createAndSetState(`${basePath}daily.${index}.wind_direction`, getWindDirection(day.wind_deg), "string");
                            createAndSetState(`${basePath}daily.${index}.clouds`, day.clouds || 0, "number", "%");
                            createAndSetState(`${basePath}daily.${index}.uv-index`, Math.round(day.uvi) || 0, "number");
                        });
                    } catch (error) {
                        // Logge einen Fehler, wenn die API nicht erreichbar ist
                        console.error("Fehler beim Abrufen der Wetterdaten: ", error.message);
                    }
                }
            }
            
            // Funktion, um die SVG von Accuweather OpenWeatherMap zuzuordnen - TAG, NACHT wird berücksichtigt
            function getWeatherIcon(vIcon_ID,bIsDay) {
                var zIcon = 0;
                if (bIsDay == true) {
                    //Tag-Icon
                    if (vIcon_ID == 800) {
                        zIcon = 1;
                    } else if (vIcon_ID == 801) {
                        zIcon = 2;
                    } else if (vIcon_ID == 802) {
                        zIcon = 3;
                    } else if (vIcon_ID == 803) {
                        zIcon = 4;
                    } else if (vIcon_ID == 804) {
                        zIcon = 6;
                    } else if (vIcon_ID == 500 || vIcon_ID == 501) {
                        zIcon = 14;
                    } else if (vIcon_ID == 502 || vIcon_ID == 503) {
                        zIcon = 13;
                    } else if (vIcon_ID == 314 || vIcon_ID == 321 || vIcon_ID == 504 || vIcon_ID == 522 || vIcon_ID == 531) {
                        zIcon = 18;
                    } else if (vIcon_ID == 511) {
                        zIcon = 26;
                    } else if (vIcon_ID == 300 || vIcon_ID == 301 || vIcon_ID == 302 || vIcon_ID == 310 || vIcon_ID == 311 || vIcon_ID == 312 || vIcon_ID == 313 || vIcon_ID == 520 || vIcon_ID == 521) {
                        zIcon = 12;
                    } else if (vIcon_ID == 200 || vIcon_ID == 201) {
                        zIcon = 17;
                    } else if (vIcon_ID == 202 || vIcon_ID == 210 || vIcon_ID == 230 || vIcon_ID == 231) {
                        zIcon = 16;
                    } else if (vIcon_ID == 211 || vIcon_ID == 212 || vIcon_ID == 221 || vIcon_ID == 232) {
                        zIcon = 15;
                    } else if (vIcon_ID == 600) {
                        zIcon = 21;
                    } else if (vIcon_ID == 601) {
                        zIcon = 20;
                    } else if (vIcon_ID == 602) {
                        zIcon = 23;
                    } else if (vIcon_ID == 611 || vIcon_ID == 612 || vIcon_ID == 613 || vIcon_ID == 615 || vIcon_ID == 616) {
                        zIcon = 29;
                    } else if (vIcon_ID == 620 || vIcon_ID == 621) {
                        zIcon = 19;
                    } else if (vIcon_ID == 622) {
                        zIcon = 22;
                    } else if (vIcon_ID == 700 || vIcon_ID == 711 || vIcon_ID == 721 || vIcon_ID == 731 || vIcon_ID == 741 || vIcon_ID == 751 || vIcon_ID == 761 || vIcon_ID == 762 || vIcon_ID == 771 || vIcon_ID == 772) {
                        zIcon = 32;
                    }
                } else {
                    //Nacht-Icon
                    if (vIcon_ID == 800) {
                        zIcon = 33;
                    } else if (vIcon_ID == 801) {
                        zIcon = 34;
                    } else if (vIcon_ID == 802) {
                        zIcon = 35;
                    } else if (vIcon_ID == 803) {
                        zIcon = 36;
                    } else if (vIcon_ID == 804) {
                        zIcon = 38;
                    } else if (vIcon_ID == 500 || vIcon_ID == 501) {
                        zIcon = 39;
                    } else if (vIcon_ID == 502 || vIcon_ID == 503) {
                        zIcon = 40;
                    } else if (vIcon_ID == 314 || vIcon_ID == 321 || vIcon_ID == 504 || vIcon_ID == 522 || vIcon_ID == 531) {
                        zIcon = 18;
                    } else if (vIcon_ID == 511) {
                        zIcon = 26;
                    } else if (vIcon_ID == 300 || vIcon_ID == 301 || vIcon_ID == 302 || vIcon_ID == 310 || vIcon_ID == 311 || vIcon_ID == 312 || vIcon_ID == 313 || vIcon_ID == 520 || vIcon_ID == 521) {
                        zIcon = 12;
                    } else if (vIcon_ID == 200 || vIcon_ID == 201) {
                        zIcon = 41;
                    } else if (vIcon_ID == 202 || vIcon_ID == 210 || vIcon_ID == 230 || vIcon_ID == 231) {
                        zIcon = 42;
                    } else if (vIcon_ID == 211 || vIcon_ID == 212 || vIcon_ID == 221 || vIcon_ID == 232) {
                        zIcon = 15;
                    } else if (vIcon_ID == 600) {
                        zIcon = 43;
                    } else if (vIcon_ID == 601) {
                        zIcon = 43;
                    } else if (vIcon_ID == 602) {
                        zIcon = 44;
                    } else if (vIcon_ID == 611 || vIcon_ID == 612 || vIcon_ID == 613 || vIcon_ID == 615 || vIcon_ID == 616) {
                        zIcon = 29;
                    } else if (vIcon_ID == 620 || vIcon_ID == 621) {
                        zIcon = 19;
                    } else if (vIcon_ID == 622) {
                        zIcon = 22;
                    } else if (vIcon_ID == 700 || vIcon_ID == 711 || vIcon_ID == 721 || vIcon_ID == 731 || vIcon_ID == 741 || vIcon_ID == 751 || vIcon_ID == 761 || vIcon_ID == 762 || vIcon_ID == 771 || vIcon_ID == 772) {
                        zIcon = 32;
                    }
                }
                return baseVisPath + zIcon + '.svg';
            }
            
            // Funktion, Runden eine Nachkommastelle
            function DATARound(vValue) {
                return Math.round(vValue * 10) / 10;
            }
            
            // Funktion, um Windrichtung zu bestimmen
            function getWindDirection(degrees) {
                const directions = [
                'N', 'NNO', 'NO', 'ONO',
                'O', 'OSO', 'SO', 'SSO',
                'S', 'SSW', 'SW', 'WSW',
                'W', 'WNW', 'NW', 'NNW'
                ];
            
                const index = Math.round(degrees / 22.5) % 16;
                return directions[index];
            }
            
            // Funktion, um Datenpunkte zu erstellen und zu setzen
            function createAndSetState(id, value, type, unit = "") {
                if (!existsState(id)) {
                    createState(id, value, {
                        type: type,
                        unit: unit,
                        read: true,
                        write: false
                    });
                }
                setState(id, value, true);
            }
             
            // Scheduler: Alle 5 Minuten ausführen
            schedule('35 */5 * * * *', function () {
                fetchWeatherData();
            });
            
            schedule('20 0 0 * * *', function () {
                //Reset Zähler
                setState(`${basePath}APICalls`, 0, true);
            });
            
            

            Ro75.

            SERVER = Beelink U59 16GB DDR4 RAM 512GB SSD, FB 7490, FritzDect 200+301+440, ConBee II, Zigbee Aqara Sensoren + NOUS A1Z, NOUS A1T, Philips Hue ** ioBroker, REDIS, influxdb2, Grafana, PiHole, Plex-Mediaserver, paperless-ngx (Docker), MariaDB + phpmyadmin *** VIS-Runtime = Intel NUC 8GB RAM 128GB SSD + 24" Touchscreen

            L Frederik BussF 2 Antworten Letzte Antwort
            0
            • Ro75R Ro75

              So ich habe das Skript noch einmal modifiziert. Es beinhaltet jetzt auch eine Zähler, damit die freien API-Calls überwacht werden und es somit nicht kostenpflichtig werden kann. Zusätzlich habe ich noch die Zeitzone implementiert. Aüßerdem werden bestimmte Zahlenwerte (Niederschlag, Temperaturen) auf eine Nachkommstelle gerundet. Die Wingeschwindigkeiten werden jetzt in km/h gespeichert und nicht mehr in m/s. Von daher ggfs. die alten Datenpunkte nochmal löschen und automatisch neu anlegen lassen.

              Weiterhin habe ich die Icons von Accuweather mit den Werten von OpenWeatherMap gemappt. Der Pfad für die Icons ist auf VIS 1 voreingestellt, kann aber angepasst werden.

              Hier die Icons: wettericon.zip

              const axios = require('axios'); // Stelle sicher, dass axios installiert ist
               
              const apiUrl = "https://api.openweathermap.org/data/3.0/onecall";
              const apiParams = {
                  lat: 50.xxxxxxxxx, 
                  lon: 14.xxxxxxxxxxxx,
                  appid: "xxxxxxxxxxxxxxxxxxxxxxxxxx",
                  units: "metric",
                  lang: "de",
                  timezone: "Europe/Berlin",
                  exclude: "minutely,hourly"
              };
               
              const basePath = "0_userdata.0.Wetter.Openweathermap."; //kann angepasst werden
              const baseVisPath = 'http://192.168.10.99:8082/vis.0/wetter/'; //muss angepasst werden
              
              createState(`${basePath}APICalls`, 0, {name: 'APICalls' ,type: 'number', read: true, write: false});
              
              // Funktion, um Wetterdaten abzurufen
              async function fetchWeatherData() {
                  if (getState(`${basePath}APICalls`).val <= 990) {
                      try {
                          const response = await axios.get(apiUrl, { params: apiParams });
                          const weatherData = response.data;
                          const date = new Date(weatherData.current.dt * 1000);
              
                          //Zähler aktualisieren - maximal 1000 kostenfrei pro Tag
                          setState(`${basePath}APICalls`, getState(`${basePath}APICalls`).val + 1, true);
              
                          // DP erstellen und aktuelle Daten speichern
                          createAndSetState(`${basePath}current.date`, date.toLocaleDateString('de-DE', {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: 'Europe/Berlin'}), "string");
                          createAndSetState(`${basePath}current.day`, date.toLocaleDateString('de-DE', { weekday: 'long' }), "string");
              
                          createAndSetState(`${basePath}current.temperatur`,  DATARound(weatherData.current.temp), "number", "°C");
                          createAndSetState(`${basePath}current.temperatur_feels`,  DATARound(weatherData.current.feels_like) || 0, "number", "°C");
                          createAndSetState(`${basePath}current.humidity`, weatherData.current.humidity, "number", "%");
                          createAndSetState(`${basePath}current.weather`, weatherData.current.weather[0].description, "string");
                          createAndSetState(`${basePath}current.wind_speed`, DATARound(weatherData.current.wind_speed * 3.6), "number", "km/h");
                          createAndSetState(`${basePath}current.wind_gust`, DATARound(weatherData.current.wind_gust * 3.6) || 0, "number", "km/h");
                          createAndSetState(`${basePath}current.wind_deg`, weatherData.current.wind_deg, "number", "°");
                          createAndSetState(`${basePath}current.wind_direction`, getWindDirection(weatherData.current.wind_deg), "string");
                          createAndSetState(`${basePath}current.uv-index`, Math.round(weatherData.current.uvi) || 0, "number");
                          createAndSetState(`${basePath}current.visibility`, weatherData.current.visibility || 0, "number", "m");
                          createAndSetState(`${basePath}current.icon`, weatherData.current.weather[0].icon, "string");
                          createAndSetState(`${basePath}current.icon_id`, weatherData.current.weather[0].id, "number");
                          createAndSetState(`${basePath}current.icon_url`, getWeatherIcon(weatherData.current.weather[0].id, getState('javascript.0.variables.isDayTime').val), "string");
                          createAndSetState(`${basePath}current.clouds`, weatherData.current.clouds, "number", "%");
                          const isRaining = weatherData.current.weather[0].description.toLowerCase().includes("rain");
                          createAndSetState(`${basePath}current.raining`, isRaining, "boolean");
                  
                          // DP erstellen und tägliche Daten speichern
                          weatherData.daily.forEach((day, index) => {
                              const date = new Date(day.dt * 1000);
                              createAndSetState(`${basePath}daily.${index}.date`, date.toLocaleDateString('de-DE', {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: 'Europe/Berlin'}), "string");
                              createAndSetState(`${basePath}daily.${index}.day`, date.toLocaleDateString('de-DE', { weekday: 'long' }), "string");
              
                              createAndSetState(`${basePath}daily.${index}.temperatur_min`, DATARound(day.temp.min), "number", "°C");
                              createAndSetState(`${basePath}daily.${index}.temperatur_max`, DATARound(day.temp.max), "number", "°C");
                              createAndSetState(`${basePath}daily.${index}.probability`, day.pop*100, "number", "%");
                              createAndSetState(`${basePath}daily.${index}.rain`, day.rain !== undefined ? DATARound(day.rain) : 0, "number", "mm");
                              createAndSetState(`${basePath}daily.${index}.snow`, day.snow !== undefined ? DATARound(day.snow) : 0, "number", "mm");
                              createAndSetState(`${basePath}daily.${index}.icon`, day.weather[0].icon, "string");
                              createAndSetState(`${basePath}daily.${index}.icon_id`, day.weather[0].id, "number");
                              createAndSetState(`${basePath}daily.${index}.icon_url`, getWeatherIcon(day.weather[0].id, true), "string");
                              createAndSetState(`${basePath}daily.${index}.weather`, day.weather[0].description, "string");
                              createAndSetState(`${basePath}daily.${index}.wind_speed`, DATARound(day.wind_speed * 3.6), "number", "km/h");
                              createAndSetState(`${basePath}daily.${index}.wind_gust`, DATARound(day.wind_gust * 3.6) || 0, "number", "km/h");
                              createAndSetState(`${basePath}daily.${index}.wind_deg`, day.wind_deg, "number", "°");
                              createAndSetState(`${basePath}daily.${index}.wind_direction`, getWindDirection(day.wind_deg), "string");
                              createAndSetState(`${basePath}daily.${index}.clouds`, day.clouds || 0, "number", "%");
                              createAndSetState(`${basePath}daily.${index}.uv-index`, Math.round(day.uvi) || 0, "number");
                          });
                      } catch (error) {
                          // Logge einen Fehler, wenn die API nicht erreichbar ist
                          console.error("Fehler beim Abrufen der Wetterdaten: ", error.message);
                      }
                  }
              }
              
              // Funktion, um die SVG von Accuweather OpenWeatherMap zuzuordnen - TAG, NACHT wird berücksichtigt
              function getWeatherIcon(vIcon_ID,bIsDay) {
                  var zIcon = 0;
                  if (bIsDay == true) {
                      //Tag-Icon
                      if (vIcon_ID == 800) {
                          zIcon = 1;
                      } else if (vIcon_ID == 801) {
                          zIcon = 2;
                      } else if (vIcon_ID == 802) {
                          zIcon = 3;
                      } else if (vIcon_ID == 803) {
                          zIcon = 4;
                      } else if (vIcon_ID == 804) {
                          zIcon = 6;
                      } else if (vIcon_ID == 500 || vIcon_ID == 501) {
                          zIcon = 14;
                      } else if (vIcon_ID == 502 || vIcon_ID == 503) {
                          zIcon = 13;
                      } else if (vIcon_ID == 314 || vIcon_ID == 321 || vIcon_ID == 504 || vIcon_ID == 522 || vIcon_ID == 531) {
                          zIcon = 18;
                      } else if (vIcon_ID == 511) {
                          zIcon = 26;
                      } else if (vIcon_ID == 300 || vIcon_ID == 301 || vIcon_ID == 302 || vIcon_ID == 310 || vIcon_ID == 311 || vIcon_ID == 312 || vIcon_ID == 313 || vIcon_ID == 520 || vIcon_ID == 521) {
                          zIcon = 12;
                      } else if (vIcon_ID == 200 || vIcon_ID == 201) {
                          zIcon = 17;
                      } else if (vIcon_ID == 202 || vIcon_ID == 210 || vIcon_ID == 230 || vIcon_ID == 231) {
                          zIcon = 16;
                      } else if (vIcon_ID == 211 || vIcon_ID == 212 || vIcon_ID == 221 || vIcon_ID == 232) {
                          zIcon = 15;
                      } else if (vIcon_ID == 600) {
                          zIcon = 21;
                      } else if (vIcon_ID == 601) {
                          zIcon = 20;
                      } else if (vIcon_ID == 602) {
                          zIcon = 23;
                      } else if (vIcon_ID == 611 || vIcon_ID == 612 || vIcon_ID == 613 || vIcon_ID == 615 || vIcon_ID == 616) {
                          zIcon = 29;
                      } else if (vIcon_ID == 620 || vIcon_ID == 621) {
                          zIcon = 19;
                      } else if (vIcon_ID == 622) {
                          zIcon = 22;
                      } else if (vIcon_ID == 700 || vIcon_ID == 711 || vIcon_ID == 721 || vIcon_ID == 731 || vIcon_ID == 741 || vIcon_ID == 751 || vIcon_ID == 761 || vIcon_ID == 762 || vIcon_ID == 771 || vIcon_ID == 772) {
                          zIcon = 32;
                      }
                  } else {
                      //Nacht-Icon
                      if (vIcon_ID == 800) {
                          zIcon = 33;
                      } else if (vIcon_ID == 801) {
                          zIcon = 34;
                      } else if (vIcon_ID == 802) {
                          zIcon = 35;
                      } else if (vIcon_ID == 803) {
                          zIcon = 36;
                      } else if (vIcon_ID == 804) {
                          zIcon = 38;
                      } else if (vIcon_ID == 500 || vIcon_ID == 501) {
                          zIcon = 39;
                      } else if (vIcon_ID == 502 || vIcon_ID == 503) {
                          zIcon = 40;
                      } else if (vIcon_ID == 314 || vIcon_ID == 321 || vIcon_ID == 504 || vIcon_ID == 522 || vIcon_ID == 531) {
                          zIcon = 18;
                      } else if (vIcon_ID == 511) {
                          zIcon = 26;
                      } else if (vIcon_ID == 300 || vIcon_ID == 301 || vIcon_ID == 302 || vIcon_ID == 310 || vIcon_ID == 311 || vIcon_ID == 312 || vIcon_ID == 313 || vIcon_ID == 520 || vIcon_ID == 521) {
                          zIcon = 12;
                      } else if (vIcon_ID == 200 || vIcon_ID == 201) {
                          zIcon = 41;
                      } else if (vIcon_ID == 202 || vIcon_ID == 210 || vIcon_ID == 230 || vIcon_ID == 231) {
                          zIcon = 42;
                      } else if (vIcon_ID == 211 || vIcon_ID == 212 || vIcon_ID == 221 || vIcon_ID == 232) {
                          zIcon = 15;
                      } else if (vIcon_ID == 600) {
                          zIcon = 43;
                      } else if (vIcon_ID == 601) {
                          zIcon = 43;
                      } else if (vIcon_ID == 602) {
                          zIcon = 44;
                      } else if (vIcon_ID == 611 || vIcon_ID == 612 || vIcon_ID == 613 || vIcon_ID == 615 || vIcon_ID == 616) {
                          zIcon = 29;
                      } else if (vIcon_ID == 620 || vIcon_ID == 621) {
                          zIcon = 19;
                      } else if (vIcon_ID == 622) {
                          zIcon = 22;
                      } else if (vIcon_ID == 700 || vIcon_ID == 711 || vIcon_ID == 721 || vIcon_ID == 731 || vIcon_ID == 741 || vIcon_ID == 751 || vIcon_ID == 761 || vIcon_ID == 762 || vIcon_ID == 771 || vIcon_ID == 772) {
                          zIcon = 32;
                      }
                  }
                  return baseVisPath + zIcon + '.svg';
              }
              
              // Funktion, Runden eine Nachkommastelle
              function DATARound(vValue) {
                  return Math.round(vValue * 10) / 10;
              }
              
              // Funktion, um Windrichtung zu bestimmen
              function getWindDirection(degrees) {
                  const directions = [
                  'N', 'NNO', 'NO', 'ONO',
                  'O', 'OSO', 'SO', 'SSO',
                  'S', 'SSW', 'SW', 'WSW',
                  'W', 'WNW', 'NW', 'NNW'
                  ];
              
                  const index = Math.round(degrees / 22.5) % 16;
                  return directions[index];
              }
              
              // Funktion, um Datenpunkte zu erstellen und zu setzen
              function createAndSetState(id, value, type, unit = "") {
                  if (!existsState(id)) {
                      createState(id, value, {
                          type: type,
                          unit: unit,
                          read: true,
                          write: false
                      });
                  }
                  setState(id, value, true);
              }
               
              // Scheduler: Alle 5 Minuten ausführen
              schedule('35 */5 * * * *', function () {
                  fetchWeatherData();
              });
              
              schedule('20 0 0 * * *', function () {
                  //Reset Zähler
                  setState(`${basePath}APICalls`, 0, true);
              });
              
              

              Ro75.

              L Offline
              L Offline
              loverz
              schrieb am zuletzt editiert von
              #18

              @ro75 es wäre cool, wenn ein Entwickler hier einen neuen Adapter basteln könnte.

              1 Antwort Letzte Antwort
              0
              • T Nicht stören
                T Nicht stören
                ticaki
                schrieb am zuletzt editiert von
                #19

                Da es so aussieht als wenn bluefox den openweather adapter nach typescript portiert, könnte man da auch ne feature request erstellen.

                Weather-Warnings Espresense NSPanel-Lovelace-ui Tagesschau

                Spenden

                wendy2702W 1 Antwort Letzte Antwort
                0
                • Ro75R Ro75

                  So ich habe das Skript noch einmal modifiziert. Es beinhaltet jetzt auch eine Zähler, damit die freien API-Calls überwacht werden und es somit nicht kostenpflichtig werden kann. Zusätzlich habe ich noch die Zeitzone implementiert. Aüßerdem werden bestimmte Zahlenwerte (Niederschlag, Temperaturen) auf eine Nachkommstelle gerundet. Die Wingeschwindigkeiten werden jetzt in km/h gespeichert und nicht mehr in m/s. Von daher ggfs. die alten Datenpunkte nochmal löschen und automatisch neu anlegen lassen.

                  Weiterhin habe ich die Icons von Accuweather mit den Werten von OpenWeatherMap gemappt. Der Pfad für die Icons ist auf VIS 1 voreingestellt, kann aber angepasst werden.

                  Hier die Icons: wettericon.zip

                  const axios = require('axios'); // Stelle sicher, dass axios installiert ist
                   
                  const apiUrl = "https://api.openweathermap.org/data/3.0/onecall";
                  const apiParams = {
                      lat: 50.xxxxxxxxx, 
                      lon: 14.xxxxxxxxxxxx,
                      appid: "xxxxxxxxxxxxxxxxxxxxxxxxxx",
                      units: "metric",
                      lang: "de",
                      timezone: "Europe/Berlin",
                      exclude: "minutely,hourly"
                  };
                   
                  const basePath = "0_userdata.0.Wetter.Openweathermap."; //kann angepasst werden
                  const baseVisPath = 'http://192.168.10.99:8082/vis.0/wetter/'; //muss angepasst werden
                  
                  createState(`${basePath}APICalls`, 0, {name: 'APICalls' ,type: 'number', read: true, write: false});
                  
                  // Funktion, um Wetterdaten abzurufen
                  async function fetchWeatherData() {
                      if (getState(`${basePath}APICalls`).val <= 990) {
                          try {
                              const response = await axios.get(apiUrl, { params: apiParams });
                              const weatherData = response.data;
                              const date = new Date(weatherData.current.dt * 1000);
                  
                              //Zähler aktualisieren - maximal 1000 kostenfrei pro Tag
                              setState(`${basePath}APICalls`, getState(`${basePath}APICalls`).val + 1, true);
                  
                              // DP erstellen und aktuelle Daten speichern
                              createAndSetState(`${basePath}current.date`, date.toLocaleDateString('de-DE', {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: 'Europe/Berlin'}), "string");
                              createAndSetState(`${basePath}current.day`, date.toLocaleDateString('de-DE', { weekday: 'long' }), "string");
                  
                              createAndSetState(`${basePath}current.temperatur`,  DATARound(weatherData.current.temp), "number", "°C");
                              createAndSetState(`${basePath}current.temperatur_feels`,  DATARound(weatherData.current.feels_like) || 0, "number", "°C");
                              createAndSetState(`${basePath}current.humidity`, weatherData.current.humidity, "number", "%");
                              createAndSetState(`${basePath}current.weather`, weatherData.current.weather[0].description, "string");
                              createAndSetState(`${basePath}current.wind_speed`, DATARound(weatherData.current.wind_speed * 3.6), "number", "km/h");
                              createAndSetState(`${basePath}current.wind_gust`, DATARound(weatherData.current.wind_gust * 3.6) || 0, "number", "km/h");
                              createAndSetState(`${basePath}current.wind_deg`, weatherData.current.wind_deg, "number", "°");
                              createAndSetState(`${basePath}current.wind_direction`, getWindDirection(weatherData.current.wind_deg), "string");
                              createAndSetState(`${basePath}current.uv-index`, Math.round(weatherData.current.uvi) || 0, "number");
                              createAndSetState(`${basePath}current.visibility`, weatherData.current.visibility || 0, "number", "m");
                              createAndSetState(`${basePath}current.icon`, weatherData.current.weather[0].icon, "string");
                              createAndSetState(`${basePath}current.icon_id`, weatherData.current.weather[0].id, "number");
                              createAndSetState(`${basePath}current.icon_url`, getWeatherIcon(weatherData.current.weather[0].id, getState('javascript.0.variables.isDayTime').val), "string");
                              createAndSetState(`${basePath}current.clouds`, weatherData.current.clouds, "number", "%");
                              const isRaining = weatherData.current.weather[0].description.toLowerCase().includes("rain");
                              createAndSetState(`${basePath}current.raining`, isRaining, "boolean");
                      
                              // DP erstellen und tägliche Daten speichern
                              weatherData.daily.forEach((day, index) => {
                                  const date = new Date(day.dt * 1000);
                                  createAndSetState(`${basePath}daily.${index}.date`, date.toLocaleDateString('de-DE', {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: 'Europe/Berlin'}), "string");
                                  createAndSetState(`${basePath}daily.${index}.day`, date.toLocaleDateString('de-DE', { weekday: 'long' }), "string");
                  
                                  createAndSetState(`${basePath}daily.${index}.temperatur_min`, DATARound(day.temp.min), "number", "°C");
                                  createAndSetState(`${basePath}daily.${index}.temperatur_max`, DATARound(day.temp.max), "number", "°C");
                                  createAndSetState(`${basePath}daily.${index}.probability`, day.pop*100, "number", "%");
                                  createAndSetState(`${basePath}daily.${index}.rain`, day.rain !== undefined ? DATARound(day.rain) : 0, "number", "mm");
                                  createAndSetState(`${basePath}daily.${index}.snow`, day.snow !== undefined ? DATARound(day.snow) : 0, "number", "mm");
                                  createAndSetState(`${basePath}daily.${index}.icon`, day.weather[0].icon, "string");
                                  createAndSetState(`${basePath}daily.${index}.icon_id`, day.weather[0].id, "number");
                                  createAndSetState(`${basePath}daily.${index}.icon_url`, getWeatherIcon(day.weather[0].id, true), "string");
                                  createAndSetState(`${basePath}daily.${index}.weather`, day.weather[0].description, "string");
                                  createAndSetState(`${basePath}daily.${index}.wind_speed`, DATARound(day.wind_speed * 3.6), "number", "km/h");
                                  createAndSetState(`${basePath}daily.${index}.wind_gust`, DATARound(day.wind_gust * 3.6) || 0, "number", "km/h");
                                  createAndSetState(`${basePath}daily.${index}.wind_deg`, day.wind_deg, "number", "°");
                                  createAndSetState(`${basePath}daily.${index}.wind_direction`, getWindDirection(day.wind_deg), "string");
                                  createAndSetState(`${basePath}daily.${index}.clouds`, day.clouds || 0, "number", "%");
                                  createAndSetState(`${basePath}daily.${index}.uv-index`, Math.round(day.uvi) || 0, "number");
                              });
                          } catch (error) {
                              // Logge einen Fehler, wenn die API nicht erreichbar ist
                              console.error("Fehler beim Abrufen der Wetterdaten: ", error.message);
                          }
                      }
                  }
                  
                  // Funktion, um die SVG von Accuweather OpenWeatherMap zuzuordnen - TAG, NACHT wird berücksichtigt
                  function getWeatherIcon(vIcon_ID,bIsDay) {
                      var zIcon = 0;
                      if (bIsDay == true) {
                          //Tag-Icon
                          if (vIcon_ID == 800) {
                              zIcon = 1;
                          } else if (vIcon_ID == 801) {
                              zIcon = 2;
                          } else if (vIcon_ID == 802) {
                              zIcon = 3;
                          } else if (vIcon_ID == 803) {
                              zIcon = 4;
                          } else if (vIcon_ID == 804) {
                              zIcon = 6;
                          } else if (vIcon_ID == 500 || vIcon_ID == 501) {
                              zIcon = 14;
                          } else if (vIcon_ID == 502 || vIcon_ID == 503) {
                              zIcon = 13;
                          } else if (vIcon_ID == 314 || vIcon_ID == 321 || vIcon_ID == 504 || vIcon_ID == 522 || vIcon_ID == 531) {
                              zIcon = 18;
                          } else if (vIcon_ID == 511) {
                              zIcon = 26;
                          } else if (vIcon_ID == 300 || vIcon_ID == 301 || vIcon_ID == 302 || vIcon_ID == 310 || vIcon_ID == 311 || vIcon_ID == 312 || vIcon_ID == 313 || vIcon_ID == 520 || vIcon_ID == 521) {
                              zIcon = 12;
                          } else if (vIcon_ID == 200 || vIcon_ID == 201) {
                              zIcon = 17;
                          } else if (vIcon_ID == 202 || vIcon_ID == 210 || vIcon_ID == 230 || vIcon_ID == 231) {
                              zIcon = 16;
                          } else if (vIcon_ID == 211 || vIcon_ID == 212 || vIcon_ID == 221 || vIcon_ID == 232) {
                              zIcon = 15;
                          } else if (vIcon_ID == 600) {
                              zIcon = 21;
                          } else if (vIcon_ID == 601) {
                              zIcon = 20;
                          } else if (vIcon_ID == 602) {
                              zIcon = 23;
                          } else if (vIcon_ID == 611 || vIcon_ID == 612 || vIcon_ID == 613 || vIcon_ID == 615 || vIcon_ID == 616) {
                              zIcon = 29;
                          } else if (vIcon_ID == 620 || vIcon_ID == 621) {
                              zIcon = 19;
                          } else if (vIcon_ID == 622) {
                              zIcon = 22;
                          } else if (vIcon_ID == 700 || vIcon_ID == 711 || vIcon_ID == 721 || vIcon_ID == 731 || vIcon_ID == 741 || vIcon_ID == 751 || vIcon_ID == 761 || vIcon_ID == 762 || vIcon_ID == 771 || vIcon_ID == 772) {
                              zIcon = 32;
                          }
                      } else {
                          //Nacht-Icon
                          if (vIcon_ID == 800) {
                              zIcon = 33;
                          } else if (vIcon_ID == 801) {
                              zIcon = 34;
                          } else if (vIcon_ID == 802) {
                              zIcon = 35;
                          } else if (vIcon_ID == 803) {
                              zIcon = 36;
                          } else if (vIcon_ID == 804) {
                              zIcon = 38;
                          } else if (vIcon_ID == 500 || vIcon_ID == 501) {
                              zIcon = 39;
                          } else if (vIcon_ID == 502 || vIcon_ID == 503) {
                              zIcon = 40;
                          } else if (vIcon_ID == 314 || vIcon_ID == 321 || vIcon_ID == 504 || vIcon_ID == 522 || vIcon_ID == 531) {
                              zIcon = 18;
                          } else if (vIcon_ID == 511) {
                              zIcon = 26;
                          } else if (vIcon_ID == 300 || vIcon_ID == 301 || vIcon_ID == 302 || vIcon_ID == 310 || vIcon_ID == 311 || vIcon_ID == 312 || vIcon_ID == 313 || vIcon_ID == 520 || vIcon_ID == 521) {
                              zIcon = 12;
                          } else if (vIcon_ID == 200 || vIcon_ID == 201) {
                              zIcon = 41;
                          } else if (vIcon_ID == 202 || vIcon_ID == 210 || vIcon_ID == 230 || vIcon_ID == 231) {
                              zIcon = 42;
                          } else if (vIcon_ID == 211 || vIcon_ID == 212 || vIcon_ID == 221 || vIcon_ID == 232) {
                              zIcon = 15;
                          } else if (vIcon_ID == 600) {
                              zIcon = 43;
                          } else if (vIcon_ID == 601) {
                              zIcon = 43;
                          } else if (vIcon_ID == 602) {
                              zIcon = 44;
                          } else if (vIcon_ID == 611 || vIcon_ID == 612 || vIcon_ID == 613 || vIcon_ID == 615 || vIcon_ID == 616) {
                              zIcon = 29;
                          } else if (vIcon_ID == 620 || vIcon_ID == 621) {
                              zIcon = 19;
                          } else if (vIcon_ID == 622) {
                              zIcon = 22;
                          } else if (vIcon_ID == 700 || vIcon_ID == 711 || vIcon_ID == 721 || vIcon_ID == 731 || vIcon_ID == 741 || vIcon_ID == 751 || vIcon_ID == 761 || vIcon_ID == 762 || vIcon_ID == 771 || vIcon_ID == 772) {
                              zIcon = 32;
                          }
                      }
                      return baseVisPath + zIcon + '.svg';
                  }
                  
                  // Funktion, Runden eine Nachkommastelle
                  function DATARound(vValue) {
                      return Math.round(vValue * 10) / 10;
                  }
                  
                  // Funktion, um Windrichtung zu bestimmen
                  function getWindDirection(degrees) {
                      const directions = [
                      'N', 'NNO', 'NO', 'ONO',
                      'O', 'OSO', 'SO', 'SSO',
                      'S', 'SSW', 'SW', 'WSW',
                      'W', 'WNW', 'NW', 'NNW'
                      ];
                  
                      const index = Math.round(degrees / 22.5) % 16;
                      return directions[index];
                  }
                  
                  // Funktion, um Datenpunkte zu erstellen und zu setzen
                  function createAndSetState(id, value, type, unit = "") {
                      if (!existsState(id)) {
                          createState(id, value, {
                              type: type,
                              unit: unit,
                              read: true,
                              write: false
                          });
                      }
                      setState(id, value, true);
                  }
                   
                  // Scheduler: Alle 5 Minuten ausführen
                  schedule('35 */5 * * * *', function () {
                      fetchWeatherData();
                  });
                  
                  schedule('20 0 0 * * *', function () {
                      //Reset Zähler
                      setState(`${basePath}APICalls`, 0, true);
                  });
                  
                  

                  Ro75.

                  Frederik BussF Offline
                  Frederik BussF Offline
                  Frederik Buss
                  schrieb am zuletzt editiert von
                  #20

                  @ro75 Sehr cooler Ansatz mit den Icons - Ich hatte die Schmalspurvariante und habe die Icons auf 01d/01n usw. ausgelesen, Deine gefällt mir aber sehr viel besser. Werde ich die Tage bei mir auch umsetzen. Frage: mit welchem Widget zeigst Du die SVG an? Die sind ja in der Größe und vor allem Längen/Breitenverhältnis teilweise komplett unterschiedlich?

                  Ich habe zusätzlich noch die stündlichen Daten abgefragt, um eine Vorhersage für die nächste Stunde anzuzeigen:

                          // Stündliche Daten speichern
                            weatherData.hourly.forEach((hour, index) => {
                              createAndSetState(`${basePath}hourly.${index}.temp`, hour.temp, "number", "°C");
                              createAndSetState(`${basePath}hourly.${index}.icon`, getState(IconPath).val + hour.weather[0].icon + '.png', "string");
                              createAndSetState(`${basePath}hourly.${index}.weather`, hour.weather[0].description, "string");
                              createAndSetState(`${basePath}hourly.${index}.wind_speed`, hour.wind_speed, "number", "m/s");
                              createAndSetState(`${basePath}hourly.${index}.wind_gust`, hour.wind_gust || 0, "number", "m/s");
                              createAndSetState(`${basePath}hourly.${index}.clouds`, hour.clouds || 0, "number", "%");
                              createAndSetState(`${basePath}hourly.${index}.date`, formatDate(getDateObject((hour.dt * 1000)), "hh:mm"), "string");
                                          
                          });
                  
                  Ro75R 1 Antwort Letzte Antwort
                  0
                  • Frederik BussF Frederik Buss

                    @ro75 Sehr cooler Ansatz mit den Icons - Ich hatte die Schmalspurvariante und habe die Icons auf 01d/01n usw. ausgelesen, Deine gefällt mir aber sehr viel besser. Werde ich die Tage bei mir auch umsetzen. Frage: mit welchem Widget zeigst Du die SVG an? Die sind ja in der Größe und vor allem Längen/Breitenverhältnis teilweise komplett unterschiedlich?

                    Ich habe zusätzlich noch die stündlichen Daten abgefragt, um eine Vorhersage für die nächste Stunde anzuzeigen:

                            // Stündliche Daten speichern
                              weatherData.hourly.forEach((hour, index) => {
                                createAndSetState(`${basePath}hourly.${index}.temp`, hour.temp, "number", "°C");
                                createAndSetState(`${basePath}hourly.${index}.icon`, getState(IconPath).val + hour.weather[0].icon + '.png', "string");
                                createAndSetState(`${basePath}hourly.${index}.weather`, hour.weather[0].description, "string");
                                createAndSetState(`${basePath}hourly.${index}.wind_speed`, hour.wind_speed, "number", "m/s");
                                createAndSetState(`${basePath}hourly.${index}.wind_gust`, hour.wind_gust || 0, "number", "m/s");
                                createAndSetState(`${basePath}hourly.${index}.clouds`, hour.clouds || 0, "number", "%");
                                createAndSetState(`${basePath}hourly.${index}.date`, formatDate(getDateObject((hour.dt * 1000)), "hh:mm"), "string");
                                            
                            });
                    
                    Ro75R Offline
                    Ro75R Offline
                    Ro75
                    schrieb am zuletzt editiert von
                    #21

                    @frederik-buss die svg mit eine picture widget. Eines, wo ein dp angegeben wird. Zumindest im VIS 1.

                    Ro75.

                    SERVER = Beelink U59 16GB DDR4 RAM 512GB SSD, FB 7490, FritzDect 200+301+440, ConBee II, Zigbee Aqara Sensoren + NOUS A1Z, NOUS A1T, Philips Hue ** ioBroker, REDIS, influxdb2, Grafana, PiHole, Plex-Mediaserver, paperless-ngx (Docker), MariaDB + phpmyadmin *** VIS-Runtime = Intel NUC 8GB RAM 128GB SSD + 24" Touchscreen

                    Frederik BussF 2 Antworten Letzte Antwort
                    0
                    • T ticaki

                      Da es so aussieht als wenn bluefox den openweather adapter nach typescript portiert, könnte man da auch ne feature request erstellen.

                      wendy2702W Online
                      wendy2702W Online
                      wendy2702
                      schrieb am zuletzt editiert von
                      #22

                      @ticaki sagte in Wetterdaten abrufen per API-Call mit dem Javascript Adapter:

                      Da es so aussieht als wenn bluefox den openweather adapter nach typescript portiert, könnte man da auch ne feature request erstellen.

                      Gibt es das nicht schon oder ist das was anderes?

                      https://github.com/ioBroker/ioBroker.openweathermap/issues/348

                      https://github.com/ioBroker/ioBroker.openweathermap/issues/20

                      Bitte keine Fragen per PN, die gehören ins Forum!

                      Benutzt das Voting rechts unten im Beitrag wenn er euch geholfen hat.

                      T 1 Antwort Letzte Antwort
                      0
                      • wendy2702W wendy2702

                        @ticaki sagte in Wetterdaten abrufen per API-Call mit dem Javascript Adapter:

                        Da es so aussieht als wenn bluefox den openweather adapter nach typescript portiert, könnte man da auch ne feature request erstellen.

                        Gibt es das nicht schon oder ist das was anderes?

                        https://github.com/ioBroker/ioBroker.openweathermap/issues/348

                        https://github.com/ioBroker/ioBroker.openweathermap/issues/20

                        T Nicht stören
                        T Nicht stören
                        ticaki
                        schrieb am zuletzt editiert von
                        #23

                        @wendy2702
                        Ich hatte nicht in die issues rein geguckt, nur im code und gesehen das da Typescript vorbereitet wird.

                        Weather-Warnings Espresense NSPanel-Lovelace-ui Tagesschau

                        Spenden

                        1 Antwort Letzte Antwort
                        0
                        • Ro75R Ro75

                          @frederik-buss die svg mit eine picture widget. Eines, wo ein dp angegeben wird. Zumindest im VIS 1.

                          Ro75.

                          Frederik BussF Offline
                          Frederik BussF Offline
                          Frederik Buss
                          schrieb am zuletzt editiert von
                          #24

                          @ro75 Ich habe jetzt Deine Icon Konvertierung leicht angepasst und umgesetzt. Super gut - Damit konnte ich nun auch meine gebastelte ESP-Wetterstation im Gäste WC auf Openweather umstellen. IMG_9676.JPEG

                          Frederik BussF 1 Antwort Letzte Antwort
                          1
                          • Frederik BussF Frederik Buss

                            @ro75 Ich habe jetzt Deine Icon Konvertierung leicht angepasst und umgesetzt. Super gut - Damit konnte ich nun auch meine gebastelte ESP-Wetterstation im Gäste WC auf Openweather umstellen. IMG_9676.JPEG

                            Frederik BussF Offline
                            Frederik BussF Offline
                            Frederik Buss
                            schrieb am zuletzt editiert von Frederik Buss
                            #25

                            Mir ist noch ein Bug aufgefallen, bzw. eine Anpassung, die gemacht werden muss, wenn auf Deutsch umgestellt wird:
                            Die Regenabfrage muss natürlich nach "regen" suchen und nicht nach "rain".

                                    const isRaining = weatherData.current.weather[0].description.toLowerCase().includes("regen");
                            
                            1 Antwort Letzte Antwort
                            1
                            • Ro75R Ro75

                              @frederik-buss die svg mit eine picture widget. Eines, wo ein dp angegeben wird. Zumindest im VIS 1.

                              Ro75.

                              Frederik BussF Offline
                              Frederik BussF Offline
                              Frederik Buss
                              schrieb am zuletzt editiert von
                              #26

                              @ro75 Mal ne andere Frage: Ich versuche gerade verzweifelt an die aktuelle Regenmenge ranzukommen. Problem ist, dass im Schüssel eine Zahl enthalten ist. Ein direkter Zugriff current.rain.1h funktioniert nicht. Leider reichen da meine rudimentären JSON Kenntnisse nicht aus. Hat jemand eine Idee?

                                "current": {
                                  "dt": 1754829354,
                                  "temp": 4.65,
                                  "feels_like": 0.62,
                                  "pressure": 1008,
                                  "humidity": 95,
                                  "dew_point": 3.92,
                                  "uvi": 0.29,
                                  "clouds": 100,
                                  "visibility": 555,
                                  "wind_speed": 5.61,
                                  "wind_deg": 359,
                                  "wind_gust": 7.82,
                                  "weather": [
                                    {
                                      "id": 500,
                                      "main": "Rain",
                                      "description": "Leichter Regen",
                                      "icon": "10n"
                                    }
                                  ],
                                  "rain": {
                                    "1h": 0.4
                                  }
                              
                              Ro75R C 2 Antworten Letzte Antwort
                              0
                              • Frederik BussF Frederik Buss

                                @ro75 Mal ne andere Frage: Ich versuche gerade verzweifelt an die aktuelle Regenmenge ranzukommen. Problem ist, dass im Schüssel eine Zahl enthalten ist. Ein direkter Zugriff current.rain.1h funktioniert nicht. Leider reichen da meine rudimentären JSON Kenntnisse nicht aus. Hat jemand eine Idee?

                                  "current": {
                                    "dt": 1754829354,
                                    "temp": 4.65,
                                    "feels_like": 0.62,
                                    "pressure": 1008,
                                    "humidity": 95,
                                    "dew_point": 3.92,
                                    "uvi": 0.29,
                                    "clouds": 100,
                                    "visibility": 555,
                                    "wind_speed": 5.61,
                                    "wind_deg": 359,
                                    "wind_gust": 7.82,
                                    "weather": [
                                      {
                                        "id": 500,
                                        "main": "Rain",
                                        "description": "Leichter Regen",
                                        "icon": "10n"
                                      }
                                    ],
                                    "rain": {
                                      "1h": 0.4
                                    }
                                
                                Ro75R Offline
                                Ro75R Offline
                                Ro75
                                schrieb am zuletzt editiert von
                                #27

                                @frederik-buss das nutze ich nicht. ist mir zu "extrem" ungenau / unbestimmt. Ich nutze hierfür den Netatmo-Crawler und habe mir eine Wetterstation mit Regenmesser in meiner "direkten" Nähe gesucht. Bin mit den Werten sehr zufrieden.

                                Ro75.

                                SERVER = Beelink U59 16GB DDR4 RAM 512GB SSD, FB 7490, FritzDect 200+301+440, ConBee II, Zigbee Aqara Sensoren + NOUS A1Z, NOUS A1T, Philips Hue ** ioBroker, REDIS, influxdb2, Grafana, PiHole, Plex-Mediaserver, paperless-ngx (Docker), MariaDB + phpmyadmin *** VIS-Runtime = Intel NUC 8GB RAM 128GB SSD + 24" Touchscreen

                                Frederik BussF 1 Antwort Letzte Antwort
                                0
                                • Ro75R Ro75

                                  @frederik-buss das nutze ich nicht. ist mir zu "extrem" ungenau / unbestimmt. Ich nutze hierfür den Netatmo-Crawler und habe mir eine Wetterstation mit Regenmesser in meiner "direkten" Nähe gesucht. Bin mit den Werten sehr zufrieden.

                                  Ro75.

                                  Frederik BussF Offline
                                  Frederik BussF Offline
                                  Frederik Buss
                                  schrieb am zuletzt editiert von
                                  #28

                                  @ro75 wieder was gelernt... Nimmst Du eine Wetterstation oder mehrere und bildest einen Mittelwert? Wenn ich das richtig verstehe, sind das private Netatmo Wetterstationen, die öffentlich ihre Daten teilen. Fallen da nicht regelmässig Stationen weg, weil ausgeschaltet oder Konfig geändert etc?

                                  Ro75R 1 Antwort Letzte Antwort
                                  0
                                  • Frederik BussF Frederik Buss

                                    @ro75 wieder was gelernt... Nimmst Du eine Wetterstation oder mehrere und bildest einen Mittelwert? Wenn ich das richtig verstehe, sind das private Netatmo Wetterstationen, die öffentlich ihre Daten teilen. Fallen da nicht regelmässig Stationen weg, weil ausgeschaltet oder Konfig geändert etc?

                                    Ro75R Offline
                                    Ro75R Offline
                                    Ro75
                                    schrieb am zuletzt editiert von
                                    #29

                                    @frederik-buss habe auch so eine Wetterstation, allerdings ohne Regensensor. Ich hatte mir zwei herausgesucht und die Werte verglichen. Die Daten sind nahezu "identisch". Am Ende habe ich mich dann für eine entschieden. Bisher ist nix weggefallen. Wenn du diesbezüglich dir Sorgen machst, arbeite mit Alias. Dann kannst du ggfs. umswitchen ohne Funktionen und Co anzupassen.

                                    Ro75.

                                    SERVER = Beelink U59 16GB DDR4 RAM 512GB SSD, FB 7490, FritzDect 200+301+440, ConBee II, Zigbee Aqara Sensoren + NOUS A1Z, NOUS A1T, Philips Hue ** ioBroker, REDIS, influxdb2, Grafana, PiHole, Plex-Mediaserver, paperless-ngx (Docker), MariaDB + phpmyadmin *** VIS-Runtime = Intel NUC 8GB RAM 128GB SSD + 24" Touchscreen

                                    1 Antwort Letzte Antwort
                                    0
                                    • Frederik BussF Offline
                                      Frederik BussF Offline
                                      Frederik Buss
                                      schrieb am zuletzt editiert von
                                      #30

                                      @ro75 OK Danke probier ich mal aus. Trotzdem würde mich interessieren, wie man den JSON Teil auslesen kann, der eine Zahl ("1h") als Schlüssel beinhaltet....?

                                      1 Antwort Letzte Antwort
                                      0
                                      • Frederik BussF Frederik Buss

                                        @ro75 Mal ne andere Frage: Ich versuche gerade verzweifelt an die aktuelle Regenmenge ranzukommen. Problem ist, dass im Schüssel eine Zahl enthalten ist. Ein direkter Zugriff current.rain.1h funktioniert nicht. Leider reichen da meine rudimentären JSON Kenntnisse nicht aus. Hat jemand eine Idee?

                                          "current": {
                                            "dt": 1754829354,
                                            "temp": 4.65,
                                            "feels_like": 0.62,
                                            "pressure": 1008,
                                            "humidity": 95,
                                            "dew_point": 3.92,
                                            "uvi": 0.29,
                                            "clouds": 100,
                                            "visibility": 555,
                                            "wind_speed": 5.61,
                                            "wind_deg": 359,
                                            "wind_gust": 7.82,
                                            "weather": [
                                              {
                                                "id": 500,
                                                "main": "Rain",
                                                "description": "Leichter Regen",
                                                "icon": "10n"
                                              }
                                            ],
                                            "rain": {
                                              "1h": 0.4
                                            }
                                        
                                        C Offline
                                        C Offline
                                        CatShape
                                        schrieb am zuletzt editiert von CatShape
                                        #31

                                        @frederik-buss
                                        Beispiel:

                                        const stringJson = '{"current": {"rain": {"1h": 0.4}}}';
                                        const objWeather = JSON.parse(stringJson);
                                        let numberRain = 0;
                                        numberRain = objWeather.current.rain['1h'];
                                        // gleichwertige Alternativen:
                                        numberRain = objWeather['current']['rain']['1h'];
                                        numberRain = ((objWeather['current'])['rain'])['1h'];
                                        

                                        Raspberry Pi 5 8GB; Raspberry Pi OS; ioBroker; ecoflow_catshape, shelly-http-cs, tuya-cs

                                        Frederik BussF 1 Antwort Letzte Antwort
                                        0
                                        • C CatShape

                                          @frederik-buss
                                          Beispiel:

                                          const stringJson = '{"current": {"rain": {"1h": 0.4}}}';
                                          const objWeather = JSON.parse(stringJson);
                                          let numberRain = 0;
                                          numberRain = objWeather.current.rain['1h'];
                                          // gleichwertige Alternativen:
                                          numberRain = objWeather['current']['rain']['1h'];
                                          numberRain = ((objWeather['current'])['rain'])['1h'];
                                          
                                          Frederik BussF Offline
                                          Frederik BussF Offline
                                          Frederik Buss
                                          schrieb am zuletzt editiert von
                                          #32

                                          @catshape Das hatte ich zwar auch probiert, aber einen Fehler bekommen, wenn nicht definiert. Ich kann nicht über xyz.['123'] abfragen, ob der Schlüssel definiert ist:

                                          console.info(weatherData.current.rain  !== undefined ? weatherData.current.rain : "nicht definiert");
                                          console.info(weatherData.current.rain['1h']  !== undefined ? weatherData.current.rain['1h'] : "nicht definiert");
                                          

                                          Ersteres läuft sauber durch, letzteres gibt einen Fehler aus:

                                          javascript.0	11:23:18.994	info	nicht definiert
                                          javascript.0	11:23:19.008	error	TypeError: Cannot read properties of undefined (reading '1h')
                                          

                                          Ich frage also ab, ob der übergeordnete Schlüssel definiert ist und packe das Ganze sicherheitshalber in einen zusätzlichen Try/Catch. Vielleicht nicht 100% elegant, aber läuft jetzt - Danke nochmal für den Impuls!

                                                  try {
                                                      setState(`${basePathHMIP}HMIP_Wetter_Aktuell_Regen`, weatherData.current.rain !== undefined ? weatherData.current.rain['1h'] : 0);
                                                  } catch (errorRain) {
                                                      setState(`${basePathHMIP}HMIP_Wetter_Aktuell_Regen`, 0);
                                                  }
                                          

                                          Mir ist bei der Gelegenheit auch aufgefallen, dass die Fehlermeldung im Script einen Fehler nicht ausgibt. Hier die korrigierte Version:

                                          } catch (error) {
                                               // Logge einen Fehler, wenn die API nicht erreichbar ist
                                               console.error("Fehler beim Abrufen der Wetterdaten: " + error.message);
                                          }
                                          
                                          C 1 Antwort Letzte Antwort
                                          0
                                          Antworten
                                          • In einem neuen Thema antworten
                                          Anmelden zum Antworten
                                          • Älteste zuerst
                                          • Neuste zuerst
                                          • Meiste Stimmen


                                          Support us

                                          ioBroker
                                          Community Adapters
                                          Donate

                                          825

                                          Online

                                          32.4k

                                          Benutzer

                                          81.5k

                                          Themen

                                          1.3m

                                          Beiträge
                                          Community
                                          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
                                          ioBroker Community 2014-2025
                                          logo
                                          • Anmelden

                                          • Du hast noch kein Konto? Registrieren

                                          • Anmelden oder registrieren, um zu suchen
                                          • Erster Beitrag
                                            Letzter Beitrag
                                          0
                                          • Home
                                          • Aktuell
                                          • Tags
                                          • Ungelesen 0
                                          • Kategorien
                                          • Unreplied
                                          • Beliebt
                                          • GitHub
                                          • Docu
                                          • Hilfe