Aller au contenu

Recommended Posts

Pour ceux que cela intéresse, il existe un site web pour récupérer les prévisions météo en json.

=>  documentation : http://www.prevision-meteo.ch/uploads/pdf/recuperation-donnees-meteo.pdf

local lat = xx.xx;
local lng = x.x;

HC2 = Net.FHttp("www.prevision-meteo.ch",80);
-- documentation : http://www.prevision-meteo.ch/uploads/pdf/recuperation-donnees-meteo.pdf

local response, status, errorCode = HC2:GET("/services/json/lat=" .. lat .. "lng=" .. lng);

if (tonumber(errorCode) == 0)
then
  jsonTable = json.decode(response);
  fibaro:debug("aujourd'hui : " .. jsonTable.current_condition.tmp .. "°c - " .. jsonTable.current_condition.condition);
  fibaro:debug(jsonTable.fcst_day_1.day_short .. " : min : " .. jsonTable.fcst_day_1.tmin .. "°c - max : " .. jsonTable.fcst_day_1.tmax .. "°c - " .. jsonTable.fcst_day_1.condition);
  fibaro:debug(jsonTable.fcst_day_2.day_short .. " : min : " .. jsonTable.fcst_day_2.tmin .. "°c - max : " .. jsonTable.fcst_day_2.tmax .. "°c - " .. jsonTable.fcst_day_2.condition);
  fibaro:debug(jsonTable.fcst_day_3.day_short .. " : min : " .. jsonTable.fcst_day_3.tmin .. "°c - max : " .. jsonTable.fcst_day_3.tmax .. "°c - " .. jsonTable.fcst_day_3.condition);
  fibaro:debug(jsonTable.fcst_day_4.day_short .. " : min : " .. jsonTable.fcst_day_4.tmin .. "°c - max : " .. jsonTable.fcst_day_4.tmax .. "°c - " .. jsonTable.fcst_day_4.condition);  		
else 
  fibaro:debug("error "..errorCode ) 
end



  • Upvote 2

Partager ce message


Lien à poster
Partager sur d’autres sites

ca marche pas chez moi!!

 

j ai changé les ID par mon ID du modules pourtant  :rolleyes:

 

edit: je suis en V4.035

Partager ce message


Lien à poster
Partager sur d’autres sites

@casinos: C'est bien ton VD, mais pourquoi passer par des variables globales. J'ai zappé cette phase et ça marche très bien.

 

Une question pour les spécialistes: est-il possible de récupérer la position (latitude - longitude) définie dans la config pour ne pas la coder en dur ?

Partager ce message


Lien à poster
Partager sur d’autres sites

Super merci j'ai fais quelques modif comme l'id plus besoin de le renseigner j'ai aussi supprimer les variables globales

local lat = 48.92289; -- A Renseigner
local lng = 2.2858; -- A Renseigner
 
HC2 = Net.FHttp("www.prevision-meteo.ch",80);
-- documentation : http://www.prevision-meteo.ch/uploads/pdf/recuperation-donnees-meteo.pdf
 
local response, status, errorCode = HC2:GET("/services/json/lat=" .. lat .. "lng=" .. lng);
 
if (tonumber(errorCode) == 0)
then
jsonTable = json.decode(response);
fibaro:debug("aujourd'hui : " .. jsonTable.current_condition.tmp .. "°c - " .. jsonTable.current_condition.condition);
fibaro:debug(jsonTable.fcst_day_1.day_short .. " : min : " .. jsonTable.fcst_day_1.tmin .. "°c - max : " .. jsonTable.fcst_day_1.tmax .. "°c - " .. jsonTable.fcst_day_1.condition);
fibaro:debug(jsonTable.fcst_day_2.day_short .. " : min : " .. jsonTable.fcst_day_2.tmin .. "°c - max : " .. jsonTable.fcst_day_2.tmax .. "°c - " .. jsonTable.fcst_day_2.condition);
fibaro:debug(jsonTable.fcst_day_3.day_short .. " : min : " .. jsonTable.fcst_day_3.tmin .. "°c - max : " .. jsonTable.fcst_day_3.tmax .. "°c - " .. jsonTable.fcst_day_3.condition);
fibaro:debug(jsonTable.fcst_day_4.day_short .. " : min : " .. jsonTable.fcst_day_4.tmin .. "°c - max : " .. jsonTable.fcst_day_4.tmax .. "°c - " .. jsonTable.fcst_day_4.condition);
else
fibaro:debug("error "..errorCode )
end
     
