Répondre à : Yahoo weather doesn`work anymore

Domotica gratuit Forums Report a bug Yahoo weather doesn`work anymore Répondre à : Yahoo weather doesn`work anymore



Hi there!
I found a solution for using a weather API.

1) register at https://openweathermap.org/
2) you will get a API-key
3) look for your loacal ID (e.g. Munich=2867714)
4) use this code in a PHP-Blockly:
$url = ‘http://api.openweathermap.org/data/2.5/weather?id=2867714&appid=YOUR_API-KEY&units=metric&lang=de’;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
‘Accept json/html’, ‘Content-Type text/html’
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 90);
$output = curl_exec($ch);
$filename = ‘OpenWeather.json’;
file_put_contents(“./”.$filename, $output);
5) you will get a file OpenWeather.jason
6) Use use this code in a PHP-Blockly for using the weather-datas:
$filename = ‘OpenWeather.json’;
$weather_json = file_get_contents(“./”.$filename);
$weather = json_decode($weather_json);

$weatherID = $weather->weather[0]->id;
$weatherMain= $weather->weather[0]->main;

//Umwandeln von Zeitstempel zu Stunden Minuten Sekunden
$sunrise = date(‘H:i:s’, $weather->sys->sunrise);

Good luck.

If you can have any questions feel free to ask