Maschinenlesbare Wetterdaten für .at

Hallo

kennt jemand von euch ein Wetterseite für Österreich bei der sich die Vorhersagedaten in vernünftig maschinenlesbarer Form auslesen lassen ?
Also nicht die übliche Prosa wie „… teils wolkig teil heiter“ , sondern „Sonnenscheindauer in Stunden“ „Regenwahrscheinlichkeit in %“ ect.

Ich möchte damit das Akkumanagement meiner gerade errichteten PV-Inselanlage optimieren.

schönen Dank
bb

Ich denke mal ich hab gefunden was ich suchte:

http://www.proplanta.de/Agrarwetter-Oesterreich/

die Seite hat zwar einen grässlichen Quelltext, mit etwa Mühe sollte sich aber alles gesuchte parsen lassen.

  • falls jemand noch etwas besseres hat …
    bb

Hallo bbernhard,

danke für den Hinweis. Schon einen Script-Rohentwurf, den man adaptieren könnte ? :slight_smile:

Nö, wie denn.
Hab die Seite selbst erst gestern gefunden.
Muß mir erst überlegen ob und wie wie ich das am besten verarbeite.

gruß
bb

Hallo bbernhard

JA, ich kenne und verwende zwei Wetterdienste welche eine frei API anbieten:

  1. Yahoo Wetter API bietet einen RSS Feed welchen man mit XML relativ einfach auswerten kann.
    Siehe zum Beispiel Link für RSS Feed für Linz: http://weather.yahooapis.com/forecastrss?w=545801&u=c.
    Ansatzpunkte wie du das in PHP auswerten kannst findet du hier.

  2. forcast.io bietet eine JSON API (10.000 Abfragen pro Tag gratis)

Mit folgenden zwei Links sind auch ‚EndUser-Web-Seiten‘ für forcast.io verfügbar:

Tipp: Man kann auch direkt Geo-Koordinaten angeben: http://forecast.io/#/f/48.3059,14.2867

Hinweis: Dieser Wetterdienst verwendet verschiedene Datenquellen und berechnet einen Durchschnitt.

Die API dazu ist unter https://developer.forecast.io/ beschrieben -> einfach einen Account anlegen damit man einen API Key bekommt.
API Doku: https://developer.forecast.io/docs/v2

Ich hab das ganze Mal ganz rudimentär in PHP abgefragt und als einfache HTML Tabellen ausgegeben um zu sehen was geht.

Aktuelle Wetterbedingungen:
forecastIO-CurrentConditions.png

Vorhersage für Heute auf Stundenbasis:

Vorhersage für die nächsten 7 Tage auf Tagesbasis:


Soucre Code (ohne HTML Tabellen Ausgabe):


<?

$api_key = 'hier API Key eintragen';
$latitude = '48.3059';       //hier GEO-Koordinaten angeben
$longitude = '14.2867';    //hier GEO-Koordinaten angeben
$units = 'ca';  // Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
$lang = 'de'; // Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'


$forecast = new ForecastIO($api_key);

// GET CURRENT CONDITIONS
$condition = $forecast->getCurrentConditions($latitude, $longitude, $units, $lang);
var_dump($condition);

// GET HOURLY CONDITIONS FOR TODAY
$conditions_today = $forecast->getForecastToday($latitude, $longitude, $units, $lang);
var_dump($conditions_today);

// GET DAILY CONDITIONS FOR NEXT 7 DAYS
$conditions_week = $forecast->getForecastWeek($latitude, $longitude, $units, $lang);
var_dump($conditions_week);



class ForecastIO {

  private $api_key;
  const API_ENDPOINT = 'https://api.forecast.io/forecast/';

  function __construct($api_key) {
    $this->api_key = $api_key;
  }


  private function requestData($latitude, $longitude, $units, $language = 'auto', $timestamp = false, $exclusions = false) {

    $validUnits = array('auto', 'us', 'si', 'ca', 'uk');
    if (in_array($units, $validUnits)) {
      $request_url = self::API_ENDPOINT .
       $this->api_key . '/' .
        $latitude . ',' . $longitude .
        ( $timestamp ? ',' . $timestamp : '' ) .
        '?units=' . $units . '&lang=' . $language .
        ( $exclusions ? '&exclude=' . $exclusions : '' );

      //Use Buffer to cache API-requests if initialized * (if not, just get the latest data) More info: http://git.io/FoO2Qw
      if(class_exists('Buffer')) {
        $cache = new Buffer();
        $content = $cache->data($request_url);
      } else {
        //echo $request_url . "
";
        //$content = file_get_contents($request_url);
        $content = Sys_GetURLContent($request_url);
      }
    } else {
      return false;
    }
    if (!empty($content)) { return json_decode($content); } else { return false; }
  }