--METEO_J = fibaro:getGlobalValue("jsonTable.current_condition.tmp").. " °C "
local METEO_J = ("aujourd'hui : " ..jsonTable.current_condition.tmp .."°c - " ..jsonTable.current_condition.condition);
local METEO_J1 = (jsonTable.fcst_day_1.day_short .. " : min : " .. jsonTable.fcst_day_1.tmin .. "°c - max : " .. jsonTable.fcst_day_1.tmax .. "°c - " .. jsonTable.fcst_day_1.condition);   
local METEO_J2 = (jsonTable.fcst_day_2.day_short .. " : min : " .. jsonTable.fcst_day_2.tmin .. "°c - max : " .. jsonTable.fcst_day_2.tmax .. "°c - " .. jsonTable.fcst_day_2.condition);
local METEO_J3 = (jsonTable.fcst_day_3.day_short .. " : min : " .. jsonTable.fcst_day_3.tmin .. "°c - max : " .. jsonTable.fcst_day_3.tmax .. "°c - " .. jsonTable.fcst_day_3.condition);
local METEO_J4 = (jsonTable.fcst_day_4.day_short .. " : min : " .. jsonTable.fcst_day_4.tmin .. "°c - max : " .. jsonTable.fcst_day_4.tmax .. "°c - " .. jsonTable.fcst_day_4.condition);

fibaro:call(fibaro:getSelfId(), "setProperty", "ui.Label1.value", METEO_J);
fibaro:call(fibaro:getSelfId(), "setProperty", "ui.Label2.value", METEO_J1);
fibaro:call(fibaro:getSelfId(), "setProperty", "ui.Label3.value", METEO_J2);
fibaro:call(fibaro:getSelfId(), "setProperty", "ui.Label4.value", METEO_J3);
fibaro:call(fibaro:getSelfId(), "setProperty", "ui.Label5.value", METEO_J4);
fibaro:call(fibaro:getSelfId(), "setProperty", "ui.Label211.value", os.date("%H:%M:%S"))
    --fibaro:debug(fibaro:getValue(262, "log"))
fibaro:log(METEO_J)
    fibaro:sleep(6*60*1000) -- 6 minutes

Partager ce message


Lien à poster
Partager sur d’autres sites

J'ai fait la même chose que toi. Reste la question aux spécialistes !!! ;)

 

Une question pour les spécialistes: est-il possible de récupérer la position (latitude - longitude) définie dans la config pour ne pas la coder en dur ?

 

En allant voir le pdf fourni pas bencol j'ai vu que dans les "conditions actuelles" il  y a une date et une heure. Je pense que c'est mieux d'afficher l'heure des prévisions plutôt que l'heure de la box.

Partager ce message


Lien à poster
Partager sur d’autres sites

@berale24

j'ai regarder dans la ip/docs/#!/settings/getLocation, j'ai trouvé l'api mais je sais pas comment faire....

Location {
houseNumber (integer, optional),
timezone (string, optional),
ntp (bool, optional),
ntpServer (string, optional),
date (Date, optional),
time (Time, optional),
latitude (string, optional),
longitude (string, optional),
city (string, optional),
temperatureUnit (string, optional),
windUnit (string, optional),
timeFormat (integer, optional),
dateFormat (string, optional)
}

Partager ce message


Lien à poster
Partager sur d’autres sites

voila l'api

http://"IPde la BOX"/api/settings/location

Partager ce message


Lien à poster
Partager sur d’autres sites

voila ce qu'il faut faire pour récupérer latitude et longitude

HC2 = Net.FHttp("127.0.0.1",80);
HC2:setBasicAuthentication("admin","xxxx");
local response, status, errorCode = HC2:GET("/api/settings/location");

if (tonumber(errorCode) == 0)
then
	jsonTable = json.decode(response);

  	fibaro:debug(jsonTable.latitude); 
  	fibaro:debug(jsonTable.longitude);
end

Partager ce message


Lien à poster
Partager sur d’autres sites

je pense que tu peux récuperer cela avec un json mais bon je suis sur plusieurs code en ce moment donc pas trop le temp

tu pourras mettre le code en ligne si tu le veux bien ;)

les docs fibaro sont dans ipbox/docs

Partager ce message


Lien à poster
Partager sur d’autres sites

oups avait pas vu @bencol :D

ben voila on y arrive

Partager ce message


Lien à poster
Partager sur d’autres sites

@bencol tu peux supprimer la ligne 2 et mettre "11111" au niveau du port

Partager ce message


Lien à poster
Partager sur d’autres sites

Bon, qqun nous fait le Virtual device àtélécharger en version finale :) ?

Partager ce message


Lien à poster
Partager sur d’autres sites

@Nico puisque l'on va être bientot cousin :D et oui Alsace - lorraine je vais te faire cela

Partager ce message


Lien à poster
Partager sur d’autres sites

Voila le module virtuel il n'y a rien a faire a ci juste avoir bien mis la latitude et la longitude dans les parametres de la hc2

 

Partager ce message


