Page 1 sur 1

[Tuto]Météo Yahoo

Publié : 23 nov. 2015, 16:31
par fratton
Si comme moi vous n'êtes pas satisfait des infos météo obtenu par le capteur virtuel Weather Underground (qui se base sur des stations météo non professionnelle), voici un script PHP pour récupérer les infos météo de Yahoo qui à l'avantage de proposer un flux RSS.

il vous faut PHP5, sur Raspberry :

Code : Tout sélectionner

sudo apt-get update
sudo apt-get install php5
Dans domoticz, créer 2 capteurs virtuels et récupérer leur numéro d'index :
Un capteur Température, Hydrométrie, Pression atmosphérique, IDX = 99 dans l'exemple ci-dessous
Un capteur Vent, IDX = 100 dans l'exemple ci-dessous

Il vous faut ensuite le code WOEID de votre lieu d'habitation, pour le trouver : http://woeid.rosselliot.co.nz/
Par exemple : 615702 pour Paris

créer un fichier meteo.php en modifiant les variables :
$WOEID, $IPPORT et les $IDX

Code : Tout sélectionner

<?php
// Code WOEID à récupérer sur woeid.rosselliot.co.nz
$WOEID="615702";

// Adresse et port de Domoticz
$IPPORT="192.168.1.2:8080";

// Index Domoticz du capteur de température Humidité et Pression atmosphérique
$IDX_THP=99;

// Index Domoticz du capteur de Vent
$IDX_VENT=100;


$result = file_get_contents("http://xml.weather.yahoo.com/forecastrss?w=$WOEID&u=c");
$xml = simplexml_load_string($result);
$xml->registerXPathNamespace('yweather', 'http://xml.weather.yahoo.com/ns/rss/1.0');
$location = $xml->channel->xpath('yweather:location');
$wind =  $xml->channel->xpath('yweather:wind');
$atmosphere = $xml->channel->xpath('yweather:atmosphere');
$astronomy = $xml->channel->xpath('yweather:astronomy');
$units = $xml->channel->xpath('yweather:units');
$condition = $xml->channel->item->xpath('yweather:condition');

$location = $location[0];
$wind =  $wind[0];
$atmosphere = $atmosphere[0];
$astronomy = $astronomy[0];
$units = $units[0];
$condition = $condition[0];

// Capteur de Température Humidité et Pression atmosphérique dans Domoticz
$rTemp=$condition['temp'];
$rPres=$atmosphere['pressure'];
$rHumi=$atmosphere['humidity'];
$majdomoticz="http://$IPPORT/json.htm?type=command&param=udevice&idx=$IDX_THP&nvalue=0&svalue=$rTemp;$rHumi;0;$rPres;0";
echo file_get_contents($majdomoticz);

// Capteur de vent
$rVent=$wind['speed'];
$rDirec=$wind['direction'];
$rTempRessentie=$wind['chill']; ; // Temperature Windchill
$majdomoticz="http://$IPPORT/json.htm?type=command&param=udevice&idx=$IDX_VENT&nvalue=0&svalue=$rDirec;N;$rVent;0;$rTemp;$rTempRessentie";
echo file_get_contents($majdomoticz);
?>
Exécuter le script par la commande :

Code : Tout sélectionner

php5 -n meteo.php
Il ne reste plus qu'a exécuter la le script php toute les 5 minutes, par exemple par un cron.

Re: Météo Yahoo

Publié : 24 nov. 2015, 19:17
par heartblood
Cool! Merci! Je testerais ça pour voir la différence avec weather underground

Re: Météo Yahoo

Publié : 24 nov. 2015, 21:13
par atlantis007
bonjour
le script fonctionne très bien
mais j ai pb avec le crontab il ne se lance pas toute les 5 minute


*/5 * * * * /home/pi/domoticz/scripts/meteo.php

Re: Météo Yahoo

Publié : 24 nov. 2015, 22:00
par fratton
Heu, il te manque ça :

*/5 * * * * php5 -n /home/pi/domoticz/scripts/meteo.php

Re: Météo Yahoo

Publié : 23 juil. 2016, 18:11
par baumansp
Pour information Google a fermé l'accès à cette API en mars 2016

https://www.igorkromin.net/index.php/20 ... ppling-it/

Re: Météo Yahoo

Publié : 23 juil. 2016, 21:27
par papoo
baumansp a écrit :Pour information Google a fermé l'accès à cette API en mars 2016
ce ne serait pas plutot yahoo qui aurait fermé l'accès?

Re: Météo Yahoo

Publié : 25 juil. 2016, 21:19
par baumansp
papoo a écrit :
baumansp a écrit :Pour information Google a fermé l'accès à cette API en mars 2016
ce ne serait pas plutot yahoo qui aurait fermé l'accès?
Oui :) j'avais la tête ailleurs

Re: Météo Yahoo

Publié : 09 août 2016, 20:09
par kronotops
Bonjour tout le monde,

je remonte un peu le sujet car en fouillant un peu partout j'ai réussi à trouver un lien jquery exploitable par la suite... par contre mes compétences en codage ne sont pas encore assez poussées pour ça donc voici le lien des fois que quelqu'un arrive à sortir un LUA ou Python avec :

https://query.yahooapis.com/v1/public/y ... ormat=json

où les ...... correspondent au code woeid. Exemple pour chez moi :
https://query.yahooapis.com/v1/public/y ... ormat=json

je continue de bosser dessus et vous tiens au courant si j'arrive à quelque chose... :D

LUA : Météo Yahoo