  //Will return the current conditions
  function getCurrentConditions($latitude, $longitude, $units = 'auto', $language) {

    $data = $this->requestData($latitude, $longitude, $units, $language);
    if ($data !== false) {
      return new ForecastIOConditions($data->currently);
    } else {
      return false;
    }
  }

  //Will return historical conditions for day of given timestamp
  function getHistoricalConditions($latitude, $longitude, $units = 'auto', $language, $timestamp) {

    $exclusions = 'currently,minutely,hourly,alerts,flags';
    $data = $this->requestData($latitude, $longitude, $units, $language, $timestamp, $exclusions);
    if ($data !== false) {
      return new ForecastIOConditions($data->daily->data[0]);
    } else {
      return false;
    }
  }

  //Will return conditions on hourly basis for today
  function getForecastToday($latitude, $longitude, $units = 'auto', $language) {

    $data = $this->requestData($latitude, $longitude, $units, $language);
    if ($data !== false) {
      $conditions = array();
      $today = date('Y-m-d');
      foreach ($data->hourly->data as $raw_data) {
        if (date('Y-m-d', $raw_data->time) == $today) {
          $conditions[] = new ForecastIOConditions($raw_data);
        }
      }
      return $conditions;
    } else {
      return false;
    }
  }

  //Will return daily conditions for next seven days
  function getForecastWeek($latitude, $longitude, $units = 'auto', $language) {

    $data = $this->requestData($latitude, $longitude, $units, $language);
    if ($data !== false) {
      $conditions = array();
      foreach ($data->daily->data as $raw_data) {
        $conditions[] = new ForecastIOConditions($raw_data);
      }
      return $conditions;
    } else {
      return false;
    }
  }
}


/**
* Wrapper for get data by getters
*/
class ForecastIOConditions {

  private $raw_data;

  function __construct($raw_data) {
    $this->raw_data = $raw_data;
  }

  function getTemperature() {
                        if(isset($this->raw_data->temperature)) { return $this->raw_data->temperature; } else { return "n.a."; }
  }

  function getTemperatureMin() {
                        if(isset($this->raw_data->temperatureMin)) { return $this->raw_data->temperatureMin; } else { return "n.a."; }
  }

  function getTemperatureMinTime($format=null) {
      if (!isset($format)) { return $this->raw_data->temperatureMinTime; } else { return date($format, $this->raw_data->temperatureMinTime); }
  }

  function getTemperatureMax() {
                        if(isset($this->raw_data->temperatureMax)) { return $this->raw_data->temperatureMax; } else { return "n.a."; }
  }

  function getTemperatureMaxTime($format=null) {
      if (!isset($format)) { return $this->raw_data->temperatureMaxTime; } else { return date($format, $this->raw_data->temperatureMaxTime); }
  }

  function getApparentTemperature() {
                        if(isset($this->raw_data->apparentTemperature)) { return $this->raw_data->apparentTemperature; } else { return "n.a."; }
  }

  function getapparentTemperatureMin() {
                        if(isset($this->raw_data->apparentTemperatureMin)) { return $this->raw_data->apparentTemperatureMin; } else { return "n.a."; }
  }

  function getapparentTemperatureMinTime($format=null) {
      if (!isset($format)) { return $this->raw_data->apparentTemperatureMinTime; } else { return date($format, $this->raw_data->apparentTemperatureMinTime); }
  }

  function getapparentTemperatureMax() {
                        if(isset($this->raw_data->apparentTemperatureMax)) { return $this->raw_data->apparentTemperatureMax; } else { return "n.a."; }
  }

  function getapparentTemperatureMaxTime($format=null) {
      if (!isset($format)) { return $this->raw_data->apparentTemperatureMaxTime; } else { return date($format, $this->raw_data->apparentTemperatureMaxTime); }
  }

  function getSummary() {
                        if(isset($this->raw_data->summary)) {
                                   return iconv("UTF-8", "ISO-8859-1", $this->raw_data->summary);
                        } else { return "n.a."; }
  }

  function getIcon() {
                        if(isset($this->raw_data->icon)) { return $this->raw_data->icon; } else { return "n.a."; }
  }

  function getTime($format = null) {
    if (!isset($format)) { return $this->raw_data->time; } else { return date($format, $this->raw_data->time); }
  }

  function getPressure() {
                        if(isset($this->raw_data->pressure)) { return $this->raw_data->pressure; } else { return "n.a."; }
  }