Lien à poster
Partager sur d’autres sites

@mprinfo : heuuu on a buggue en meme temps je pense ;-) 

Partager ce message


Lien à poster
Partager sur d’autres sites

@pepite tu as mis cela au début du code

HC2 = Net.FHttp("127.0.0.1",11111);

cela évite de mettre pas user et password

Partager ce message


Lien à poster
Partager sur d’autres sites

je vais mettre le code complet pour celui que ça intéresse

HC2 = Net.FHttp("127.0.0.1",11111);
local response, status, errorCode = HC2:GET("/api/settings/location");
 
if (tonumber(errorCode) == 0)
then
jsonTable = json.decode(response);
 
fibaro:debug(jsonTable.latitude);
fibaro:debug(jsonTable.longitude);
end

local lat = (jsonTable.latitude);
local lng = (jsonTable.longitude);
HC2 = Net.FHttp("www.prevision-meteo.ch",80);
-- documentation : http://www.prevision-meteo.ch/uploads/pdf/recuperation-donnees-meteo.pdf
 
local response, status, errorCode = HC2:GET("/services/json/lat=" .. lat .. "lng=" .. lng);
 
if (tonumber(errorCode) == 0)
then
jsonTable = json.decode(response);
fibaro:debug("aujourd'hui : " .. jsonTable.current_condition.tmp .. "°c - " .. jsonTable.current_condition.condition);
fibaro:debug(jsonTable.fcst_day_1.day_short .. " : min : " .. jsonTable.fcst_day_1.tmin .. "°c - max : " .. jsonTable.fcst_day_1.tmax .. "°c - " .. jsonTable.fcst_day_1.condition);
fibaro:debug(jsonTable.fcst_day_2.day_short .. " : min : " .. jsonTable.fcst_day_2.tmin .. "°c - max : " .. jsonTable.fcst_day_2.tmax .. "°c - " .. jsonTable.fcst_day_2.condition);
fibaro:debug(jsonTable.fcst_day_3.day_short .. " : min : " .. jsonTable.fcst_day_3.tmin .. "°c - max : " .. jsonTable.fcst_day_3.tmax .. "°c - " .. jsonTable.fcst_day_3.condition);
fibaro:debug(jsonTable.fcst_day_4.day_short .. " : min : " .. jsonTable.fcst_day_4.tmin .. "°c - max : " .. jsonTable.fcst_day_4.tmax .. "°c - " .. jsonTable.fcst_day_4.condition);
else
fibaro:debug("error "..errorCode )
end
     
--METEO_J = fibaro:getGlobalValue("jsonTable.current_condition.tmp").. " °C "
local METEO_J = ("aujourd'hui : " ..jsonTable.current_condition.tmp .."°c - " ..jsonTable.current_condition.condition);
local METEO_J1 = (jsonTable.fcst_day_1.day_short .. " : min : " .. jsonTable.fcst_day_1.tmin .. "°c - max : " .. jsonTable.fcst_day_1.tmax .. "°c - " .. jsonTable.fcst_day_1.condition);   
local METEO_J2 = (jsonTable.fcst_day_2.day_short .. " : min : " .. jsonTable.fcst_day_2.tmin .. "°c - max : " .. jsonTable.fcst_day_2.tmax .. "°c - " .. jsonTable.fcst_day_2.condition);
local METEO_J3 = (jsonTable.fcst_day_3.day_short .. " : min : " .. jsonTable.fcst_day_3.tmin .. "°c - max : " .. jsonTable.fcst_day_3.tmax .. "°c - " .. jsonTable.fcst_day_3.condition);
local METEO_J4 = (jsonTable.fcst_day_4.day_short .. " : min : " .. jsonTable.fcst_day_4.tmin .. "°c - max : " .. jsonTable.fcst_day_4.tmax .. "°c - " .. jsonTable.fcst_day_4.condition);

fibaro:call(fibaro:getSelfId(), "setProperty", "ui.Label1.value", METEO_J);
fibaro:call(fibaro:getSelfId(), "setProperty", "ui.Label2.value", METEO_J1);
fibaro:call(fibaro:getSelfId(), "setProperty", "ui.Label3.value", METEO_J2);
fibaro:call(fibaro:getSelfId(), "setProperty", "ui.Label4.value", METEO_J3);
fibaro:call(fibaro:getSelfId(), "setProperty", "ui.Label5.value", METEO_J4);
fibaro:call(fibaro:getSelfId(), "setProperty", "ui.Label211.value", os.date("%H:%M:%S"))
    --fibaro:debug(fibaro:getValue(262, "log"))
fibaro:log(METEO_J)

Partager ce message


Lien à poster
Partager sur d’autres sites

Nickels !

Partager ce message


Lien à poster
Partager sur d’autres sites

×