Publié : 12 août 2016, 22:12
par papoo
j'ai pas mal galéré pour arriver à faire fonctionner quelque chose en lua

mais ça fonctionne
l'api ne donne pas les unités métriques il m'a fallu convertir
temp yahoo.png
temp yahoo.png (13.04 Kio) Consulté 15412 fois
à toi de jouer si tu souhaite ajouter d'autres infos
log yahoo.png
log yahoo.png (14.85 Kio) Consulté 15412 fois

Code : Tout sélectionner

--[[
name : script_time_yahoo.lua
auteur : papoo
version : 1.00
maj : 10/08/2016
date : 10/08/2016
 Ce script a pour but de remonter les informations météo du site https://www.yahoo.com/news/weather/ sur domoticz 
 URL post : http://easydomoticz.com/forum/viewtopic.php?f=17&t=1078#p20931
]]--
--------------------------------------------
------------ Variables à éditer ------------
-------------------------------------------- 
local WOEID='608140'  --L'API yahoo necessite un code WOEID. Pour trouver le code WOEID de votre lieu d'habitation, rendez vous sur : http://woeid.rosselliot.co.nz/

local dz_temp_hu_pre = 739   -- renseigner l'id du device Température Humidité et Pression atmosphérique associé si souhaité, sinon nil
local debugging = true     -- true pour voir les logs dans la console log Dz ou false pour ne pas les voir

--------------------------------------------
----------- Fin variables à éditer ---------
-------------------------------------------- 
local indexArray=0   

--------------------------------------------
---------------- Fonctions -----------------
-------------------------------------------- 
function voir_les_logs (s)
    if (debugging) then 
      if s ~= nil then
        print ("<font color='#f3031d'>".. s .."</font>");
      else
      print ("<font color='#f3031d'>aucune valeur affichable</font>");
      end
    end
end   

function round(value, digits)
  local precision = 10^digits
  return (value >= 0) and
      (math.floor(value * precision + 0.5) / precision) or
      (math.ceil(value * precision - 0.5) / precision)
end

function fahrenheit_to_celsius(fahrenheit, digits) 
    if fahrenheit ~= nil then
   return round((5/9) * (fahrenheit - 32), digits or 2)
   else
   print ("<font color='#f3031d'>pas de fahrenheit a convertir en celsius</font>");
   end
end
function miles_to_km(miles, digits) 
    if miles ~= nil then
   return round((miles * 1.609344), digits or 2)
   else
   print ("<font color='#f3031d'>pas de miles a convertir en km</font>");
   end
end

--------------------------------------------
-------------- Fin Fonctions ---------------
--------------------------------------------

commandArray = {}
now=os.date("*t")
if now.min % 5 == 0 then  -- exécution toutes les 5 minutes
voir_les_logs("script_time_yahoo.lua",debugging)


      local fname ="/tmp/yahoo.xml"
      os.execute("curl 'http://query.yahooapis.com/v1/public/yql?q=select+*+from+weather.forecast+where+woeid=".. WOEID .."&format=xml' > ".. fname .." && chmod 777 " .. fname)
      
      
      -- voir_les_logs("Fichier local : " ..fname,debugging)
      local f = io.open(fname, "r")

          if f == nil then
          print("Error opening file '" .. fname .. "'.")
          os.exit(1)
          end
 
      local xml = f:read("*all")
               f:close()


   for instance in xml:gmatch("<channel>(.-)</channel>") do 
   
   local distance_unit, pressure_unit, speed_unit, temp_unit = instance:match('<yweather:units.*distance="(.-)".*pressure="(.-)".*speed="(.-)".*temperature="(.-)"/>')
   local city, country, region = instance:match('<yweather:location.*city="(.-)".*country="(.-)".*region="(.-)"/>')
   local wind_chill, wind_direction, wind_speed = instance:match('<yweather:wind.*chill="(.-)".*direction="(.-)".*speed="(.-)"/>')
   local humidity, pressure= instance:match('<yweather:atmosphere.*humidity="(.-)".*pressure="(.-)"')
   local sunrise, sunset = instance:match('<yweather:astronomy.*sunrise="(.-)".*sunset="(.-)"/>')
   local temp = instance:match('<yweather.*condition.*temp="(.-)"')

   voir_les_logs("--- --- --- unite distance= "..distance_unit..", unite pression = "..pressure_unit..", unite vitesse = "..speed_unit..", unite temperature = "..temp_unit,debugging)

         voir_les_logs("--- --- --- Ville = "..city..", Pays = "..country..", Region = "..region,debugging)
         voir_les_logs("--- --- --- Temperature Ressentie = "..fahrenheit_to_celsius(wind_chill,1)..", direction du vent = "..wind_direction..", vitesse du vent = "..miles_to_km(wind_speed,1),debugging)
         voir_les_logs("--- --- --- humidite = "..humidity..", pression = "..pressure,debugging)
         voir_les_logs("--- --- --- lever soleil ="..sunrise..", coucher soleil = "..sunset,debugging)
         voir_les_logs("--- --- --- Temperature = "..fahrenheit_to_celsius(temp,1),debugging)


       if dz_temp_hu_pre ~= nil then  
          commandArray[indexArray] = {['UpdateDevice'] = dz_temp_hu_pre..'|0|'..fahrenheit_to_celsius(temp,1)..';'..humidity..';0;'..pressure..';0;'}
          indexArray=indexArray+1
       end

   end   


end
return commandArray

Re: Météo Yahoo

Publié : 13 août 2016, 19:44
par kronotops
Impeccable !!! C'est parfait tout fonctionne correctement :D Merci beaucoup.