  function getDewPoint() {
                        if(isset($this->raw_data->dewPoint)) { return $this->raw_data->dewPoint; } else { return "n.a."; }
  }

  function getHumidity() {
                        if(isset($this->raw_data->humidity)) { return $this->raw_data->humidity; } else { return "n.a."; }
  }

  function getWindSpeed() {
                        if(isset($this->raw_data->windSpeed)) { return $this->raw_data->windSpeed; } else { return "n.a."; }
  }

  function getWindBearing() {
                        if(isset($this->raw_data->windBearing)) { return $this->raw_data->windBearing; } else { return "n.a."; }
  }

  function getPrecipitationType() {
                        if(isset($this->raw_data->precipType)) { return $this->raw_data->precipType; } else { return "-"; }
  }

  function getPrecipitationProbability() {
                        if(isset($this->raw_data->precipProbability)) { return $this->raw_data->precipProbability; } else { return "n.a."; }
  }

  function getPrecipIntensity() {
                        if(isset($this->raw_data->precipIntensity)) { return $this->raw_data->precipIntensity; } else { return "n.a."; }
  }

  function getPrecipIntensityMax() {
                        if(isset($this->raw_data->precipIntensityMax)) { return $this->raw_data->precipIntensityMax; } else { return "n.a."; }
  }

  function getPrecipIntensityMaxTime($format=null) {
                        if(isset($this->raw_data->precipIntensityMaxTime)) {
                                   if (!isset($format)) { return $this->raw_data->precipIntensityMaxTime; } else { return date($format, $this->raw_data->precipIntensityMaxTime); }
                        } else { return 0; }
  }

  function getCloudCover() {
                        if(isset($this->raw_data->cloudCover)) { return $this->raw_data->cloudCover; } else { return "n.a."; }
  }

  function getOzone() {
                        if(isset($this->raw_data->ozone)) { return $this->raw_data->ozone; } else { return "n.a."; }
  }

  function getSunrise($format=null) {
            if (!isset($format)) { return $this->raw_data->sunriseTime; } else { return date($format, $this->raw_data->sunriseTime); }
  }

  function getSunset($format=null) {
                        if (!isset($format)) { return $this->raw_data->sunsetTime; } else { return date($format, $this->raw_data->sunsetTime); }
  }

  function getMoonPhase() {
                        if(isset($this->raw_data->moonPhase)) { return $this->raw_data->moonPhase; } else { return "n.a."; }
  }

}

?>

Danke dir, eine API ist natürlich vieel besser als HTML parsen.

Yahoo Wetter kannte ich, liegt aber in unserer Region (Südalpe/Beckenlage, oft Inversionswetterlage) mehr falsch als richtig.

Werde mal beobachten ob forcast.io das besser kann.
Allerdings sind das größtenteils US Datenquellen. Die können mit den regionalen Gegebenheiten wohl auch eher schlecht.

Deine Vorgabe ist ja schon super da kann ich leicht anknüpfen.

schönen Dank
bb

PreinfalkG

Kannst Du schon etwas über die Qualität der Vorhersage berichten?

Wie sieht beispielhaft der php code für die aktuelle Temperatur aus?

Danke :confused:

Hallo m0nx

Hier der ganze PHP Code der Abfrage mit HTML Erzeugung in einem Script.

Doings:

  • API Key eintragen
  • Geo Koordinaten auf deine Lokation stellen
  • anstatt der drei ‚echo $html‘ Ausgaben die Variable $html in einer ‚~HTMLBox‘ zuweisen

<?

$api_key = 'hier API KEY eintragen';
$latitude = '48.3059';
$longitude = '14.2867';
$units = 'ca';  // Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
$lang = 'de'; // Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'


$forecast = new ForecastIO($api_key);

//-------------------------------------------------------------------------------------------------------------------------------------
/*
 * GET CURRENT CONDITIONS
 */
$condition = $forecast->getCurrentConditions($latitude, $longitude, $units, $lang);
$html = "<style type='text/css'>";
$html .= "table { border-spacing: 0px; border-collapse:collapse; white-space:nowrap; }";
$html .= "tr.row:hover { background-color:#CCCCCC; color:black; }";
$html .= "td { text-align: right; padding-left: 5px; padding-right: 5px; border-left: 0px solid #fff;}";
$html .= "</style>";

$html .= "<table>";
$html .= AddCurrentConditionEntry("Zeit",$condition->getTime('d.m.Y H:i:s'),"");
$html .= AddCurrentConditionEntry("Zusammenfassung",$condition->getSummary(),"");		//utf8_encode

