NEWS


  • Hallo zusammen

    Da WU keine Daten mehr liefert (zumindest gratis nicht) habe ich mir heute ein Skript zum auslesen der DarkSky Daten gebaut (quick&dirty).
    Wenn's jemand gebrauchen kann, nur zu.
    Falls ich mal Zeit finde werde ich evtl. einen Adapter daraus machen - oder jemand von euch übernimmt 😉

    var request = require('request');
    var moment = require('moment');
    
    extractDarkSkyData(null);
    
    
    // Trigger
    schedule("*/5 * * * *", function (data) {
        extractDarkSkyData(data);
    });
    
    function extractDarkSkyData(data) {
        log("calling Darksky Wetter URL", 'info');
        //https://api.darksky.net/forecast/2cd....997/47.2694981,8.6569669?units=si&lang=de
        request('https://api.darksky.net/forecast/<yourApiKey>/<yourCoordinates>?units=si&lang=de', 
                 {json:true}, function (error, response, body) {
            log("looking for DarkSky data...", 'info');
            if (!error && response.statusCode == 200) {
                log ("error:" + error);            
    
                log ("basics", 'info');
                setIfDifferent('darksky.latitude', "Latitude", body.latitude, 0, "°", true);
                setIfDifferent('darksky.longitude', "Longitude", body.longitude, 0, "°", true);
                setIfDifferent('darksky.timezone', "Timezone", body.timezone, "n/a", "", false);
                
                log ("current", 'info');
                setIfDifferent('darksky.currently.time', "time (unix, local)", body.currently.time, 0, " unix", true);
                setIfDifferent('darksky.currently.summary', "Weather", body.currently.summary, "n/a", "", false);
                setIfDifferent('darksky.currently.icon', "", body.currently.icon, "", "", false);
                setIfDifferent('darksky.currently.precipIntensity', "Niederschlag", body.currently.precipIntensity, 0, "mm/h", true);
                setIfDifferent('darksky.currently.precipProbability', "Niederschlag Wahrscheinlichkeit", body.currently.precipProbability *100, 0, "%", true);
                setIfDifferent('darksky.currently.precipType', "Niederschlag Typ", body.currently.precipType, "", "", false);
                setIfDifferent('darksky.currently.temperature', "Temperatur", body.currently.temperature, 0, "°C", true);
                setIfDifferent('darksky.currently.apparentTemperature', "Temperatur (Windchill)", body.currently.apparentTemperature, 0, "°C", true);
                setIfDifferent('darksky.currently.dewPoint', "Taupunkt", body.currently.dewPoint, 0, "°C", true);
                setIfDifferent('darksky.currently.humidity', "Luftfeuchtigkeit", body.currently.humidity *100, 0, "%", true);
                setIfDifferent('darksky.currently.pressure', "Luftdruck", body.currently.pressure, 0, "hPa", true);
                setIfDifferent('darksky.currently.windSpeed', "Windgeschwindigkeit", body.currently.windSpeed, 0, "m/s", true);
                setIfDifferent('darksky.currently.windGust', "Boen", body.currently.windGust, 0, "m/s", true);
                setIfDifferent('darksky.currently.windBearing', "Windrichtung", body.currently.windBearing, 0, "°", true);
                setIfDifferent('darksky.currently.cloudCover', "Bedeckungsgrad", body.currently.cloudCover *100, 0, "%", true);
                setIfDifferent('darksky.currently.uvIndex', "UV Index", body.currently.uvIndex, 0, "", true);
                setIfDifferent('darksky.currently.visibility', "Sichtweite", body.currently.visibility, 0, "km", true);
                setIfDifferent('darksky.currently.ozone', "Ozon", body.currently.ozone, 0, "DU", true);
                
                
                var obsDate = moment.unix(body.currently.time);
                var now = moment();
                var age = moment.duration(now.diff(obsDate));
                log("age in Seconds: " + age.asSeconds(), 'info');
                    
                setIfDifferent('darksky.currently.age', 'current_age', age.asSeconds(), 0, 's', true);
                setIfDifferent('darksky.currently.time2', 'Zeit', obsDate.format("DD.MM.YYYY HH:mm:ss ZZ"), "", '', false);
                
                log ("hourly", 'info');
                var i=0;
                body.hourly.data.forEach(function(value, index, array){
                    var obsDate = moment.unix(value.time);
                    var now = moment();
                    var age = moment.duration(now.diff(obsDate));
                    log("age in Seconds: " + age.asSeconds(), 'info');
    
                    //I'm only interested in future data. If you want all data, remove the 'if'
                    if (age < 0) {
                        log("future entry. store it", 'debug');
                        setIfDifferent('darksky.hourly.'+i+'.time', "time (unix, local)", value.time, 0, "unix", true);
                        setIfDifferent('darksky.hourly.'+i+'.summary', "Weather", value.summary, "n/a", "", false);
                        setIfDifferent('darksky.hourly.'+i+'.icon', "", value.icon, "", "", false);
                        setIfDifferent('darksky.hourly.'+i+'.precipIntensity', "Niederschlag", value.precipIntensity, 0, "mm/h", true);
                        setIfDifferent('darksky.hourly.'+i+'.precipProbability', "Niederschlag Wahrscheinlichkeit", value.precipProbability *100, 0, "%", true);
                        setIfDifferent('darksky.hourly.'+i+'.precipType', "Niederschlag Typ", value.precipType, "", "", false);
                        setIfDifferent('darksky.hourly.'+i+'.temperature', "Temperatur", value.temperature, 0, "°C", true);
                        setIfDifferent('darksky.hourly.'+i+'.apparentTemperature', "Temperatur (Windchill)", value.apparentTemperature, 0, "°C", true);
                        setIfDifferent('darksky.hourly.'+i+'.dewPoint', "Taupunkt", value.dewPoint, 0, "°C", true);
                        setIfDifferent('darksky.hourly.'+i+'.humidity', "Luftfeuchtigkeit", value.humidity *100, 0, "%", true);
                        setIfDifferent('darksky.hourly.'+i+'.pressure', "Luftdruck", value.pressure, 0, "hPa", true);
                        setIfDifferent('darksky.hourly.'+i+'.windSpeed', "Windgeschwindigkeit", value.windSpeed, 0, "m/s", true);
                        setIfDifferent('darksky.hourly.'+i+'.windGust', "Boen", value.windGust, 0, "m/s", true);
                        setIfDifferent('darksky.hourly.'+i+'.windBearing', "Windrichtung", value.windBearing, 0, "°", true);
                        setIfDifferent('darksky.hourly.'+i+'.cloudCover', "Bedeckungsgrad", value.cloudCover *100, 0, "%", true);
                        setIfDifferent('darksky.hourly.'+i+'.uvIndex', "UV Index", value.uvIndex, 0, "", true);
                        setIfDifferent('darksky.hourly.'+i+'.visibility', "Sichtweite", value.visibility, 0, "km", true);
                        setIfDifferent('darksky.hourly.'+i+'.ozone', "Ozon", value.ozone, 0, "DU", true);
                        setIfDifferent('darksky.hourly.'+i+'.age', 'current_age', age.asSeconds(), 0, 's', true);
                        setIfDifferent('darksky.hourly.'+i+'.time2', 'Zeit', obsDate.format("DD.MM.YYYY HH:mm:ss ZZ"), "", '', false);
                        i++
                    } else {
                        log("past entry - not stored");
                    }
                });
                
                log ("daily", 'info');
                i=0;
                body.daily.data.forEach(function(value, index, array){
                    var obsDate = moment.unix(value.time);
                    var now = moment();
                    var age = moment.duration(now.diff(obsDate));
                    log("age in Seconds: " + age.asSeconds(), 'info');
                    
                    if (age < 0) {
                        log("future entry. store it", 'debug');
                        setIfDifferent('darksky.daily.'+i+'.time', "time (unix, local)", value.time, 0, "unix", true);
                        setIfDifferent('darksky.daily.'+i+'.summary', "Weather", value.summary, "n/a", "", false);
                        setIfDifferent('darksky.daily.'+i+'.icon', "", value.icon, "", "", false);
                        setIfDifferent('darksky.daily.'+i+'.sunriseTime', "Sonnenaufgang", value.sunriseTime, "", "unix", true);
                        setIfDifferent('darksky.daily.'+i+'.sunsetTime', "Sonnenuntergang", value.sunsetTime, "", "unix", true);
                        setIfDifferent('darksky.daily.'+i+'.moonPhase', "Mondphase", value.moonPhase *100, 0, "%", true);
                        setIfDifferent('darksky.daily.'+i+'.precipIntensity', "Niederschlag", value.precipIntensity, 0, "mm/h", true);
                        setIfDifferent('darksky.daily.'+i+'.precipIntensityMax', "Niederschlag MAX", value.precipIntensityMax, 0, "mm/h", true);
                        setIfDifferent('darksky.daily.'+i+'.precipIntensityMaxTime', "Niederschlag MAX Zeit", value.precipIntensityMaxTime, 0, "unix", true);
                        setIfDifferent('darksky.daily.'+i+'.precipIntensity', "Niederschlag", value.precipIntensity, 0, "mm/h", true);
                        setIfDifferent('darksky.daily.'+i+'.precipProbability', "Niederschlag Wahrscheinlichkeit", value.precipProbability *100, 0, "%", true);
                        setIfDifferent('darksky.daily.'+i+'.precipType', "Niederschlag Typ", value.precipType, "", "", false);
                        setIfDifferent('darksky.daily.'+i+'.temperatureHigh', "Temperatur High", value.temperatureHigh, 0, "°C", true);
                        setIfDifferent('darksky.daily.'+i+'.temperatureHighTime', "Temperatur High Zeit", value.temperatureHighTime, 0, "unix", true);
                        setIfDifferent('darksky.daily.'+i+'.temperatureLow', "Temperatur Low", value.temperatureLow, 0, "°C", true);
                        setIfDifferent('darksky.daily.'+i+'.temperatureLowTime', "Temperatur Low Zeit", value.temperatureLowTime, 0, "unix", true);
                        setIfDifferent('darksky.daily.'+i+'.apparentTemperatureHigh', "Temperatur High (Windchill)", value.apparentTemperatureHigh, 0, "°C", true);
                        setIfDifferent('darksky.daily.'+i+'.apparentTemperatureHighTime', "Temperatur (Windchill) High Zeit", value.apparentTemperatureHighTime, 0, "unix", true);
                        setIfDifferent('darksky.daily.'+i+'.apparentTemperatureLow', "Temperatur Low (Windchill)", value.apparentTemperatureLow, 0, "°C", true);
                        setIfDifferent('darksky.daily.'+i+'.apparentTemperatureLowTime', "Temperatur (windchill) Low Zeit", value.apparentTemperatureLowTime, 0, "unix", true);
                        setIfDifferent('darksky.daily.'+i+'.dewPoint', "Taupunkt", value.dewPoint, 0, "°C", true);
                        setIfDifferent('darksky.daily.'+i+'.humidity', "Luftfeuchtigkeit", value.humidity *100, 0, "%", true);
                        setIfDifferent('darksky.daily.'+i+'.pressure', "Luftdruck", value.pressure, 0, "hPa", true);
                        setIfDifferent('darksky.daily.'+i+'.windSpeed', "Windgeschwindigkeit", value.windSpeed, 0, "m/s", true);
                        setIfDifferent('darksky.daily.'+i+'.windGust', "Boen", value.windGust, 0, "m/s", true);
                        setIfDifferent('darksky.daily.'+i+'.windGustTime', "Boen Zeit", value.windGustTime, 0, "unix", true);
                        setIfDifferent('darksky.daily.'+i+'.windBearing', "Windrichtung", value.windBearing, 0, "°", true);
                        setIfDifferent('darksky.daily.'+i+'.cloudCover', "Bedeckungsgrad", value.cloudCover *100, 0, "%", true);
                        setIfDifferent('darksky.daily.'+i+'.uvIndex', "UV Index", value.uvIndex, 0, "", true);
                        setIfDifferent('darksky.daily.'+i+'.uvIndexTime', "UV Index Zeit", value.uvIndexTime, 0, "unix", true);
                        setIfDifferent('darksky.daily.'+i+'.visibility', "Sichtweite", value.visibility, 0, "km", true);
                        setIfDifferent('darksky.daily.'+i+'.ozone', "Ozon", value.ozone, 0, "DU", true);
                        setIfDifferent('darksky.daily.'+i+'.temperatureMax', "Temperatur MAX", value.temperatureMax, 0, "°C", true);
                        setIfDifferent('darksky.daily.'+i+'.temperatureMaxTime', "Temperatur MAX Zeit", value.temperatureMaxTime, 0, "unix", true);
                        setIfDifferent('darksky.daily.'+i+'.temperatureMin', "Temperatur MIN", value.temperatureMin, 0, "°C", true);
                        setIfDifferent('darksky.daily.'+i+'.temperatureMinTime', "Temperatur MIN Zeit", value.temperatureMinTime, 0, "unix", true);
                        setIfDifferent('darksky.daily.'+i+'.apparentTemperatureMax', "Temperatur MAX (Windchill)", value.apparentTemperatureMax, 0, "°C", true);
                        setIfDifferent('darksky.daily.'+i+'.apparentTemperatureMaxTime', "Temperatur (Windchill) MAX Zeit", value.apparentTemperatureMaxTime, 0, "unix", true);
                        setIfDifferent('darksky.daily.'+i+'.apparentTemperatureMin', "Temperatur MIN (Windchill)", value.apparentTemperatureMin, 0, "°C", true);
                        setIfDifferent('darksky.daily.'+i+'.apparentTemperatureMinTime', "Temperatur (windchill) MAX Zeit", value.apparentTemperatureMinTime, 0, "unix", true);
    
                        setIfDifferent('darksky.daily.'+i+'.age', 'current_age', age.asSeconds(), 0, 's', true);
                        setIfDifferent('darksky.daily.'+i+'.time2', 'Zeit', obsDate.format("DD.MM.YYYY HH:mm:ss ZZ"), "", '', false);
                        i++
                    } else {
                        log("past entry - not stored");
                    }
                });                                
            } else {
                log ("error:" + error.stack, 'error');
            }
            log("END Darksky Wetter data...", 'info');
        });
    }
    
    
    function setIfDifferent(id, name, value, initVal, unit, isNumber) {
        var oldVal = getState(id);
        if (oldVal.notExist) {
            createState(id, {name: name, initialValue: initVal, unit: unit}, function(){
            log("new State created: " + id + " ->" + name);
            setIfDifferent(id, name, value, initVal, unit);
            });
        }
        else if (oldVal.val != value) {
            if (isNumber) {
                setState(id, parseFloat(value));
            } else {
                setState(id, value);
            }
            log("new Value set for " + name + " (" + id + ")" + ": " + value + " / old: " + oldVal.val, 'info');
        }
    }
    

    viele Grüsse
    Daniel


  • Wollte das Script ausprobieren.

    Nur bekomme ich es nicht zum laufen.

    Fehlermeldungen direkt aus dem Script-Editor und aus dem Log habe ich angehängt.

    Habe ich da ein Problem in Zeile 16 mit constants ? Wenn ich mit Maus über das Wort fahre erhalte ich folgenden Text:

    Cannot find name 'constants'. Did you mean '"constants"'?
    any

    Wahrscheinlich ist es eh nur eine Kleinigkeit, aber für mich sind Scripte Neuland.

    LG
    Martin

    Meldung1.png
    Meldung2.png


  • Hallo Martin

    Lass diese Option einfach mal weg. die braucht es eigentlich gar nicht:
    also

    ...
    request('https://api.darksky.net/forecast/<yourApiKey>/<yourCoordinates>?units=si&lang=de', 
                 {json:true}, function (error, response, body) {
    ...
    
    

    viele Grüsse
    Daniel

    P.S.
    Ich nehme sie oben auch raus.


  • Danke, danke, danke.

    Funktioniert nun perferkt.

  • Most Active

    das script funktioniert bei mir und holt Daten, aber mein iobroker schmiert total ab???

  • Forum Testing Most Active

    Dschaedl sagte in Skript für DarkSky Wetterdaten:

    Da WU keine Daten mehr liefert (zumindest gratis nicht)

    Siehe mal da:

    Link

  • Most Active

    da gibts aber wieder kein "current" also aktuelles wetter, oder?
    Darksky hat auch das "jetzt" wetter

  • Forum Testing Most Active

    dos1973 sagte in Skript für DarkSky Wetterdaten:

    da gibts aber wieder kein "current" also aktuelles wetter, oder?
    Darksky hat auch das "jetzt" wetter

    Doch, ein Auszug davon:

    Screenshot (2641).png

  • Most Active

    ok, dann schau ich da mal rein, Danke


  • dos1973 sagte in Skript für DarkSky Wetterdaten:

    das script funktioniert bei mir und holt Daten, aber mein iobroker schmiert total ab???

    hmm, also bei mir rennt das Script nun seit 28.März ohne Probleme durch, und auch Iobroker macht keine Zicken

  • Starter

    Hallo,

    deute ich das hier richtig:

    schedule("*/5 * * * *", function (data) {

    das die 5 bedeutet alle 5 Minuten werden die aktuellen Daten geholt? Weil ich mich gewundert habe in der Darksky API, das da schon über 200 Aufrufe waren, wobei das
    Script erst ein paar Stunden lief.

    Kann man hier einen kleineren Intervall einstellen? So oft muss das ja nicht sein die Daten abzurufen, auch wenn 1000 Aufrufe kostenfrei sind.

    Grüße
    JB

Suggested Topics

539
Online

34.6k
Users

40.7k
Topics

557.3k
Posts