$html .= AddCurrentConditionEntry("Temperatur",$condition->getTemperature()," °C");
$html .= AddCurrentConditionEntry("gefühlte Temperatur",$condition->getApparentTemperature()," °C");
$html .= AddCurrentConditionEntry("Taupunkt",$condition->getDewPoint()," °C");
$html .= AddCurrentConditionEntry("Luftfeuchtigkeit",$condition->getHumidity()*100," %");

$html .= AddCurrentConditionEntry("Luftdruck",$condition->getPressure()," hPa");
$html .= AddCurrentConditionEntry("Windgeschindigkeit",$condition->getWindSpeed()," km/h");
$html .= AddCurrentConditionEntry("Windrichtung",$condition->getWindBearing(),"");

$html .= AddCurrentConditionEntry("Niederschlagswahrscheinlichkeit",$condition->getPrecipitationProbability()*100," %");
$html .= AddCurrentConditionEntry("Niederschlagsart",$condition->getPrecipitationType(),"");
$html .= AddCurrentConditionEntry("Niederschlagsintensität",$condition->getPrecipIntensity()," l");

$html .= AddCurrentConditionEntry("Wolkendecke",$condition->getCloudCover()*100," %");   //Bewölkungssituation
$html .= AddCurrentConditionEntry("Ozon",$condition->getOzone(),"");
$html .= AddCurrentConditionEntry("Icon",$condition->getIcon(),"");

$html .= "</table>";
echo $html;
//SetValue(27391 /*[Schnittstellen\Interfaces\Forecast.io\Aktuell\Aktuelll]*/ ,$html);


//-------------------------------------------------------------------------------------------------------------------------------------

/*
 * GET HOURLY CONDITIONS FOR TODAY
 */
$conditions_today = $forecast->getForecastToday($latitude, $longitude, $units, $lang);

$html = "<style type='text/css'>";
$html .= "table { border-spacing: 0px; border-collapse:collapse; white-space:nowrap; }";
$html .= "tr.header td { text-align: center; background-color:#CCCCCC; color:black; }";
$html .= "tr.row:hover { background-color:#CCCCCC; color:black; }";
$html .= "td { text-align: right; padding-left: 5px; padding-right: 5px; border-left: 1px solid #fff; font-size: 14px;}";
$html .= "</style>";
$html .= "<div style='width:99%; overflow:auto; border: 0px solid #CCC; margin: 1px 1px 8px 1px; padding: 10px 2px 10px 2px;'>";
$html .= "<table>";
$html .= "<tr class=header><td>Zeit</td><td>Zusammenfassung</td><td>Temp</td><td>gefühlt</td><td>Taupunkt</td><td>Bewölkung</td><td>Luftfeuchtigkeit</td><td>Luftdruck</td><td>Wind</td><td>Windrichtung</td><td>Niederschlag</td><td>Art</td><td>Menge</td><td>Ozon</td><td>Icon</td></tr>";
foreach($conditions_today as $cond) {
	$html .= AddHourlyConditionEntry($cond);
}
$html .= "</table>";
$html .= "</div>";
echo $html;
//SetValue(38572 /*[Schnittstellen\Interfaces\Forecast.io\Heute\Heute auf Stundenbasis]*/ ,$html);

//-------------------------------------------------------------------------------------------------------------------------------------

/*
 * GET DAILY CONDITIONS FOR NEXT 7 DAYS
 */
$conditions_week = $forecast->getForecastWeek($latitude, $longitude, $units, $lang);

$html = "<style type='text/css'>";
$html .= "table { border-spacing: 0px; border-collapse:collapse; white-space:nowrap; }";
$html .= "tr.header { background-color:#CCCCCC; color:black; }";
$html .= "td.header { text-align: center; font-weight: bold; font-size: 14px; }";
$html .= "tr.row:hover { background-color:#CCCCCC; color:black; }";
$html .= "td { text-align: right; padding-left: 5px; padding-right: 5px; border-left: 1px solid #fff; font-size: 14px;}";
$html .= "</style>";
$html .= "<div style='width:99%; overflow:auto; border: 0px solid #CCC; margin: 1px 1px 8px 1px; padding: 10px 2px 10px 2px;'>";

$html .= "<table>";
$html .= GetDailyConditionEntryTable1Header();
foreach($conditions_week as $conditions) {
	$html .= GetDailyConditionEntryTable1($conditions);
}
$html .= "</table>";
$html .= "<br><hr><br>";
$html .= "<table>";
$html .= GetDailyConditionEntryTable2Header();
foreach($conditions_week as $conditions) {
	$html .= GetDailyConditionEntryTable2($conditions);
}
$html .= "</table>";
$html .= "<br><hr><br>";
$html .= "<table>";
$html .= GetDailyConditionEntryTable3Header();
foreach($conditions_week as $conditions) {
	$html .= GetDailyConditionEntryTable3($conditions);
}
$html .= "</table>";
$html .= "<br><hr><br>";
$html .= "<table>";
$html .= GetDailyConditionEntryTable4Header();
foreach($conditions_week as $conditions) {
	$html .= GetDailyConditionEntryTable4($conditions);
}
$html .= "</table>";
$html .= "</div>";
echo $html;
//SetValue(47052 /*[Schnittstellen\Interfaces\Forecast.io\Woche\Woche auf Tagesbasis]*/ ,$html);

//-------------------------------------------------------------------------------------------------------------------------------------

/*
 * GET HISTORICAL CONDITIONS
	$condition = $forecast->getHistoricalConditions($latitude, $longitude, $units, $lang, time()-360000);	//strtotime('2014-10-10T14:00:00-0700'));
	// strtotime('2010-10-10T14:00:00-0700') gives timestamp for Pacfic Time... DST shouldn't matter since should be same day
	var_dump($condition);
*/

//-------------------------------------------------------------------------------------------------------------------------------------

function AddCurrentConditionEntry($key,$value,$suffix) {
	return sprintf("<tr class='row'><td>%s</td><td>%s%s</td></tr>",$key,$value,$suffix);
}

function AddHourlyConditionEntry($obj) {
	$tr = "<tr class='row'>";
	$tr .= sprintf("<td>%s</td>",$obj->getTime('H:i:s'));
	$tr .= sprintf("<td>%s</td>",$obj->getSummary());
	$tr .= sprintf("<td>%s °C</td>",$obj->getTemperature());
	$tr .= sprintf("<td>%s °C</td>",$obj->getApparentTemperature());
	$tr .= sprintf("<td>%s °C</td>",$obj->getDewPoint());
	$tr .= sprintf("<td>%s %%</td>",$obj->getCloudCover()*100);
	$tr .= sprintf("<td>%s %%</td>",$obj->getHumidity()*100);

	$tr .= sprintf("<td>%s hPa</td>",$obj->getPressure());
	$tr .= sprintf("<td>%s km/h</td>",$obj->getWindSpeed());
	$tr .= sprintf("<td>%s°</td>",$obj->getWindBearing());

	$tr .= sprintf("<td>%s %%</td>",$obj->getPrecipitationProbability()*100);
	$tr .= sprintf("<td>%s </td>",$obj->getPrecipitationType());
	$tr .= sprintf("<td>%s l</td>",$obj->getPrecipIntensity());

	$tr .= sprintf("<td>%s </td>",$obj->getOzone());
	$tr .= sprintf("<td>%s </td>",$obj->getIcon());
	$tr .= "</tr>";
	return $tr;
}

function AddDailyConditionEntry($obj) {
	$tr = "<tr class='row'>";
	$tr .= sprintf("<td>%s</td>",$obj->getTime('D, d.m.Y'));
	$tr .= sprintf("<td>%s</td>",$obj->getSummary());

	$tr .= sprintf("<td>%s °C um %s<br>%s °C um %s</td>",$obj->getTemperatureMin(),$obj->getTemperatureMinTime('H:i'),$obj->getTemperatureMax(),$obj->getTemperatureMaxTime('H:i'));
	$tr .= sprintf("<td>%s °C um %s<br>%s °C um %s</td>",$obj->getapparentTemperatureMin(),$obj->getapparentTemperatureMinTime('H:i'),$obj->getapparentTemperatureMax(),$obj->getapparentTemperatureMaxTime('H:i'));
	$tr .= sprintf("<td>%s °C</td>",$obj->getDewPoint());
	$tr .= sprintf("<td>%s %%</td>",$obj->getHumidity()*100);

	$tr .= sprintf("<td>%s hPa</td>",$obj->getPressure());
	$tr .= sprintf("<td>%s km/h</td>",$obj->getWindSpeed());
	$tr .= sprintf("<td>%s </td>",$obj->getWindBearing());

	$tr .= sprintf("<td>%s %%</td>",$obj->getPrecipitationProbability()*100);
	$tr .= sprintf("<td>%s </td>",$obj->getPrecipitationType());
	$tr .= sprintf("<td>%s l</td>",$obj->getPrecipIntensity());
	$tr .= sprintf("<td>%s l um %s</td>",$obj->getPrecipIntensityMax(),$obj->getPrecipIntensityMaxTime('H:i'));

	$tr .= sprintf("<td>%s %%</td>",$obj->getCloudCover()*100);
	$tr .= sprintf("<td>%s </td>",$obj->getOzone());
	$tr .= sprintf("<td>%s </td>",$obj->getIcon());

	$tr .= sprintf("<td>%s </td>",$obj->getSunrise('H:i'));
	$tr .= sprintf("<td>%s </td>",$obj->getSunset('H:i'));
	$tr .= sprintf("<td>%s </td>",$obj->getMoonPhase());

	$tr .= "</tr>";
	return $tr;
}

function GetDailyConditionEntryTable1Header() {
	return "<tr class=header><td class=header>Zeit</td><td class=header>Zusammenfassung</td><td class=header>Min/Max Temp</td><td class=header>Min/Max Temp gefühlt</td><td class=header>Taupunkt</td><td class=header>Icon</td></tr>";
}

function GetDailyConditionEntryTable1($obj) {
	$tr = "<tr class='row'>";
	$tr .= sprintf("<td>%s</td>",$obj->getTime('D, d.m.Y'));
	$tr .= sprintf("<td>%s</td>",$obj->getSummary());
	$tr .= sprintf("<td>%s °C um %s<br>%s °C um %s</td>",$obj->getTemperatureMin(),$obj->getTemperatureMinTime('H:i'),$obj->getTemperatureMax(),$obj->getTemperatureMaxTime('H:i'));
	$tr .= sprintf("<td>%s °C um %s<br>%s °C um %s</td>",$obj->getapparentTemperatureMin(),$obj->getapparentTemperatureMinTime('H:i'),$obj->getapparentTemperatureMax(),$obj->getapparentTemperatureMaxTime('H:i'));
	$tr .= sprintf("<td>%s °C</td>",$obj->getDewPoint());
	$tr .= sprintf("<td>%s </td>",$obj->getIcon());
	$tr .= "</tr>";
	return $tr;
}

function GetDailyConditionEntryTable2Header() {
	return "<tr class=header><td class=header>Zeit</td><td class=header>Luftfeuchtigkeit</td><td class=header>Luftdruck</td><td class=header>Ozon</td><td class=header>Windgeschwindigkeit</td><td class=header>Windrichtung</td></tr>";
}

function GetDailyConditionEntryTable2($obj) {
	$tr = "<tr class='row'>";
	$tr .= sprintf("<td>%s</td>",$obj->getTime('D, d.m.Y'));
	$tr .= sprintf("<td>%s %%</td>",$obj->getHumidity()*100);
	$tr .= sprintf("<td>%s hPa</td>",$obj->getPressure());
	$tr .= sprintf("<td>%s </td>",$obj->getOzone());
	$tr .= sprintf("<td>%s km/h</td>",$obj->getWindSpeed());
	$tr .= sprintf("<td>%s°</td>",$obj->getWindBearing());
	$tr .= "</tr>";
	return $tr;
}

function GetDailyConditionEntryTable3Header() {
	return "<tr class=header><td class=header>Zeit</td><td class=header>Bewölkung</td><td class=header>Niederschlags-<br>wahrscheinlichkeit</td><td class=header>Niederschlagsart</td><td class=header>Niederschlagsmenge</td><td class=header>Niederschlagsmenge<br>maximum</td></tr>";
}

function GetDailyConditionEntryTable3($obj) {
	$tr = "<tr class='row'>";
	$tr .= sprintf("<td>%s</td>",$obj->getTime('D, d.m.Y'));
	$tr .= sprintf("<td>%s %%</td>",$obj->getCloudCover()*100);
	$tr .= sprintf("<td>%s %%</td>",$obj->getPrecipitationProbability()*100);
	$tr .= sprintf("<td>%s </td>",$obj->getPrecipitationType());
	$tr .= sprintf("<td>%s l</td>",$obj->getPrecipIntensity());
	$tr .= sprintf("<td>%s l um %s</td>",$obj->getPrecipIntensityMax(),$obj->getPrecipIntensityMaxTime('H:i'));
	$tr .= "</tr>";
	return $tr;
}

function GetDailyConditionEntryTable4Header() {
	return "<tr class=header><td class=header>Zeit</td><td class=header>Sonnenaufgang</td><td class=header>Sonnenuntergang</td><td class=header>Mond Zyklus</td></tr>";
}

function GetDailyConditionEntryTable4($obj) {
	$tr = "<tr class='row'>";
	$tr .= sprintf("<td>%s</td>",$obj->getTime('D, d.m.Y'));
	$tr .= sprintf("<td>%s </td>",$obj->getSunrise('H:i'));
	$tr .= sprintf("<td>%s </td>",$obj->getSunset('H:i'));
	$tr .= sprintf("<td>%s </td>",$obj->getMoonPhase());
	$tr .= "</tr>";
	return $tr;
}

//=====================================================================================================================================

class ForecastIO {

  private $api_key;
  const API_ENDPOINT = 'https://api.forecast.io/forecast/';

  /**
   * Create a new instance
   *
   * @param String $api_key
   */
  function __construct($api_key) {
    $this->api_key = $api_key;
  }


  private function requestData($latitude, $longitude, $units, $language = 'auto', $timestamp = false, $exclusions = false) {

    $validUnits = array('auto', 'us', 'si', 'ca', 'uk');
    if (in_array($units, $validUnits)) {
      $request_url = self::API_ENDPOINT .
        $this->api_key . '/' .
        $latitude . ',' . $longitude .
        ( $timestamp ? ',' . $timestamp : '' ) .
        '?units=' . $units . '&lang=' . $language .
        ( $exclusions ? '&exclude=' . $exclusions : '' );

      //Use Buffer to cache API-requests if initialized * (if not, just get the latest data) More info: http://git.io/FoO2Qw
      if(class_exists('Buffer')) {
        $cache = new Buffer();
        $content = $cache->data($request_url);
      } else {
        //echo $request_url . "
";
        //$content = file_get_contents($request_url);
        $content = Sys_GetURLContent($request_url);
      }
    } else {
      return false;
    }
    if (!empty($content)) { return json_decode($content); } else { return false; }
  }

  //Will return the current conditions
  function getCurrentConditions($latitude, $longitude, $units = 'auto', $language) {

    $data = $this->requestData($latitude, $longitude, $units, $language);
    if ($data !== false) {
      return new ForecastIOConditions($data->currently);
    } else {
      return false;
    }
  }

  //Will return historical conditions for day of given timestamp
  function getHistoricalConditions($latitude, $longitude, $units = 'auto', $language, $timestamp) {

    $exclusions = 'currently,minutely,hourly,alerts,flags';
    $data = $this->requestData($latitude, $longitude, $units, $language, $timestamp, $exclusions);
    if ($data !== false) {
      return new ForecastIOConditions($data->daily->data[0]);
    } else {
      return false;
    }
  }

  //Will return conditions on hourly basis for today
  function getForecastToday($latitude, $longitude, $units = 'auto', $language) {

    $data = $this->requestData($latitude, $longitude, $units, $language);
    if ($data !== false) {
      $conditions = array();
      $today = date('Y-m-d');
      foreach ($data->hourly->data as $raw_data) {
        if (date('Y-m-d', $raw_data->time) == $today) {
          $conditions[] = new ForecastIOConditions($raw_data);
        }
      }
      return $conditions;
    } else {
      return false;
    }
  }

  //Will return daily conditions for next seven days
  function getForecastWeek($latitude, $longitude, $units = 'auto', $language) {

    $data = $this->requestData($latitude, $longitude, $units, $language);
    if ($data !== false) {
      $conditions = array();
      foreach ($data->daily->data as $raw_data) {
        $conditions[] = new ForecastIOConditions($raw_data);
      }
      return $conditions;
    } else {
      return false;
    }
  }
}


/**
 * Wrapper for get data by getters
 */
class ForecastIOConditions {

  private $raw_data;

  function __construct($raw_data) {
    $this->raw_data = $raw_data;
  }

  function getTemperature() {
		if(isset($this->raw_data->temperature)) { return $this->raw_data->temperature; } else { return "n.a."; }
  }

  function getTemperatureMin() {
		if(isset($this->raw_data->temperatureMin)) { return $this->raw_data->temperatureMin; } else { return "n.a."; }
  }

  function getTemperatureMinTime($format=null) {
      if (!isset($format)) { return $this->raw_data->temperatureMinTime; } else { return date($format, $this->raw_data->temperatureMinTime); }
  }

  function getTemperatureMax() {
		if(isset($this->raw_data->temperatureMax)) { return $this->raw_data->temperatureMax; } else { return "n.a."; }
  }

  function getTemperatureMaxTime($format=null) {
      if (!isset($format)) { return $this->raw_data->temperatureMaxTime; } else { return date($format, $this->raw_data->temperatureMaxTime); }
  }

  function getApparentTemperature() {
		if(isset($this->raw_data->apparentTemperature)) { return $this->raw_data->apparentTemperature; } else { return "n.a."; }
  }

  function getapparentTemperatureMin() {
		if(isset($this->raw_data->apparentTemperatureMin)) { return $this->raw_data->apparentTemperatureMin; } else { return "n.a."; }
  }

  function getapparentTemperatureMinTime($format=null) {
      if (!isset($format)) { return $this->raw_data->apparentTemperatureMinTime; } else { return date($format, $this->raw_data->apparentTemperatureMinTime); }
  }

  function getapparentTemperatureMax() {
		if(isset($this->raw_data->apparentTemperatureMax)) { return $this->raw_data->apparentTemperatureMax; } else { return "n.a."; }
  }

  function getapparentTemperatureMaxTime($format=null) {
      if (!isset($format)) { return $this->raw_data->apparentTemperatureMaxTime; } else { return date($format, $this->raw_data->apparentTemperatureMaxTime); }
  }

  function getSummary() {
		if(isset($this->raw_data->summary)) {
			return iconv("UTF-8", "ISO-8859-1", $this->raw_data->summary);
		} else { return "n.a."; }
  }

  function getIcon() {
		if(isset($this->raw_data->icon)) { return $this->raw_data->icon; } else { return "n.a."; }
  }

  function getTime($format = null) {
    if (!isset($format)) { return $this->raw_data->time; } else { return date($format, $this->raw_data->time); }
  }

  function getPressure() {
		if(isset($this->raw_data->pressure)) { return $this->raw_data->pressure; } else { return "n.a."; }
  }

  function getDewPoint() {
		if(isset($this->raw_data->dewPoint)) { return $this->raw_data->dewPoint; } else { return "n.a."; }
  }

  function getHumidity() {
		if(isset($this->raw_data->humidity)) { return $this->raw_data->humidity; } else { return "n.a."; }
  }

  function getWindSpeed() {
		if(isset($this->raw_data->windSpeed)) { return $this->raw_data->windSpeed; } else { return "n.a."; }
  }

  function getWindBearing() {
		if(isset($this->raw_data->windBearing)) { return $this->raw_data->windBearing; } else { return "n.a."; }
  }

  function getPrecipitationType() {
		if(isset($this->raw_data->precipType)) { return $this->raw_data->precipType; } else { return "-"; }
  }

  function getPrecipitationProbability() {
		if(isset($this->raw_data->precipProbability)) { return $this->raw_data->precipProbability; } else { return "n.a."; }
  }

  function getPrecipIntensity() {
		if(isset($this->raw_data->precipIntensity)) { return $this->raw_data->precipIntensity; } else { return "n.a."; }
  }

  function getPrecipIntensityMax() {
		if(isset($this->raw_data->precipIntensityMax)) { return $this->raw_data->precipIntensityMax; } else { return "n.a."; }
  }

  function getPrecipIntensityMaxTime($format=null) {
	  	if(isset($this->raw_data->precipIntensityMaxTime)) {
			if (!isset($format)) { return $this->raw_data->precipIntensityMaxTime; } else { return date($format, $this->raw_data->precipIntensityMaxTime); }
		} else { return 0; }
  }

  function getCloudCover() {
		if(isset($this->raw_data->cloudCover)) { return $this->raw_data->cloudCover; } else { return "n.a."; }
  }

  function getOzone() {
		if(isset($this->raw_data->ozone)) { return $this->raw_data->ozone; } else { return "n.a."; }
  }

  function getSunrise($format=null) {
    	if (!isset($format)) { return $this->raw_data->sunriseTime; } else { return date($format, $this->raw_data->sunriseTime); }
  }

  function getSunset($format=null) {
  	 	if (!isset($format)) { return $this->raw_data->sunsetTime; } else { return date($format, $this->raw_data->sunsetTime); }
  }

  function getMoonPhase() {
		if(isset($this->raw_data->moonPhase)) { return $this->raw_data->moonPhase; } else { return "n.a."; }
  }

}

?>

Hallo MrMonk

Wenn du die Klassen ‚ForecastIO‘ und ‚ForecastIOConditions‘ in ein eigenes Skript auslagerst (bei mir 47626) dann bekommst du mit diesem Code die aktuelle Temperatur …



include_once(IPS_GetScript(47626 /*[Schnittstellen\Interfaces\Forecast.io\forecast.io Library]*/)['ScriptFile']);

$api_key = 'API Key hier eintragen';
$latitude = '48.3059';
$longitude = '14.2867';
$units = 'ca';  // Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
$lang = 'de'; // Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'

$forecast = new ForecastIO($api_key);
$condition = $forecast->getCurrentConditions($latitude, $longitude, $units, $lang);
echo "aktuelle Temperatur ist: " . $condition->getTemperature()," °C";


… hat sich erledigt.

ich könnte da noch was beisteuern:

bin bisher sehr zufrieden!