Aller au contenu

Yagda - Yet Another Graphic Data Analyser (Netatmo - Vmc - Emoncms - Json Viewer)


Messages recommandés

Posté(e)

J'ai encore beaucoup travaillé sur le script php et lua, je peux maintenant gérer aussi le thermostat netatmo et récupérer ses données.

  • Upvote 1
Posté(e)

Bonjour

J'ai un problème, je suis en V3.6 et je n'ai que les données du Netatmo intérieur mais je n’aie pas les données des Netatmo additionnel des autres pièces

le debug me donne :

 [DEBUG] 10:51:19: Récupération des données intérieures: true
[DEBUG] 10:51:19: Récupération des données extérieures : false
[DEBUG] 10:51:19: err: [string "-------------------------------------------..."]:73: Expected value but found T_END at character 1
[DEBUG] 10:51:19: Récupération des données intérieures Mod2: false
[DEBUG] 10:51:19: err: [string "-------------------------------------------..."]:161: Expected value but found T_END at character 1
[DEBUG] 10:51:20: Récupération des données intérieures Mod3: false
[DEBUG] 10:51:20: err: [string "-------------------------------------------..."]:204: Expected value but found T_END at character 1
[DEBUG] 10:51:20: Récupération des données intérieures Mod4: false
[DEBUG] 10:51:20: err: [string "-------------------------------------------..."]:247: Expected value but found T_END at character 1
[DEBUG] 10:51:22: Payload: /input/post.json?json={NETATMO_temperature_exterieure:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:22: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:22: Payload: /input/post.json?json={NETATMO_humidite_exterieure:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:22: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:22: Payload: /input/post.json?json={NETATMO_pression:1021.2}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:22: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:22: Payload: /input/post.json?json={NETATMO_bruit:39}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:22: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:23: Payload: /input/post.json?json={NETATMO_temperature_interieure_Salon:22.2}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:23: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:23: Payload: /input/post.json?json={NETATMO_temperature_int_mod2_Cuisine:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:23: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:24: Payload: /input/post.json?json={NETATMO_temperature_int_mod3_Chambre:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:24: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:24: Payload: /input/post.json?json={NETATMO_temperature_int_mod4_Bureau:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:24: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:25: Payload: /input/post.json?json={NETATMO_humidite_interieure_Salon:40}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:25: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:25: Payload: /input/post.json?json={NETATMO_humidite_int_mod2_Cuisine:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:25: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:26: Payload: /input/post.json?json={NETATMO_humidite_int_mod3_Chambre:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:26: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:27: Payload: /input/post.json?json={NETATMO_humidite_int_mod4_Bureau:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:27: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:27: Payload: /input/post.json?json={NETATMO_co2_Salon:504}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:27: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:28: Payload: /input/post.json?json={NETATMO_co2_mod2_Cuisine:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:28: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:28: Payload: /input/post.json?json={NETATMO_co2_mod3_Chambre:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:28: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:29: Payload: /input/post.json?json={NETATMO_co2_mod4_Bureau:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:29: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[ERROR] 10:51:29: line 374: attempt to compare number with string

Avez vous une idée ?

Merci par avance

Posté(e)

Bonjour Sebcbien

 

J'attends avec impatience :-) car je ne m'en sors pas depuis avec json avec le message Expected value but found T_END at character 1 dans mes autres script Netatmo, le tiens a l'air pas mal du tout :-)

 

 
Posté(e)

Réservé LUA Vfib

 

Comme promis, voici une nouvelle version, qui intègre aussi la possibilité de commander et lire les valeurs du thermostat Netatmo.

Il y a en effet deux nouveaux boutons et deux lignes d'infos en plus. Ils permettent de commander le thermostat (j'utilise les boutons away/program avec le mode away/present de la maison, ainsi quand je ne suis pas là , pas de chauffage, c'est automatique, une chose de moins à  penser, UNE !)

 

Afin de permettre une migration facile, j'ai créé un fichier php différent (thermtatmo.php) et vous pouvez charger le nouveau virtual device en plus de votre setup actuel.

Une fois que tout marchera, modifiez simplement la ligne

local EmonCMS_Prefix = "NETATMO_TEST_REMOVE_WHEN_OK_" 

en local EmonCMS_Prefix = "NETATMO_"

et désactivez (ou effacez) l'ancien Virtual device.

(N'oubliez pas de modifier le script qui appuye toutes les 5 minutes sur le bouton update..)

 

Vos graphiques emoncms continueront à  être mis à  jour comme si de rien n'était, sans coupure.

 

Voici le virtual device:

Netatmo_Thermostat.vfib

Screenshot:

post-826-0-47786900-1427544158_thumb.png

Pour cette version, il faut utiliser le nouveau code php (thermtatmo.php) qui ajoute plein de fonction et une "aide" intégrée. Voir post suivant.

Code principal (bouton update):

J'ai essayé de commenter le code le plus possible, normalement avec ces commentaires, l'utilisation de ces scripts ne devrait pas trop poser de problème.

Si vous avez besoin de précisions, demandez ;)

-----------------------------------------------------------------------------------------
-- Thermtatmo v3
-- Retreive Netatmo values for more than 2 modules, compute CO2 and push to EmonCMS
-- Sebastien Jauquet
-- Février 2015
-- Thanks to cedriclocqueneux, krikroff, i-magin and all contibutors to the netatmo code
-----------------------------------------------------------------------------------------

-- Instructions:
-- Create an free emoncms.org account
-- Retrieve your Write API Key from it
-- Create a Global variable (undefined) -> CO2_Max_Value to store the max value of CO2 of the house - if you dont need this, set CO2 to false (default: 0)
-- Install my thermtatmo.php in your webserver and write his address in the ip Address of this module
-- for each value you want to be pushed to emoncms, modify the section -- Push To EMONCMS -- below
-- Create a block scene or use gea to click this button each 10 minutes (to avoid rejection from the api of Netatmo)
-- V2.01 -- First released version
-- V2.2 -- doesn't push to emonCMS if netatmo query return false
-- V2.3 -- added push message to phone if error
-- V3 -- changed name and added Netatmo thermostat retrieve and push modes away and program
-- V3.1 -- Added customisation options for code Sharing

local id = {
PHONE_SEB		= 1323,
PHONE_GG		= 53
	}
-- Prefix of the id of the inputs to be created in emoncms
-- Use this for testing to not mess your current feeds with wrong values while testing
-- When everything is ok, restore original prefix. I suggest "NETATMO_" and delete on emoncms the inputs created for testing
-- local EmonCMS_Prefix = "NETATMO_"
local EmonCMS_Prefix = "NETATMO_TEST_REMOVE_WHEN_OK_" 
-------------------------------------------------------------------------
local PushToEmonCMS = true -- true = push to emoncms - false = do not push
local Thermostat = true -- true = get thermostat values - false = do not get them
local VMC = true -- true = set in Global variable CO2_Max_Value the Max CO2 Value
local selfId = fibaro:getSelfId();
local thismodule=fibaro:getSelfId()
local domaine = fibaro:get(selfId, 'IPAddress')
local PushItem
local DoNotPush_Error = false
local activatePush = true; -- activate push when netatmo error detected 
local ID_Smartphones = {id["PHONE_SEB"]}; -- list of device receiving Push
local CO2_Max_Value_Local = 0 -- if you dont need this, set CO2 to false (default: 0)
local emoncms = Net.FHttp("emoncms.org",80)
local emoncms_api_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -- your EMONCMS WRITE api Key

EmonCMS = {}; 
 
if (temperature_exterieure==nil) then temperature_exterieure = ""; end
if (humidite_exterieure==nil) then humidite_exterieure = ""; end

if (temperature_interieure==nil) then temperature_interieure = ""; end
if (humidite_interieure==nil) then humidite_interieure = ""; end
if (co2==nil) then co2 = ""; end
if (pression==nil) then pression = ""; end
if (bruit==nil) then bruit = ""; end

if (temperature_int_mod2==nil) then temperature_int_mod2 = ""; end
if (humidite_int_mod2==nil) then humidite_int_mod2 = ""; end
if (co2_mod2==nil) then co2_mod2 = ""; end

if (temperature_int_mod3==nil) then temperature_int_mod3 = ""; end
if (humidite_int_mod3==nil) then humidite_int_mod3 = ""; end
if (co2_mod3==nil) then co2_mod3 = ""; end

if (temperature_int_mod4==nil) then temperature_int_mod4 = ""; end
if (humidite_int_mod4==nil) then humidite_int_mod4 = ""; end
if (co2_mod4==nil) then co2_mod4 = ""; end 

if (temperature_therm1==nil) then temperature_therm1 = ""; end
if (temperature_setpoint_therm1==nil) then temperature_setpoint_therm1 = ""; end
if (relay_therm1==nil) then relay_therm1 = ""; end
if (temperature_max==nil) then temperature_max = ""; end
if (temperature_min==nil) then temperature_min = ""; end

if(refreshUI==nil) then -- Loads in memory only the first occurence
function refreshUI(therm, therm1, ext, bruit, titre, tempmod, co2mod, humidmod, lastupdate, laststatus)
  fibaro:call(selfId,"setProperty","ui.thermstatus.value",therm);
  fibaro:call(selfId,"setProperty","ui.thermostat1.value",therm1);
  fibaro:call(selfId,"setProperty","ui.ext.value",ext);
  fibaro:call(selfId,"setProperty","ui.bruit.value",bruit);  
  fibaro:call(selfId,"setProperty","ui.titre.value",titre);  
  fibaro:call(selfId,"setProperty","ui.tempmod.value",tempmod);  
  fibaro:call(selfId,"setProperty","ui.co2mod.value",co2mod);  
  fibaro:call(selfId,"setProperty","ui.humidmod.value",humidmod);  
  fibaro:call(selfId,"setProperty","ui.lastupdate.value",lastupdate);      
  fibaro:call(selfId,"setProperty","ui.laststatus.value",laststatus);   
end;
end

pushMessage = function (sendPush) 
	if (activatePush) then 
		for i=1, #ID_Smartphones do 
		  fibaro:call(tonumber(ID_Smartphones[i]), 'sendPush', sendPush); 
		  fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", "orange", "Push message ("..sendPush..") sent to mobile: "..tonumber(ID_Smartphones[i]), "span")); 
		end 
	end 
end

if(getTherm1==nil) then -- Loads in memory only the first occurence
function getTherm1(retry)
  retry = retry or 0
  -- Setting up the connection data
  local FHTE = Net.FHttp(domaine, 80);
  -- Netatmo extérieur
  local response = FHTE:GET("/netatmo/thermtatmo.php?parameter=therm1");
  -- decoding json string to table
  if (response~= nil) then
    local result = nil;
    result = json.decode(response);
    if (result ~= nil) then
      -- prevent: attempt to index field 'body' (a nil value)
      if (result.body ~= nil) then
        temperature_therm1 = result.body.measured.temperature or "n.c";
		--fibaro:debug(temperature_therm1)
        temperature_setpoint_therm1 = result.body.measured.setpoint_temp or "n.c";
		--fibaro:debug(temperature_setpoint_therm1)
		relay_therm1 = result.body.therm_relay_cmd or "n.c";
		--fibaro:debug(relay_therm1)
		-- variable globale pour info sms
        local msg = "Température Thermostat 1 : "..temperature_therm1.."°C";
        --fibaro:setGlobal("tempext", msg);
        return true;
      else
        fibaro:debug("Netatmo Therm1: erreur le " .. os.date());
        if (result.error ~= nil) then
          fibaro:debug("error code: "..result.error.code..", message: "..result.error.message);
        end
      end
    else
      fibaro:debug("Netatmo Therm1: erreur decodage json le " .. os.date());
    end
  else
    fibaro:debug("Netatmo Therm1:la reponse est null !");
  end
  if ((retry or 5)< 5) then
    fibaro:debug("Retry #"..retry.."process, please wait...");
    fibaro:sleep(5000);
    return getInt(tonumber(retry+1));
  else
      return false;
  end
end;
 
end

if(getExt==nil) then -- Loads in memory only the first occurence
function getExt(retry)
  retry = retry or 0
  -- Setting up the connection data
  local FHTE = Net.FHttp(domaine, 80);
  -- Netatmo extérieur
  local response = FHTE:GET("/netatmo/thermtatmo.php?parameter=ext");
  -- decoding json string to table
  if (response~= nil) then
    local result = nil;
    result = json.decode(response);
    if (result ~= nil) then
      -- prevent: attempt to index field 'body' (a nil value)
      if (result.body ~= nil) then
        temperature_exterieure = result.body[1].value[1][1] or "n.c";
        humidite_exterieure =result.body[1].value[1][2] or "n.c";
        -- variable globale pour info sms
        local msg = "Température extérieure : "..temperature_exterieure.."°C";
        fibaro:setGlobal("tempext", msg);
        return true;
      else
        fibaro:debug("Netatmo EXT: erreur le " .. os.date());
        if (result.error ~= nil) then
          fibaro:debug("error code: "..result.error.code..", message: "..result.error.message);
        end
      end
    else
      fibaro:debug("Netatmo EXT: erreur decodage json le " .. os.date());
    end
  else
    fibaro:debug("Netatmo EXT:la reponse est null !");
  end
  if ((retry or 5)< 5) then
    fibaro:debug("Retry #"..retry.."process, please wait...");
    fibaro:sleep(5000);
    return getInt(tonumber(retry+1));
  else
      return false;
  end
end;
 
end
 
if(getInt==nil) then -- Loads in memory only the first occurence
function getInt(retry)
  retry = retry or 0;
  -- Setting up the connection data
  local FHTE = Net.FHttp(domaine, 80);
  -- Netatmo intérieur
  local response = FHTE:GET("/netatmo/thermtatmo.php?parameter=int");
  -- decoding json string to table
  if (response~= nil) then
    local result = nil;
    result = json.decode(response);
    if (result ~= nil) then
      -- prevent: attempt to index field 'body' (a nil value)
      if (result.body ~= nil) then
        temperature_interieure = result.body[1].value[1][1] or "n.c";
        humidite_interieure = result.body[1].value[1][3] or "n.c";          
        co2 = result.body[1].value[1][2] or "n.c";
        pression = result.body[1].value[1][4] or "n.c";
        bruit = result.body[1].value[1][5] or "n.c";
        -- variable globale pour info sms
        fibaro:setGlobal("tempint", "Température intérieure : "..temperature_interieure.."°C");
        return true;
      else
        fibaro:debug("Netatmo INT: erreur le " .. os.date());
        if (result.error ~= nil) then
          fibaro:debug("error code: "..result.error.code..", message: "..result.error.message);
        end
      end
    else
      fibaro:debug("Netatmo INT: erreur decodage json le " .. os.date());
    end
  else
    fibaro:debug("Netatmo INT:la reponse est null !");
  end
  if ((retry or 5)< 5) then
    fibaro:debug("Retry #"..retry.."process, please wait...");
    fibaro:sleep(5000);
    return getExt(tonumber(retry+1));
  else
      return false;
  end
end;
 
end

if(getMod2==nil) then -- Loads in memory only the first occurence 
function getMod2(retry)
  retry = retry or 0;
  -- Setting up the connection data
  local FHTE = Net.FHttp(domaine, 80);
  -- Netatmo intérieur
  local response = FHTE:GET("/netatmo/thermtatmo.php?parameter=mod2");
  -- decoding json string to table
  if (response~= nil) then
    local result = nil;
    result = json.decode(response);
    if (result ~= nil) then
      -- prevent: attempt to index field 'body' (a nil value)
      if (result.body ~= nil) then
        temperature_int_mod2 = result.body[1].value[1][1] or "n.c";
        humidite_int_mod2 = result.body[1].value[1][2] or "n.c";          
        co2_mod2 = result.body[1].value[1][3] or "n.c";
        -- variable globale pour info sms
        -- fibaro:setGlobal("tempint", "Température intérieure : "..temperature_interieure.."°C");
        return true;
      else
        fibaro:debug("Netatmo INT_mod2: erreur le " .. os.date());
        if (result.error ~= nil) then
          fibaro:debug("error code: "..result.error.code..", message: "..result.error.message);
        end
      end
    else
      fibaro:debug("Netatmo INT_mod2: erreur decodage json le " .. os.date());
    end
  else
    fibaro:debug("Netatmo INT_mod2:la reponse est null !");
  end
  if ((retry or 5)< 5) then
    fibaro:debug("Retry #"..retry.."process, please wait...");
    fibaro:sleep(5000);
    return getExt(tonumber(retry+1));
  else
      return false;
  end
end;
 
end

if(getMod3==nil) then -- Loads in memory only the first occurence 
function getMod3(retry)
  retry = retry or 0;
  -- Setting up the connection data
  local FHTE = Net.FHttp(domaine, 80);
  -- Netatmo intérieur
  local response = FHTE:GET("/netatmo/thermtatmo.php?parameter=mod3");
  -- decoding json string to table
  if (response~= nil) then
    local result = nil;
    result = json.decode(response);
    if (result ~= nil) then
      -- prevent: attempt to index field 'body' (a nil value)
      if (result.body ~= nil) then
        temperature_int_mod3 = result.body[1].value[1][1] or "n.c";
        humidite_int_mod3 = result.body[1].value[1][2] or "n.c";          
        co2_mod3 = result.body[1].value[1][3] or "n.c";
        -- variable globale pour info sms
        -- fibaro:setGlobal("tempint", "Température intérieure : "..temperature_interieure.."°C");
        return true;
      else
        fibaro:debug("Netatmo INT_mod3: erreur le " .. os.date());
        if (result.error ~= nil) then
          fibaro:debug("error code: "..result.error.code..", message: "..result.error.message);
        end
      end
    else
      fibaro:debug("Netatmo INT_mod3: erreur decodage json le " .. os.date());
    end
  else
    fibaro:debug("Netatmo INT_mod3:la reponse est null !");
  end
  if ((retry or 5)< 5) then
    fibaro:debug("Retry #"..retry.."process, please wait...");
    fibaro:sleep(5000);
    return getExt(tonumber(retry+1));
  else
      return false;
  end
end;
 
end

if(getMod4==nil) then -- Loads in memory only the first occurence 
function getMod4(retry)
  retry = retry or 0;
  -- Setting up the connection data
  local FHTE = Net.FHttp(domaine, 80);
  -- Netatmo intérieur
  local response = FHTE:GET("/netatmo/thermtatmo.php?parameter=mod4");
  -- decoding json string to table
  if (response~= nil) then
    local result = nil;
    result = json.decode(response);
    if (result ~= nil) then
      -- prevent: attempt to index field 'body' (a nil value)
      if (result.body ~= nil) then
        temperature_int_mod4 = result.body[1].value[1][1] or "n.c";
        humidite_int_mod4 = result.body[1].value[1][2] or "n.c";          
        co2_mod4 = result.body[1].value[1][3] or "n.c";
        -- variable globale pour info sms
        -- fibaro:setGlobal("tempint", "Température intérieure : "..temperature_interieure.."°C");
        return true;
      else
        fibaro:debug("Netatmo INT_mod4: erreur le " .. os.date());
        if (result.error ~= nil) then
          fibaro:debug("error code: "..result.error.code..", message: "..result.error.message);
        end
      end
    else
      fibaro:debug("Netatmo INT_mod4: erreur decodage json le " .. os.date());
    end
  else
    fibaro:debug("Netatmo INT_mod4:la reponse est null !");
  end
  if ((retry or 5)< 5) then
    fibaro:debug("Retry #"..retry.."process, please wait...");
    fibaro:sleep(5000);
    return getExt(tonumber(retry+1));
  else
      return false;
  end
end;
 
end

function EmonCMS:Push(payloademon)
payloademon = "/input/post.json?json={" .. EmonCMS_Prefix .. payloademon .. "}&apikey=" .. emoncms_api_key
response, status, errorCode = emoncms:GET(payloademon);
fibaro:debug("Payload: " .. payloademon) ;
fibaro:debug("response: " .. response .. " Status: " .. status .. " errorcode: " .. errorCode) ;
fibaro:sleep(500);
end

local function main()
  -- retrieve values from thermtatmo.php (res = result) add or remove the one you need
  local resTherm1, resInt, resExt, resMod2, resMod3, resMod4 = false, false, false, false, false, false;
  
  if Thermostat == true then  
	local status, err = pcall(function () resTherm1 = getTherm1(); end);
	  fibaro:debug("Récupération des valeurs du Thermostat 1: " .. tostring(resTherm1));
	  if (status == false) then
		DoNotPush_Error = true;
		fibaro:debug("err: "..tostring(err or 'n.c'));
	  end
  end
  
  local status, err = pcall(function () resInt = getInt(); end);
  fibaro:debug("Récupération des données intérieures: " .. tostring(resInt));
  if (status == false) then
	DoNotPush_Error = true;
    fibaro:debug("err: "..tostring(err or 'n.c'));
  end

  local status, err = pcall(function () resExt = getExt(); end);
  fibaro:debug("Récupération des données extérieures : " .. tostring(resExt));
  if (status == false) then
	DoNotPush_Error = true;
    fibaro:debug("err: "..tostring(err or 'n.c'));
  end

  local status, err = pcall(function () resMod2 = getMod2(); end);
  fibaro:debug("Récupération des données intérieures Mod2: " .. tostring(resMod2));
  if (status == false) then
	DoNotPush_Error = true;
    fibaro:debug("err: "..tostring(err or 'n.c'));
  end
  
  local status, err = pcall(function () resMod3 = getMod3(); end);
  fibaro:debug("Récupération des données intérieures Mod3: " .. tostring(resMod3));
  if (status == false) then
	DoNotPush_Error = true;
    fibaro:debug("err: "..tostring(err or 'n.c'));
  end
  
  local status, err = pcall(function () resMod4 = getMod4(); end);
  fibaro:debug("Récupération des données intérieures Mod4: " .. tostring(resMod4));
  if (status == false) then
	DoNotPush_Error = true;
    fibaro:debug("err: "..tostring(err or 'n.c'));
  end
fibaro:debug("1")
if DoNotPush_Error == false then
		-- if no retreive values error from netatmo, then display values in the virtual device and push to emon cms
		-- add or remove in the right order and separated by comma the definition of the display in the VD (definition of the array for the refresh ui function)
		
		-- calculate Min and Max temperature:
	  if Thermostat == false then
		fibaro:debug("not calculating Temp Max & Min Values")
	  else
		temperature_max = temperature_interieure
		if temperature_int_mod2 > temperature_max then temperature_max = temperature_int_mod2 end
		if temperature_int_mod3 > temperature_max then temperature_max = temperature_int_mod3 end
		if temperature_int_mod4 > temperature_max then temperature_max = temperature_int_mod4 end
 		temperature_min = temperature_interieure
		if temperature_int_mod2 < temperature_min then temperature_min = temperature_int_mod2 end
		if temperature_int_mod3 < temperature_min then temperature_min = temperature_int_mod3 end
		if temperature_int_mod4 < temperature_min then temperature_min = temperature_int_mod4 end
	  end
		-- call function refresh ui with retreived parameters:
	  refreshUI(
		"T° Therm - SetPoint - Max - Min",
		temperature_therm1.." Relais: "..relay_therm1.." - "..temperature_setpoint_therm1.." - "..temperature_max.." - "..temperature_min,
		"Ext: "..temperature_exterieure.." °C - "..humidite_exterieure.." % - "..pression.." mbar", 
		"Bruit Rez: "..bruit.." dB",
		"Rez - Emilien - Thomas - Parents",
		temperature_interieure.." - "..temperature_int_mod2.." - "..temperature_int_mod3.." - "..temperature_int_mod4.." °C ",
		co2.." - "..co2_mod2.." - "..co2_mod3.." - "..co2_mod4.." ppm",
		humidite_interieure.." - "..humidite_int_mod2.." - "..humidite_int_mod3.." - "..humidite_int_mod4.." % ",
		os.date("%H:%M"),
		tostring(resInt).." "..tostring(resExt).." "..tostring(resMod2).." "..tostring(resMod3).." "..tostring(resMod4)
		);
		-- Push To EMONCMS --
		-- Syntax: payload = set label of input on emoncms .. variable containing the value
	  if PushToEmonCMS == true then
	    if Thermostat == true then  
			payloademon = "temperature_1er:"..temperature_therm1
				EmonCMS:Push(payloademon);
			payloademon = "temperature_set_point_1er:".. temperature_setpoint_therm1
				EmonCMS:Push(payloademon);
			payloademon = "relais_chaudiere_1er:".. relay_therm1
				EmonCMS:Push(payloademon);
		end
		payloademon = "temperature_exterieure:"..temperature_exterieure
			EmonCMS:Push(payloademon);
		payloademon = "humidite_exterieure:".. humidite_exterieure
			EmonCMS:Push(payloademon);
		payloademon = "pression:".. pression
			EmonCMS:Push(payloademon);
		payloademon = "bruit:".. bruit
			EmonCMS:Push(payloademon);
		payloademon = "temperature_interieure_Rez:".. temperature_interieure
			EmonCMS:Push(payloademon);
		payloademon = "temperature_int_mod2_Emilien:".. temperature_int_mod2
			EmonCMS:Push(payloademon);
		payloademon = "temperature_int_mod3_Thomas:".. temperature_int_mod3
			EmonCMS:Push(payloademon);
		payloademon = "temperature_int_mod4_Parents:".. temperature_int_mod4
			EmonCMS:Push(payloademon);
		payloademon = "humidite_interieure_Rez:".. humidite_interieure
			EmonCMS:Push(payloademon);
		payloademon = "humidite_int_mod2_Emilien:".. humidite_int_mod2
			EmonCMS:Push(payloademon);
		payloademon = "humidite_int_mod3_Thomas:".. humidite_int_mod3
			EmonCMS:Push(payloademon);
		payloademon = "humidite_int_mod4_Parents:".. humidite_int_mod4
			EmonCMS:Push(payloademon);
		payloademon = "co2_Rez:".. co2
			EmonCMS:Push(payloademon);
		payloademon = "co2_mod2_Emilien:".. co2_mod2
			EmonCMS:Push(payloademon);
		payloademon = "co2_mod3_Thomas:".. co2_mod3
			EmonCMS:Push(payloademon);
		payloademon = "co2_mod4_Parents:".. co2_mod4
			EmonCMS:Push(payloademon);
	  end
	if VMC == true then  
		-- Compute Value MAX CO2 Maison, store in global variable (to adjust the VMC Speed in another VD)
		  if CO2_Max_Value_Local == false then
			fibaro:debug("not calculating nor storing CO2 Max Value")
		  else
			CO2_Max_Value_Local = co2
			if CO2_Max_Value_Local < co2_mod2 then CO2_Max_Value_Local = co2_mod2 end
			if CO2_Max_Value_Local < co2_mod3 then CO2_Max_Value_Local = co2_mod3 end
			if CO2_Max_Value_Local < co2_mod4 then CO2_Max_Value_Local = co2_mod4 end
			if tonumber(fibaro:getGlobalValue("CO2_Max_Value")) == CO2_Max_Value_Local then CO2_Max_Value_Local = CO2_Max_Value_Local +1; fibaro:debug("added 1 to Max CO2"); end -- so CO2_Max_Value_Local is not the same between measures and global var is modified and can be detected in other scenes
			fibaro:setGlobal("CO2_Max_Value", CO2_Max_Value_Local )
			fibaro:debug("CO2_Max_Value: ".. CO2_Max_Value_Local )  
		  end
	end
else
	-- if error detected, to not push to emoncms and push message to phone
	fibaro:debug("push error")
	pushMessage("Error with netatmo device. resInt:" .. tostring(resInt).." resExt:"..tostring(resExt).." resMod2:"..tostring(resMod2).." resMod3:"..tostring(resMod3).." resMod4:"..tostring(resMod4).." resTherm1:"..tostring(resTherm1));
end
end

-- launch
main();
Posté(e)

Et voici le nouveau code PHP (fichier termtatmo.php)

Mode d'emploi:

Remplir les valeurs personelles: XXXXXXXXXXXXXXXXX dans le code ci-dessous

Losqu'il est exécuté sans paramètre, une page d'aide apparait:

Exemple de retour avec http:// 192.165.10.102 /netatmo/thermtatmo.php (192.165.10.102 étant l'adressi IP de mon serveur Web)


Available parameters: 

For Netatmo thermostat: 

http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json_viewer_therm'>http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json_viewer_therm
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=xml_therm
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json_therm'>http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json_therm
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=names_therm'>http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=names_therm
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=therm1
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=therm1_set_away
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=therm1_set_program


For Netatmo Weather:

http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json_viewer
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=names
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=selected_modules
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=int
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=ext
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=mod2
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=mod3
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=mod4 
 

le parametre jsonviewer permet de "débuger" et va retourner le json reçu par netatmo et l'afficher dans un json viewer.

Voici mon retour de la page http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json_viewer

post-826-0-74143100-1427546570_thumb.png

Avec le json viewer il est plus facile de s'y retrouver

Ainsi vous pourrez modifier la section pour l'adapter à  votre setup (j'ai des valeurs différentes car j'ai deux stations de base netatmo et donc les ID changent)

Allez-y mollo avec les exécutions car l'api de netatmo bloque après trop de demandes par minutes...

$module_interne = $json_devices["body"]["devices"][0]["_id"];
$module_externe = $json_devices["body"]["modules"][1]["_id"];
$module_interne2 = $json_devices["body"]["modules"][2]["_id"];
$module_interne3 = $json_devices["body"]["modules"][3]["_id"];
$module_interne4 = $json_devices["body"]["modules"][4]["_id"];

Script PHP:

thermtatmo.zip

<?php
//ini_set('display_errors', false);
//set_exception_handler('ReturnError');

$parameter=$_GET['parameter'];
$password="XXXXXXXXXXXXXX"; // netatmo password
$username="XXXXXXXXXXX@XXXXXXXXXXXXXXX.com"; // netatmo username
$app_id = "XXXXXXXXXXXXXXXXXXXXXX"; // netatmo
$app_secret = "XXXXXXXXXXXXXXXXXXXXXX"; // netatmo
$token_url = "https://api.netatmo.net/oauth2/token";
$postdata = http_build_query(
        array(
            'grant_type' => "password",
            'client_id' => $app_id,
            'client_secret' => $app_secret,
            'username' => $username,
            'password' => $password,
            'scope' => 'read_station read_thermostat write_thermostat'
    )
);

$opts = array('http' =>
	array(
		'method'  => 'POST',
		'header'  => 'Content-type: application/x-www-form-urlencoded',
		'content' => $postdata
	)
);

$context  = stream_context_create($opts);
$response = file_get_contents($token_url, false, $context);
$params = null;
$params = json_decode($response, true);

// Section For Thermostat --------------------------------------
$therm_api_url = "https://api.netatmo.net/api/getuser?access_token=" . $params['access_token']."&app_type=app_thermostat";
$therm_requete = @file_get_contents($therm_api_url);
$therm_url_devices = "https://api.netatmo.net/api/devicelist?access_token=" .  $params['access_token']."&app_type=app_thermostat";
$therm_resulat_device = @file_get_contents($therm_url_devices);	
$therm_json_devices = json_decode($therm_resulat_device,true);
$therm1_device = $therm_json_devices["body"]["modules"][0]["_id"];
$therm1_relay = $therm_json_devices["body"]["devices"][0]["_id"];

if ($parameter == "json_viewer_therm") {
print('    
<html>
<style type="text/css">
    body {
      font: 11pt arial;
    }
    #jsoneditor {
      width: 800px;
      height: 2000px;
    }
</style>
<head>
    <title><YAGDA></title>
</head>
<body>
');
	echo "nombre de devices Thermostat: " . count($therm_json_devices["body"]["devices"]) . "<br>";
		for ($i = 0; $i <= count($therm_json_devices["body"]["devices"]) - 1; $i++) {
			echo "Station Name: " . $therm_json_devices["body"]["devices"][$i]["station_name"];
			echo " - Device No: " . $i ." id: " . $therm_json_devices["body"]["devices"][$i]["_id"] . " Name: " . $therm_json_devices["body"]["devices"][$i]["module_name"] . "<br>";
		}
	echo "<br>nombre de modules Thermostat: " . count($therm_json_devices["body"]["modules"]) . "<br>";
		for ($i = 0; $i <= count($therm_json_devices["body"]["modules"]) - 1; $i++) {
			echo "Parent Device: " . $therm_json_devices["body"]["modules"][$i]["main_device"];
			echo " - Module No: " . $i ." id: " . $therm_json_devices["body"]["modules"][$i]["_id"] . " Name: " . $therm_json_devices["body"]["modules"][$i]["module_name"] . "<br>";
		}

print('
<br>
<link rel="stylesheet" type="text/css" href="jsoneditor/jsoneditor.css"/>
<script src="jsoneditor/jsoneditor.js"></script>
<div id="jsoneditor"></div>
<script>
  var container = document.getElementById(\'jsoneditor\');
  var options = {
    mode: "view"
  };
  var json = ');

  echo $therm_resulat_device;

  print('
  var editor = new jsoneditor.JSONEditor(container, options, json);
</script>
');
}
if ($parameter == "xml_therm") {
// setup Station continue
$device1 = $therm_json_devices["body"]["modules"][0]["main_device"];
$module1 = $therm_json_devices["body"]["modules"][0]["_id"];
//$device2 = $therm_json_devices["body"]["modules"][1]["main_device"];
//$module2 = $therm_json_devices["body"]["modules"][1]["_id"];
//$device3 = $therm_json_devices["body"]["modules"][2]["main_device"];
//$module3 = $therm_json_devices["body"]["modules"][2]["_id"];

$url_thermostat1="http://api.netatmo.net/api/getthermstate?access_token=" .  $params['access_token']."&device_id=".$device1."&module_id=".$module1;
$value_thermostat1= file_get_contents($url_thermostat1);
$json_mesures_thermostat1 = json_decode($value_thermostat1, true);
$temperature_thermostat1 = $json_mesures_thermostat1["body"]["measured"]["temperature"];
$run_thermostat1 = $json_mesures_thermostat1["body"]["therm_relay_cmd"];
$setpoint_thermostat1=$json_mesures_thermostat1["body"]["measured"]["setpoint_temp"];

//$url_thermostat2="http://api.netatmo.net/api/getthermstate?access_token=" .  $params['access_token']."&device_id=".$device2."&module_id=".$module2;
//$value_thermostat2= file_get_contents($url_thermostat2);
//$temperature_thermostat2 = $json_mesures_thermostat2["body"]["measured"]["temperature"];
//$run_thermostat2 = $json_mesures_thermostat2["body"]["therm_relay_cmd"];
//$setpoint_thermostat2=$json_mesures_thermostat2["body"]["measured"]["setpoint_temp"];

//$url_thermostat3="http://api.netatmo.net/api/getthermstate?access_token=" .  $params['access_token']."&device_id=".$device3."&module_id=".$module3;
//$value_thermostat3= file_get_contents($url_thermostat3);
//$json_mesures_thermostat3 = json_decode($value_thermostat3, true);
//$temperature_thermostat3 = $json_mesures_thermostat3["body"]["measured"]["temperature"];
//$run_thermostat3 = $json_mesures_thermostat3["body"]["therm_relay_cmd"];
//$setpoint_thermostat3=$json_mesures_thermostat3["body"]["measured"]["setpoint_temp"];

echo '<?xml version="1.0" encoding="utf8" ?>';
echo "<netatmo>";
echo "<Temp_Thermo_1>" . $temperature_thermostat1   . "</Temp_Thermo_1>";
echo "<Etat_Thermo_1>" . $run_thermostat1   . "</Etat_Thermo_1>";             // Etat du thermostat, 0 chaudiere a l'arret, 100 chaudiere en marche
echo "<Consigne_Thermo_1>" . $setpoint_thermostat1   . "</Consigne_Thermo_1>";
//echo "<Temp_Thermo_2>" . $temperature_thermostat2   . "</Temp_Thermo_2>";
//echo "<Etat_Thermo_2>" . $run_thermostat2   . "</Etat_Thermo_2>";
//echo "<Consigne_Thermo_2>" . $setpoint_thermostat2   . "</Consigne_Thermo_2>";
//echo "<Temp_Thermo_3>" . $temperature_thermostat3   . "</Temp_Thermo_3>";
//echo "<Etat_Thermo_3>" . $run_thermostat3   . "</Etat_Thermo_3>";
//echo "<Consigne_Thermo_3>" . $setpoint_thermostat3   . "</Consigne_Thermo_3>";
echo "</netatmo>";
}
if ($parameter == "json_therm") {
echo  $therm_resulat_device;
}
if ($parameter == "names_therm") {
	echo "nombre de devices: " . count($therm_json_devices["body"]["devices"]) . "<br>";
		for ($i = 0; $i <= count($therm_json_devices["body"]["devices"]) - 1; $i++) {
			echo "Station Name: " . $therm_json_devices["body"]["devices"][$i]["station_name"];
			echo " - Device No: " . $i ." id: " . $therm_json_devices["body"]["devices"][$i]["_id"] . " Name: " . $therm_json_devices["body"]["devices"][$i]["module_name"] . "<br>";
		}
	echo "<br>nombre de modules: " . count($therm_json_devices["body"]["modules"]) . "<br>";
		for ($i = 0; $i <= count($therm_json_devices["body"]["modules"]) - 1; $i++) {
			echo "Parent Device: " . $therm_json_devices["body"]["modules"][$i]["main_device"];
			echo " - Module No: " . $i ." id: " . $therm_json_devices["body"]["modules"][$i]["_id"] . " Name: " . $therm_json_devices["body"]["modules"][$i]["module_name"] . "<br>";
		}

}
if ($parameter == "therm1") {
$url_mesures_therm1 = "https://api.netatmo.net/api/getthermstate?access_token=" .  $params['access_token'] . "&device_id=" . $therm1_relay . "&module_id=".$therm1_device;
    
$mesures_therm1 = file_get_contents($url_mesures_therm1);
echo $mesures_therm1 ;
}
if ($parameter == "therm1_set_away") {
$url_set_therm1 = "https://api.netatmo.net/api/setthermpoint?access_token=" .  $params['access_token'] . "&device_id=" . $therm1_relay . "&module_id=" . $therm1_device. "&setpoint_mode=away";
    
$set_therm1 = file_get_contents($url_set_therm1);
echo $set_therm1 ;
}
if ($parameter == "therm1_set_program") {
$url_set_therm1 = "https://api.netatmo.net/api/setthermpoint?access_token=" .  $params['access_token'] . "&device_id=" . $therm1_relay . "&module_id=" . $therm1_device. "&setpoint_mode=program";
    
$set_therm1 = file_get_contents($url_set_therm1);
echo $set_therm1 ;
}

// Section For Weather Station -----------------------------------
$api_url = "https://api.netatmo.net/api/getuser?access_token=" . $params['access_token'];
$requete = file_get_contents($api_url);
$url_devices = "https://api.netatmo.net/api/devicelist?access_token=" .  $params['access_token'];
$resulat_device = file_get_contents($url_devices);  
$json_devices = json_decode($resulat_device,true);
$json_objects = json_decode($resulat_device);
$module_interne = $json_devices["body"]["devices"][0]["_id"];
$module_externe = $json_devices["body"]["modules"][1]["_id"];
$module_interne2 = $json_devices["body"]["modules"][2]["_id"];
$module_interne3 = $json_devices["body"]["modules"][3]["_id"];
$module_interne4 = $json_devices["body"]["modules"][4]["_id"];

if ($parameter == "json") {
echo  $resulat_device;
}
if ($parameter == "json_viewer") {
print('    
<html>
<style type="text/css">
    body {
      font: 11pt arial;
    }
    #jsoneditor {
      width: 800px;
      height: 2000px;
    }
</style>
<head>
    <title><YAGDA></title>
</head>
<body>
');
	echo "nombre de devices: " . count($json_devices["body"]["devices"]) . "<br>";
		for ($i = 0; $i <= count($json_devices["body"]["devices"]) - 1; $i++) {
			echo "Station Name: " . $json_devices["body"]["devices"][$i]["station_name"];
			echo " - Device No: " . $i ." id: " . $json_devices["body"]["devices"][$i]["_id"] . " Name: " . $json_devices["body"]["devices"][$i]["module_name"] . "<br>";
		}
	echo "<br>nombre de modules: " . count($json_devices["body"]["modules"]) . "<br>";
		for ($i = 0; $i <= count($json_devices["body"]["modules"]) - 1; $i++) {
			echo "Parent Device: " . $json_devices["body"]["modules"][$i]["main_device"];
			echo " - Module No: " . $i ." id: " . $json_devices["body"]["modules"][$i]["_id"] . " Name: " . $json_devices["body"]["modules"][$i]["module_name"] . "<br>";
		}

print('
<br>
<link rel="stylesheet" type="text/css" href="jsoneditor/jsoneditor.css"/>
<script src="jsoneditor/jsoneditor.js"></script>
<div id="jsoneditor"></div>
<script>
  var container = document.getElementById(\'jsoneditor\');
  var options = {
    mode: "view"
  };
  var json = ');

  echo $resulat_device;

  print('
  var editor = new jsoneditor.JSONEditor(container, options, json);
</script>
');
}
if ($parameter == "names") {
	echo "nombre de devices: " . count($json_devices["body"]["devices"]) . "<br>";
		for ($i = 0; $i <= count($json_devices["body"]["devices"]) - 1; $i++) {
			echo "Station Name: " . $json_devices["body"]["devices"][$i]["station_name"];
			echo " - Device No: " . $i ." id: " . $json_devices["body"]["devices"][$i]["_id"] . " Name: " . $json_devices["body"]["devices"][$i]["module_name"] . "<br>";
		}
	echo "<br>nombre de modules: " . count($json_devices["body"]["modules"]) . "<br>";
		for ($i = 0; $i <= count($json_devices["body"]["modules"]) - 1; $i++) {
			echo "Parent Device: " . $json_devices["body"]["modules"][$i]["main_device"];
			echo " - Module No: " . $i ." id: " . $json_devices["body"]["modules"][$i]["_id"] . " Name: " . $json_devices["body"]["modules"][$i]["module_name"] . "<br>";
		}

}
if ($parameter == "selected_modules") {
echo "Selected Modules: <br>";
echo "mod interne ----- (int): " . $module_interne . "<br>";
echo "mod externe ---- (ext): " . $module_externe  . "<br>";
echo "mod interne2 (mod2): " . $module_interne2 . "<br>";
echo "mod interne3 (mod3): " . $module_interne3 . "<br>";
echo "mod interne4 (mod4): " . $module_interne4 . "<br>";
}
if ($parameter == "int") {
$url_mesures_internes = "https://api.netatmo.net/api/getmeasure?access_token=" .  $params['access_token'] . "&device_id=" . $module_interne . "&scale=max&type=Temperature,CO2,Humidity,Pressure,Noise&date_end=last";
$mesures_internes = file_get_contents($url_mesures_internes);
echo $mesures_internes ;
}
if ($parameter == "ext") {
$url_mesures_externes = "https://api.netatmo.net/api/getmeasure?access_token=" .  $params['access_token'] . "&device_id=" . $module_interne . "&module_id=" . $module_externe . "&scale=max&type=Temperature,Humidity&date_end=last";
$mesures_externes = file_get_contents($url_mesures_externes);   
echo $mesures_externes ;
}
if ($parameter == "mod2") {
$url_mesures_internes2 = "https://api.netatmo.net/api/getmeasure?access_token=" .  $params['access_token'] . "&device_id=" .  $module_interne . "&module_id=" . $module_interne2 . "&scale=max&type=Temperature,Humidity,CO2&date_end=last";
$mesures_internes2 = file_get_contents($url_mesures_internes2);
echo $mesures_internes2 ;
}
if ($parameter == "mod3") {
$url_mesures_internes3 = "https://api.netatmo.net/api/getmeasure?access_token=" .  $params['access_token'] . "&device_id=" .  $module_interne . "&module_id=" . $module_interne3 . "&scale=max&type=Temperature,Humidity,CO2&date_end=last";
$mesures_internes3 = file_get_contents($url_mesures_internes3);
echo $mesures_internes3 ;
}
if ($parameter == "mod4") {
$url_mesures_internes4 = "https://api.netatmo.net/api/getmeasure?access_token=" .  $params['access_token'] . "&device_id=" .  $module_interne . "&module_id=" . $module_interne4 . "&scale=max&type=Temperature,Humidity,CO2&date_end=last";
$mesures_internes4 = file_get_contents($url_mesures_internes4);
echo $mesures_internes4 ;
}

// Section Infos
if ($parameter == "") {
print('    
<html>
<style type="text/css">
    body {
      font: 11pt arial;
    }
</style>
<head>
    <title><YAGDA></title>
</head>
<body>
<br>
Available parameters:
<br><br>
For Netatmo thermostat:
<br><br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json_viewer_therm'>http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json_viewer_therm<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=xml_therm<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json_therm'>http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json_therm<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=names_therm'>http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=names_therm<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=therm1<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=therm1_set_away<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=therm1_set_program<br>
<br><br>
For Netatmo Weather:<br><br>

http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json_viewer<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=names<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=selected_modules<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=int<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=ext<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=mod2<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=mod3<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=mod4<br>

');
}

?>
Posté(e)

Bonjour

J'ai un problème, je suis en V3.6 et je n'ai que les données du Netatmo intérieur mais je n’aie pas les données des Netatmo additionnel des autres pièces

le debug me donne :

 [DEBUG] 10:51:19: Récupération des données intérieures: true
[DEBUG] 10:51:19: Récupération des données extérieures : false
[DEBUG] 10:51:19: err: [string "-------------------------------------------..."]:73: Expected value but found T_END at character 1
[DEBUG] 10:51:19: Récupération des données intérieures Mod2: false
[DEBUG] 10:51:19: err: [string "-------------------------------------------..."]:161: Expected value but found T_END at character 1
[DEBUG] 10:51:20: Récupération des données intérieures Mod3: false
[DEBUG] 10:51:20: err: [string "-------------------------------------------..."]:204: Expected value but found T_END at character 1
[DEBUG] 10:51:20: Récupération des données intérieures Mod4: false
[DEBUG] 10:51:20: err: [string "-------------------------------------------..."]:247: Expected value but found T_END at character 1
[DEBUG] 10:51:22: Payload: /input/post.json?json={NETATMO_temperature_exterieure:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:22: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:22: Payload: /input/post.json?json={NETATMO_humidite_exterieure:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:22: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:22: Payload: /input/post.json?json={NETATMO_pression:1021.2}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:22: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:22: Payload: /input/post.json?json={NETATMO_bruit:39}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:22: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:23: Payload: /input/post.json?json={NETATMO_temperature_interieure_Salon:22.2}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:23: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:23: Payload: /input/post.json?json={NETATMO_temperature_int_mod2_Cuisine:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:23: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:24: Payload: /input/post.json?json={NETATMO_temperature_int_mod3_Chambre:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:24: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:24: Payload: /input/post.json?json={NETATMO_temperature_int_mod4_Bureau:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:24: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:25: Payload: /input/post.json?json={NETATMO_humidite_interieure_Salon:40}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:25: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:25: Payload: /input/post.json?json={NETATMO_humidite_int_mod2_Cuisine:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:25: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:26: Payload: /input/post.json?json={NETATMO_humidite_int_mod3_Chambre:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:26: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:27: Payload: /input/post.json?json={NETATMO_humidite_int_mod4_Bureau:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:27: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:27: Payload: /input/post.json?json={NETATMO_co2_Salon:504}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:27: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:28: Payload: /input/post.json?json={NETATMO_co2_mod2_Cuisine:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:28: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:28: Payload: /input/post.json?json={NETATMO_co2_mod3_Chambre:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:28: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[DEBUG] 10:51:29: Payload: /input/post.json?json={NETATMO_co2_mod4_Bureau:}&apikey=XXXXXXXXXXXXXXXXXXXXXXXXXX
[DEBUG] 10:51:29: response: Notice: Undefined index: userid in /var/www/emoncms/index.php on line 131 Status: 200 errorcode: 0
[ERROR] 10:51:29: line 374: attempt to compare number with string

Avez vous une idée ?

Merci par avance

Ton problème vient de la section suivante ans le php:

$module_interne = $json_devices["body"]["devices"][0]["_id"];
$module_externe = $json_devices["body"]["modules"][1]["_id"];
$module_interne2 = $json_devices["body"]["modules"][2]["_id"];
$module_interne3 = $json_devices["body"]["modules"][3]["_id"];
$module_interne4 = $json_devices["body"]["modules"][4]["_id"];

voir post ci-dessus pour plus d'infos.

  • 4 mois après...
Posté(e)

Salut @sebcbien

Je reveille un vieux post mais j'ai enfin pris le temps d'installer ton script pour que gérer mon th° Netatmo et c'est le top!!!

Merci !

  • 3 semaines après...
Posté(e)

J'ai fait une mise àjour avec un mode été/hiver et la fonction "no frost" si ça intéressé qqun je posterai.

Sent from my SM-N910F using Tapatalk

Posté(e)

Oki, voici la version 3.2 :-)

 

Voici le Virtual device, il faut uniquement changer le emoncms id dans le code du bouton update et "c'est tout".

post-826-0-44498000-1439935685_thumb.jpg
 

-----------------------------------------------------------------------------------------
-- Thermtatmo v3
-- Retreive Netatmo values for more than 2 modules, compute CO2 and push to EmonCMS
-- Sebastien Jauquet
-- Aoà»t 2015
-- Thanks to cedriclocqueneux, krikroff, i-magin and all contibutors to the netatmo code
-----------------------------------------------------------------------------------------

-- Instructions:
-- Create an free emoncms.org account
-- Retrieve your Write API Key from it
-- Create a Global variable (undefined) -> CO2_Max_Value to store the max value of CO2 of the house - if you dont need this, set CO2 to false (default: 0)
-- Install my thermtatmo.php in your webserver and write his address in the ip Address of this module
-- for each value you want to be pushed to emoncms, modify the section -- Push To EMONCMS -- below
-- Create a block scene or use gea to click this button each 10 minutes (to avoid rejection from the api of Netatmo)
-- V2.01 -- First released version
-- V2.2 -- doesn't push to emonCMS if netatmo query return false
-- V2.3 -- added push message to phone if error
-- V3 -- changed name and added Netatmo thermostat retrieve and push modes away and program
-- V3.1 -- Added customisation options for code Sharing
-- V3.2 -- Added Frost Guard Mode and possibility for two thermostats

local id = {
	PHONE_SEB				= 1323,
    PHONE_GG				= 53
	}
-- Prefix of the id of the inputs to be created in emoncms
-- Use this for testing to not mess your current feeds with wrong values while testing
-- When everything is ok, restore original prefix. I suggest "NETATMO_" and delete on emoncms the inputs created for testing
-- local EmonCMS_Prefix = "NETATMO_"
local EmonCMS_Prefix = "NETATMO_" 
-------------------------------------------------------------------------
local PushToEmonCMS = true -- true = push to emoncms - false = do not push
local Thermostat = true -- true = get thermostat values - false = do not get them
local VMC = true -- true = set in Global variable CO2_Max_Value the Max CO2 Value
local selfId = fibaro:getSelfId();
local thismodule=fibaro:getSelfId()
local domaine = fibaro:get(selfId, 'IPAddress')
local PushItem
local DoNotPush_Error = false
local activatePush = false; -- activate push when netatmo error detected 
local ID_Smartphones = {id["PHONE_SEB"]}; -- list of device receiving Push
local CO2_Max_Value_Local = 0 -- if you dont need this, set CO2 to false (default: 0)
local emoncms = Net.FHttp("emoncms.org",80)
local emoncms_api_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -- your EMONCMS WRITE api Key

-- IDs générés le : 16/08/15 à  02:13:29
local id = {
--Coin Chaudière
TEMP_EAU_REZ = 1360, TEMP_EAU_BOILER = 1362, TEMP_EAU_1ER = 1361, 
--Grenier
TEMP_GRENIER = 1359, 
}

EmonCMS = {}; 
 
if (temperature_exterieure==nil) then temperature_exterieure = ""; end
if (humidite_exterieure==nil) then humidite_exterieure = ""; end

if (temperature_interieure==nil) then temperature_interieure = ""; end
if (humidite_interieure==nil) then humidite_interieure = ""; end
if (co2==nil) then co2 = ""; end
if (pression==nil) then pression = ""; end
if (bruit==nil) then bruit = ""; end

if (temperature_int_mod2==nil) then temperature_int_mod2 = ""; end
if (humidite_int_mod2==nil) then humidite_int_mod2 = ""; end
if (co2_mod2==nil) then co2_mod2 = ""; end

if (temperature_int_mod3==nil) then temperature_int_mod3 = ""; end
if (humidite_int_mod3==nil) then humidite_int_mod3 = ""; end
if (co2_mod3==nil) then co2_mod3 = ""; end

if (temperature_int_mod4==nil) then temperature_int_mod4 = ""; end
if (humidite_int_mod4==nil) then humidite_int_mod4 = ""; end
if (co2_mod4==nil) then co2_mod4 = ""; end 

if (temperature_max==nil) then temperature_max = ""; end
if (temperature_min==nil) then temperature_min = ""; end

-- therm1 = 1er
if (temperature_therm1==nil) then temperature_therm1 = ""; end
if (temperature_setpoint_therm1==nil) then temperature_setpoint_therm1 = ""; end
if (relay_therm1==nil) then relay_therm1 = ""; end

-- therm2 = rez
if (temperature_therm2==nil) then temperature_therm2 = ""; end
if (temperature_setpoint_therm2==nil) then temperature_setpoint_therm2 = ""; end
if (relay_therm2==nil) then relay_therm2 = ""; end



if(refreshUI==nil) then -- Loads in memory only the first occurence
function refreshUI(therm, therm2, therm1, ext, bruit, titre, tempmod, co2mod, humidmod, lastupdate, laststatus)
  fibaro:call(selfId,"setProperty","ui.thermstatus.value",therm);
  fibaro:call(selfId,"setProperty","ui.thermostat2.value",therm2);
  fibaro:call(selfId,"setProperty","ui.thermostat1.value",therm1);
  fibaro:call(selfId,"setProperty","ui.ext.value",ext);
  fibaro:call(selfId,"setProperty","ui.bruit.value",bruit);  
  fibaro:call(selfId,"setProperty","ui.titre.value",titre);  
  fibaro:call(selfId,"setProperty","ui.tempmod.value",tempmod);  
  fibaro:call(selfId,"setProperty","ui.co2mod.value",co2mod);  
  fibaro:call(selfId,"setProperty","ui.humidmod.value",humidmod);  
  fibaro:call(selfId,"setProperty","ui.lastupdate.value",lastupdate);      
  fibaro:call(selfId,"setProperty","ui.laststatus.value",laststatus);   
end;
end

pushMessage = function (sendPush) 
	if (activatePush) then 
		for i=1, #ID_Smartphones do 
		  fibaro:call(tonumber(ID_Smartphones[i]), 'sendPush', sendPush); 
		  fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", "orange", "Push message ("..sendPush..") sent to mobile: "..tonumber(ID_Smartphones[i]), "span")); 
		end 
	end 
end

if(getTherm1==nil) then -- Loads in memory only the first occurence
function getTherm1(retry)
  retry = retry or 0
  -- Setting up the connection data
  local FHTE = Net.FHttp(domaine, 80);
  -- Netatmo extérieur
  local response = FHTE:GET("/netatmo/thermtatmo.php?parameter=therm1");
  -- decoding json string to table
  if (response~= nil) then
    local result = nil;
    result = json.decode(response);
    if (result ~= nil) then
      -- prevent: attempt to index field 'body' (a nil value)
      if (result.body ~= nil) then
        temperature_therm1 = result.body.measured.temperature or "n.c";
		--fibaro:debug(temperature_therm1)
        temperature_setpoint_therm1 = result.body.measured.setpoint_temp or "n.c";
		--fibaro:debug(temperature_setpoint_therm1)
		relay_therm1 = result.body.therm_relay_cmd or "n.c";
		--fibaro:debug(relay_therm1)
		-- variable globale pour info sms
        local msg = "Température Thermostat 1 : "..temperature_therm1.."°C";
        --fibaro:setGlobal("tempext", msg);
        return true;
      else
        fibaro:debug("Netatmo Therm1: erreur le " .. os.date());
        if (result.error ~= nil) then
          fibaro:debug("error code: "..result.error.code..", message: "..result.error.message);
        end
      end
    else
      fibaro:debug("Netatmo Therm1: erreur decodage json le " .. os.date());
    end
  else
    fibaro:debug("Netatmo Therm1:la reponse est null !");
  end
  if ((retry or 5)< 5) then
    fibaro:debug("Retry #"..retry.."process, please wait...");
    fibaro:sleep(5000);
    return getInt(tonumber(retry+1));
  else
      return false;
  end
end;
 
end

if(getTherm2==nil) then -- Loads in memory only the first occurence
function getTherm2(retry)
  retry = retry or 0
  -- Setting up the connection data
  local FHTE = Net.FHttp(domaine, 80);
  -- Netatmo extérieur
  local response = FHTE:GET("/netatmo/thermtatmo.php?parameter=therm2");
  -- decoding json string to table
  if (response~= nil) then
    local result = nil;
    result = json.decode(response);
    if (result ~= nil) then
      -- prevent: attempt to index field 'body' (a nil value)
      if (result.body ~= nil) then
        temperature_therm2 = result.body.measured.temperature or "n.c";
		--fibaro:debug(temperature_therm1)
        temperature_setpoint_therm2 = result.body.measured.setpoint_temp or "n.c";
		--fibaro:debug(temperature_setpoint_therm1)
		relay_therm2 = result.body.therm_relay_cmd or "n.c";
		--fibaro:debug(relay_therm1)
		-- variable globale pour info sms
        local msg = "Température Thermostat 2 : "..temperature_therm2.."°C";
        --fibaro:setGlobal("tempext", msg);
        return true;
      else
        fibaro:debug("Netatmo Therm2: erreur le " .. os.date());
        if (result.error ~= nil) then
          fibaro:debug("error code: "..result.error.code..", message: "..result.error.message);
        end
      end
    else
      fibaro:debug("Netatmo Therm2: erreur decodage json le " .. os.date());
    end
  else
    fibaro:debug("Netatmo Therm2:la reponse est null !");
  end
  if ((retry or 5)< 5) then
    fibaro:debug("Retry #"..retry.."process, please wait...");
    fibaro:sleep(5000);
    return getInt(tonumber(retry+1));
  else
      return false;
  end
end;
 
end

if(getExt==nil) then -- Loads in memory only the first occurence
function getExt(retry)
  retry = retry or 0
  -- Setting up the connection data
  local FHTE = Net.FHttp(domaine, 80);
  -- Netatmo extérieur
  local response = FHTE:GET("/netatmo/thermtatmo.php?parameter=ext");
  -- decoding json string to table
  if (response~= nil) then
    local result = nil;
    result = json.decode(response);
    if (result ~= nil) then
      -- prevent: attempt to index field 'body' (a nil value)
      if (result.body ~= nil) then
        temperature_exterieure = result.body[1].value[1][1] or "n.c";
        humidite_exterieure =result.body[1].value[1][2] or "n.c";
        -- variable globale pour info sms
        local msg = "Température extérieure : "..temperature_exterieure.."°C";
        fibaro:setGlobal("tempext", msg);
        return true;
      else
        fibaro:debug("Netatmo EXT: erreur le " .. os.date());
        if (result.error ~= nil) then
          fibaro:debug("error code: "..result.error.code..", message: "..result.error.message);
        end
      end
    else
      fibaro:debug("Netatmo EXT: erreur decodage json le " .. os.date());
    end
  else
    fibaro:debug("Netatmo EXT:la reponse est null !");
  end
  if ((retry or 5)< 5) then
    fibaro:debug("Retry #"..retry.."process, please wait...");
    fibaro:sleep(5000);
    return getInt(tonumber(retry+1));
  else
      return false;
  end
end;
 
end
 
if(getInt==nil) then -- Loads in memory only the first occurence
function getInt(retry)
  retry = retry or 0;
  -- Setting up the connection data
  local FHTE = Net.FHttp(domaine, 80);
  -- Netatmo intérieur
  local response = FHTE:GET("/netatmo/thermtatmo.php?parameter=int");
  -- decoding json string to table
  if (response~= nil) then
    local result = nil;
    result = json.decode(response);
    if (result ~= nil) then
      -- prevent: attempt to index field 'body' (a nil value)
      if (result.body ~= nil) then
        temperature_interieure = result.body[1].value[1][1] or "n.c";
        humidite_interieure = result.body[1].value[1][3] or "n.c";          
        co2 = result.body[1].value[1][2] or "n.c";
        pression = result.body[1].value[1][4] or "n.c";
        bruit = result.body[1].value[1][5] or "n.c";
        -- variable globale pour info sms
        fibaro:setGlobal("tempint", "Température intérieure : "..temperature_interieure.."°C");
        return true;
      else
        fibaro:debug("Netatmo INT: erreur le " .. os.date());
        if (result.error ~= nil) then
          fibaro:debug("error code: "..result.error.code..", message: "..result.error.message);
        end
      end
    else
      fibaro:debug("Netatmo INT: erreur decodage json le " .. os.date());
    end
  else
    fibaro:debug("Netatmo INT:la reponse est null !");
  end
  if ((retry or 5)< 5) then
    fibaro:debug("Retry #"..retry.."process, please wait...");
    fibaro:sleep(5000);
    return getExt(tonumber(retry+1));
  else
      return false;
  end
end;
 
end

if(getMod2==nil) then -- Loads in memory only the first occurence 
function getMod2(retry)
  retry = retry or 0;
  -- Setting up the connection data
  local FHTE = Net.FHttp(domaine, 80);
  -- Netatmo intérieur
  local response = FHTE:GET("/netatmo/thermtatmo.php?parameter=mod2");
  -- decoding json string to table
  if (response~= nil) then
    local result = nil;
    result = json.decode(response);
    if (result ~= nil) then
      -- prevent: attempt to index field 'body' (a nil value)
      if (result.body ~= nil) then
        temperature_int_mod2 = result.body[1].value[1][1] or "n.c";
        humidite_int_mod2 = result.body[1].value[1][2] or "n.c";          
        co2_mod2 = result.body[1].value[1][3] or "n.c";
        -- variable globale pour info sms
        -- fibaro:setGlobal("tempint", "Température intérieure : "..temperature_interieure.."°C");
        return true;
      else
        fibaro:debug("Netatmo INT_mod2: erreur le " .. os.date());
        if (result.error ~= nil) then
          fibaro:debug("error code: "..result.error.code..", message: "..result.error.message);
        end
      end
    else
      fibaro:debug("Netatmo INT_mod2: erreur decodage json le " .. os.date());
    end
  else
    fibaro:debug("Netatmo INT_mod2:la reponse est null !");
  end
  if ((retry or 5)< 5) then
    fibaro:debug("Retry #"..retry.."process, please wait...");
    fibaro:sleep(5000);
    return getExt(tonumber(retry+1));
  else
      return false;
  end
end;
 
end

if(getMod3==nil) then -- Loads in memory only the first occurence 
function getMod3(retry)
  retry = retry or 0;
  -- Setting up the connection data
  local FHTE = Net.FHttp(domaine, 80);
  -- Netatmo intérieur
  local response = FHTE:GET("/netatmo/thermtatmo.php?parameter=mod3");
  -- decoding json string to table
  if (response~= nil) then
    local result = nil;
    result = json.decode(response);
    if (result ~= nil) then
      -- prevent: attempt to index field 'body' (a nil value)
      if (result.body ~= nil) then
        temperature_int_mod3 = result.body[1].value[1][1] or "n.c";
        humidite_int_mod3 = result.body[1].value[1][2] or "n.c";          
        co2_mod3 = result.body[1].value[1][3] or "n.c";
        -- variable globale pour info sms
        -- fibaro:setGlobal("tempint", "Température intérieure : "..temperature_interieure.."°C");
        return true;
      else
        fibaro:debug("Netatmo INT_mod3: erreur le " .. os.date());
        if (result.error ~= nil) then
          fibaro:debug("error code: "..result.error.code..", message: "..result.error.message);
        end
      end
    else
      fibaro:debug("Netatmo INT_mod3: erreur decodage json le " .. os.date());
    end
  else
    fibaro:debug("Netatmo INT_mod3:la reponse est null !");
  end
  if ((retry or 5)< 5) then
    fibaro:debug("Retry #"..retry.."process, please wait...");
    fibaro:sleep(5000);
    return getExt(tonumber(retry+1));
  else
      return false;
  end
end;
 
end

if(getMod4==nil) then -- Loads in memory only the first occurence 
function getMod4(retry)
  retry = retry or 0;
  -- Setting up the connection data
  local FHTE = Net.FHttp(domaine, 80);
  -- Netatmo intérieur
  local response = FHTE:GET("/netatmo/thermtatmo.php?parameter=mod4");
  -- decoding json string to table
  if (response~= nil) then
    local result = nil;
    result = json.decode(response);
    if (result ~= nil) then
      -- prevent: attempt to index field 'body' (a nil value)
      if (result.body ~= nil) then
        temperature_int_mod4 = result.body[1].value[1][1] or "n.c";
        humidite_int_mod4 = result.body[1].value[1][2] or "n.c";          
        co2_mod4 = result.body[1].value[1][3] or "n.c";
        -- variable globale pour info sms
        -- fibaro:setGlobal("tempint", "Température intérieure : "..temperature_interieure.."°C");
        return true;
      else
        fibaro:debug("Netatmo INT_mod4: erreur le " .. os.date());
        if (result.error ~= nil) then
          fibaro:debug("error code: "..result.error.code..", message: "..result.error.message);
        end
      end
    else
      fibaro:debug("Netatmo INT_mod4: erreur decodage json le " .. os.date());
    end
  else
    fibaro:debug("Netatmo INT_mod4:la reponse est null !");
  end
  if ((retry or 5)< 5) then
    fibaro:debug("Retry #"..retry.."process, please wait...");
    fibaro:sleep(5000);
    return getExt(tonumber(retry+1));
  else
      return false;
  end
end;
 
end

function EmonCMS:Push(payloademon)
payloademon = "/input/post.json?json={" .. EmonCMS_Prefix .. payloademon .. "}&apikey=" .. emoncms_api_key
response, status, errorCode = emoncms:GET(payloademon);
fibaro:debug("Payload: " .. payloademon) ;
fibaro:debug("response: " .. response .. " Status: " .. status .. " errorcode: " .. errorCode) ;
fibaro:sleep(500);
end

local function main()
  -- retrieve values from thermtatmo.php (res = result) add or remove the one you need
  local resTherm1, resInt, resExt, resMod2, resMod3, resMod4 = false, false, false, false, false, false;
  
  if Thermostat == true then  
	local status, err = pcall(function () resTherm1 = getTherm1(); end);
	  fibaro:debug("Récupération des valeurs du Thermostat 1: " .. tostring(resTherm1));
	  if (status == false) then
		DoNotPush_Error = true;
		fibaro:debug("err: "..tostring(err or 'n.c'));
	  end
	  
	local status, err = pcall(function () resTherm2 = getTherm2(); end);
	  fibaro:debug("Récupération des valeurs du Thermostat 2: " .. tostring(resTherm2));
	  if (status == false) then
		DoNotPush_Error = true;
		fibaro:debug("err: "..tostring(err or 'n.c'));
	  end
  end
  
  local status, err = pcall(function () resInt = getInt(); end);
  fibaro:debug("Récupération des données intérieures: " .. tostring(resInt));
  if (status == false) then
	DoNotPush_Error = true;
    fibaro:debug("err: "..tostring(err or 'n.c'));
  end

  local status, err = pcall(function () resExt = getExt(); end);
  fibaro:debug("Récupération des données extérieures : " .. tostring(resExt));
  if (status == false) then
	DoNotPush_Error = true;
    fibaro:debug("err: "..tostring(err or 'n.c'));
  end

  local status, err = pcall(function () resMod2 = getMod2(); end);
  fibaro:debug("Récupération des données intérieures Mod2: " .. tostring(resMod2));
  if (status == false) then
	DoNotPush_Error = true;
    fibaro:debug("err: "..tostring(err or 'n.c'));
  end
  
  local status, err = pcall(function () resMod3 = getMod3(); end);
  fibaro:debug("Récupération des données intérieures Mod3: " .. tostring(resMod3));
  if (status == false) then
	DoNotPush_Error = true;
    fibaro:debug("err: "..tostring(err or 'n.c'));
  end
  
  local status, err = pcall(function () resMod4 = getMod4(); end);
  fibaro:debug("Récupération des données intérieures Mod4: " .. tostring(resMod4));
  if (status == false) then
	DoNotPush_Error = true;
    fibaro:debug("err: "..tostring(err or 'n.c'));
  end
fibaro:debug("1")
if DoNotPush_Error == false then
		-- if no retreive values error from netatmo, then display values in the virtual device and push to emon cms
		-- add or remove in the right order and separated by comma the definition of the display in the VD (definition of the array for the refresh ui function)
		
		-- calculate Min and Max temperature:
	  if Thermostat == false then
		fibaro:debug("not calculating Temp Max & Min Values")
	  else
		temperature_max = temperature_interieure
		if temperature_therm1 > temperature_max then temperature_max = temperature_therm1 end
		if temperature_therm2 > temperature_max then temperature_therm2 = temperature_int_mod2 end
		if temperature_int_mod2 > temperature_max then temperature_max = temperature_int_mod2 end
		if temperature_int_mod3 > temperature_max then temperature_max = temperature_int_mod3 end
		if temperature_int_mod4 > temperature_max then temperature_max = temperature_int_mod4 end

 		temperature_min = temperature_interieure
		if temperature_therm1 < temperature_max then temperature_max = temperature_therm1 end
		if temperature_therm2 < temperature_max then temperature_therm2 = temperature_int_mod2 end
		if temperature_int_mod2 < temperature_min then temperature_min = temperature_int_mod2 end
		if temperature_int_mod3 < temperature_min then temperature_min = temperature_int_mod3 end
		if temperature_int_mod4 < temperature_min then temperature_min = temperature_int_mod4 end
	  end
		-- call function refresh ui with retreived parameters:
		if relay_therm1 == "0" then relay_therm1_disp = "Décl." else relay_therm1_disp = "Encl."end
		if relay_therm2 == "0" then relay_therm2_disp = "Décl." else relay_therm2_disp = "Encl."end
	  refreshUI(
		"Floor: T° (SetPoint - Max - Min)",
		"Rez: "..temperature_therm2.."° ("..relay_therm2_disp.." - "..temperature_setpoint_therm2.." - "..temperature_max.." - "..temperature_min..")",
		"1er: "..temperature_therm1.."° ("..relay_therm1_disp.." - "..temperature_setpoint_therm1.." - "..temperature_max.." - "..temperature_min..")",
		"Ext: "..temperature_exterieure.." °C - "..humidite_exterieure.." % - "..pression.." mbar", 
		"Bruit Rez: "..bruit.." dB",
		"Rez - Emilien - Thomas - Parents",
		temperature_interieure.." - "..temperature_int_mod2.." - "..temperature_int_mod3.." - "..temperature_int_mod4.." °C ",
		co2.." - "..co2_mod2.." - "..co2_mod3.." - "..co2_mod4.." ppm",
		humidite_interieure.." - "..humidite_int_mod2.." - "..humidite_int_mod3.." - "..humidite_int_mod4.." % ",
		os.date("%H:%M"),
		tostring(resInt).." "..tostring(resExt).." "..tostring(resMod2).." "..tostring(resMod3).." "..tostring(resMod4)
		);
		-- Push To EMONCMS --
		-- Syntax: payload = set label of input on emoncms .. variable containing the value
	  if PushToEmonCMS == true then
	    if Thermostat == true then  
			payloademon = "temperature_1er:"..temperature_therm1
				EmonCMS:Push(payloademon);
			payloademon = "temperature_set_point_1er:".. temperature_setpoint_therm1
				EmonCMS:Push(payloademon);
			payloademon = "relais_chaudiere_1er:".. relay_therm1
				EmonCMS:Push(payloademon);
			
			payloademon = "temperature_Rez:"..temperature_therm2
				EmonCMS:Push(payloademon);
			payloademon = "temperature_set_point_Rez:".. temperature_setpoint_therm2
				EmonCMS:Push(payloademon);
			payloademon = "relais_chaudiere_Rez:".. relay_therm2
				EmonCMS:Push(payloademon);
		end
		payloademon = "temperature_exterieure:"..temperature_exterieure
			EmonCMS:Push(payloademon);
		payloademon = "humidite_exterieure:".. humidite_exterieure
			EmonCMS:Push(payloademon);
		payloademon = "pression:".. pression
			EmonCMS:Push(payloademon);
		payloademon = "bruit:".. bruit
			EmonCMS:Push(payloademon);
		payloademon = "temperature_interieure_Rez:".. temperature_interieure
			EmonCMS:Push(payloademon);
		payloademon = "temperature_int_mod2_Emilien:".. temperature_int_mod2
			EmonCMS:Push(payloademon);
		payloademon = "temperature_int_mod3_Thomas:".. temperature_int_mod3
			EmonCMS:Push(payloademon);
		payloademon = "temperature_int_mod4_Parents:".. temperature_int_mod4
			EmonCMS:Push(payloademon);
		payloademon = "humidite_interieure_Rez:".. humidite_interieure
			EmonCMS:Push(payloademon);
		payloademon = "humidite_int_mod2_Emilien:".. humidite_int_mod2
			EmonCMS:Push(payloademon);
		payloademon = "humidite_int_mod3_Thomas:".. humidite_int_mod3
			EmonCMS:Push(payloademon);
		payloademon = "humidite_int_mod4_Parents:".. humidite_int_mod4
			EmonCMS:Push(payloademon);
		payloademon = "co2_Rez:".. co2
			EmonCMS:Push(payloademon);
		payloademon = "co2_mod2_Emilien:".. co2_mod2
			EmonCMS:Push(payloademon);
		payloademon = "co2_mod3_Thomas:".. co2_mod3
			EmonCMS:Push(payloademon);
		payloademon = "co2_mod4_Parents:".. co2_mod4
			EmonCMS:Push(payloademon);

		payloademon = "TEMP_EAU_REZ:".. fibaro:getValue(id["TEMP_EAU_REZ"], "value")
			EmonCMS:Push(payloademon);	
		payloademon = "TEMP_EAU_BOILER:".. fibaro:getValue(id["TEMP_EAU_BOILER"], "value")
			EmonCMS:Push(payloademon);	
		payloademon = "TEMP_EAU_1ER:".. fibaro:getValue(id["TEMP_EAU_1ER"], "value")
			EmonCMS:Push(payloademon);	
		payloademon = "TEMP_GRENIER:".. fibaro:getValue(id["TEMP_GRENIER"], "value")
			EmonCMS:Push(payloademon);				
		
	  end
	if VMC == true then  
		-- Compute Value MAX CO2 Maison, store in global variable (to adjust the VMC Speed in another VD)
		  if CO2_Max_Value_Local == false then
			fibaro:debug("not calculating nor storing CO2 Max Value")
		  else
			CO2_Max_Value_Local = co2
			if CO2_Max_Value_Local < co2_mod2 then CO2_Max_Value_Local = co2_mod2 end
			if CO2_Max_Value_Local < co2_mod3 then CO2_Max_Value_Local = co2_mod3 end
			if CO2_Max_Value_Local < co2_mod4 then CO2_Max_Value_Local = co2_mod4 end
			if tonumber(fibaro:getGlobalValue("CO2_Max_Value")) == CO2_Max_Value_Local then CO2_Max_Value_Local = CO2_Max_Value_Local +1; fibaro:debug("added 1 to Max CO2"); end -- so CO2_Max_Value_Local is not the same between measures and global var is modified and can be detected in other scenes
			fibaro:setGlobal("CO2_Max_Value", CO2_Max_Value_Local )
			fibaro:debug("CO2_Max_Value: ".. CO2_Max_Value_Local )  
		  end
	end
else
	-- if error detected, to not push to emoncms and push message to phone
	fibaro:debug("push error")
	pushMessage("Error with netatmo device. resInt:" .. tostring(resInt).." resExt:"..tostring(resExt).." resMod2:"..tostring(resMod2).." resMod3:"..tostring(resMod3).." resMod4:"..tostring(resMod4).." resTherm1:"..tostring(resTherm1));
end
end

-- launch
main();
 
 
 

voici le code php en clair, pas oublier de changer les paramètres au début.

j'ai une configuration avec deux maisons (la mienne et chez ma mère) et deux thermostats (rez et étage)

l'ordre des modules peut donc changer, utilisez les paramèttres pour afficher les configurations et faire votre choix.

<?php
//ini_set('display_errors', false);
//set_exception_handler('ReturnError');

$parameter=$_GET['parameter'];
$password="XXXXXXXXXXXXXXXXXXXX"; // netatmo password
$username="XXXXXXXXXXXXXXXXXXXXXXXXX"; // netatmo username
$app_id = "XXXXXXXXXXXXXXXXXXXXXXXXXX"; // netatmo
$app_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // netatmo
$token_url = "https://api.netatmo.net/oauth2/token";
$postdata = http_build_query(
        array(
            'grant_type' => "password",
            'client_id' => $app_id,
            'client_secret' => $app_secret,
            'username' => $username,
            'password' => $password,
            'scope' => 'read_station read_thermostat write_thermostat'
    )
);

$opts = array('http' =>
	array(
		'method'  => 'POST',
		'header'  => 'Content-type: application/x-www-form-urlencoded',
		'content' => $postdata
	)
);

$context  = stream_context_create($opts);
$response = file_get_contents($token_url, false, $context);
$params = null;
$params = json_decode($response, true);

// Section For Thermostat --------------------------------------
$therm_api_url = "https://api.netatmo.net/api/getuser?access_token=" . $params['access_token']."&app_type=app_thermostat";
$therm_requete = @file_get_contents($therm_api_url);

//if ($therm_requete == "{"error":{"code":26,"message":"User usage reached"}}") {
//echo $therm_requete ;
//exit();
//}

$therm_url_devices = "https://api.netatmo.net/api/devicelist?access_token=" .  $params['access_token']."&app_type=app_thermostat";
$therm_resulat_device = @file_get_contents($therm_url_devices);	
$therm_json_devices = json_decode($therm_resulat_device,true);
$therm1_device = $therm_json_devices["body"]["modules"][1]["_id"];
$therm1_relay = $therm_json_devices["body"]["devices"][0]["_id"];
$therm2_device = $therm_json_devices["body"]["modules"][0]["_id"];
$therm2_relay = $therm_json_devices["body"]["devices"][1]["_id"];

if ($parameter == "json_viewer_therm") {
print('    
<html>
<style type="text/css">
    body {
      font: 11pt arial;
    }
    #jsoneditor {
      width: 800px;
      height: 2000px;
    }
</style>
<head>
    <title><YAGDA></title>
</head>
<body>
');
	echo "nombre de devices Thermostat: " . count($therm_json_devices["body"]["devices"]) . "<br>";
		for ($i = 0; $i <= count($therm_json_devices["body"]["devices"]) - 1; $i++) {
			echo "Station Name: " . $therm_json_devices["body"]["devices"][$i]["station_name"];
			echo " - Device No: " . $i ." id: " . $therm_json_devices["body"]["devices"][$i]["_id"] . " Name: " . $therm_json_devices["body"]["devices"][$i]["module_name"] . "<br>";
		}
	echo "<br>nombre de modules Thermostat: " . count($therm_json_devices["body"]["modules"]) . "<br>";
		for ($i = 0; $i <= count($therm_json_devices["body"]["modules"]) - 1; $i++) {
			echo "Parent Device: " . $therm_json_devices["body"]["modules"][$i]["main_device"];
			echo " - Module No: " . $i ." id: " . $therm_json_devices["body"]["modules"][$i]["_id"] . " Name: " . $therm_json_devices["body"]["modules"][$i]["module_name"] . "<br>";
		}

print('
<br>
<link rel="stylesheet" type="text/css" href="jsoneditor/jsoneditor.css"/>
<script src="jsoneditor/jsoneditor.js"></script>
<div id="jsoneditor"></div>
<script>
  var container = document.getElementById(\'jsoneditor\');
  var options = {
    mode: "view"
  };
  var json = ');

  echo $therm_resulat_device;

  print('
  var editor = new jsoneditor.JSONEditor(container, options, json);
</script>
');
}
if ($parameter == "xml_therm") {
// setup Station continue
$device1 = $therm_json_devices["body"]["modules"][0]["main_device"];
$module1 = $therm_json_devices["body"]["modules"][0]["_id"];
//$device2 = $therm_json_devices["body"]["modules"][1]["main_device"];
//$module2 = $therm_json_devices["body"]["modules"][1]["_id"];
//$device3 = $therm_json_devices["body"]["modules"][2]["main_device"];
//$module3 = $therm_json_devices["body"]["modules"][2]["_id"];

$url_thermostat1="http://api.netatmo.net/api/getthermstate?access_token=" .  $params['access_token']."&device_id=".$device1."&module_id=".$module1;
$value_thermostat1= file_get_contents($url_thermostat1);
$json_mesures_thermostat1 = json_decode($value_thermostat1, true);
$temperature_thermostat1 = $json_mesures_thermostat1["body"]["measured"]["temperature"];
$run_thermostat1 = $json_mesures_thermostat1["body"]["therm_relay_cmd"];
$setpoint_thermostat1=$json_mesures_thermostat1["body"]["measured"]["setpoint_temp"];

//$url_thermostat2="http://api.netatmo.net/api/getthermstate?access_token=" .  $params['access_token']."&device_id=".$device2."&module_id=".$module2;
//$value_thermostat2= file_get_contents($url_thermostat2);
//$temperature_thermostat2 = $json_mesures_thermostat2["body"]["measured"]["temperature"];
//$run_thermostat2 = $json_mesures_thermostat2["body"]["therm_relay_cmd"];
//$setpoint_thermostat2=$json_mesures_thermostat2["body"]["measured"]["setpoint_temp"];

//$url_thermostat3="http://api.netatmo.net/api/getthermstate?access_token=" .  $params['access_token']."&device_id=".$device3."&module_id=".$module3;
//$value_thermostat3= file_get_contents($url_thermostat3);
//$json_mesures_thermostat3 = json_decode($value_thermostat3, true);
//$temperature_thermostat3 = $json_mesures_thermostat3["body"]["measured"]["temperature"];
//$run_thermostat3 = $json_mesures_thermostat3["body"]["therm_relay_cmd"];
//$setpoint_thermostat3=$json_mesures_thermostat3["body"]["measured"]["setpoint_temp"];

echo '<?xml version="1.0" encoding="utf8" ?>';
echo "<netatmo>";
echo "<Temp_Thermo_1>" . $temperature_thermostat1   . "</Temp_Thermo_1>";
echo "<Etat_Thermo_1>" . $run_thermostat1   . "</Etat_Thermo_1>";             // Etat du thermostat, 0 chaudiere a l'arret, 100 chaudiere en marche
echo "<Consigne_Thermo_1>" . $setpoint_thermostat1   . "</Consigne_Thermo_1>";
//echo "<Temp_Thermo_2>" . $temperature_thermostat2   . "</Temp_Thermo_2>";
//echo "<Etat_Thermo_2>" . $run_thermostat2   . "</Etat_Thermo_2>";
//echo "<Consigne_Thermo_2>" . $setpoint_thermostat2   . "</Consigne_Thermo_2>";
//echo "<Temp_Thermo_3>" . $temperature_thermostat3   . "</Temp_Thermo_3>";
//echo "<Etat_Thermo_3>" . $run_thermostat3   . "</Etat_Thermo_3>";
//echo "<Consigne_Thermo_3>" . $setpoint_thermostat3   . "</Consigne_Thermo_3>";
echo "</netatmo>";
}
if ($parameter == "json_therm") {
echo  $therm_resulat_device;
}
if ($parameter == "names_therm") {
	echo "nombre de devices: " . count($therm_json_devices["body"]["devices"]) . "<br>";
		for ($i = 0; $i <= count($therm_json_devices["body"]["devices"]) - 1; $i++) {
			echo "Station Name: " . $therm_json_devices["body"]["devices"][$i]["station_name"];
			echo " - Device No: " . $i ." id: " . $therm_json_devices["body"]["devices"][$i]["_id"] . " Name: " . $therm_json_devices["body"]["devices"][$i]["module_name"] . "<br>";
		}
	echo "<br>nombre de modules: " . count($therm_json_devices["body"]["modules"]) . "<br>";
		for ($i = 0; $i <= count($therm_json_devices["body"]["modules"]) - 1; $i++) {
			echo "Parent Device: " . $therm_json_devices["body"]["modules"][$i]["main_device"];
			echo " - Module No: " . $i ." id: " . $therm_json_devices["body"]["modules"][$i]["_id"] . " Name: " . $therm_json_devices["body"]["modules"][$i]["module_name"] . "<br>";
		}

}
if ($parameter == "therm1") {
$url_mesures_therm1 = "https://api.netatmo.net/api/getthermstate?access_token=" .  $params['access_token'] . "&device_id=" . $therm1_relay . "&module_id=".$therm1_device;
    
$mesures_therm1 = file_get_contents($url_mesures_therm1);
echo $mesures_therm1 ;
}
if ($parameter == "therm1_set_away") {
$url_set_therm1 = "https://api.netatmo.net/api/setthermpoint?access_token=" .  $params['access_token'] . "&device_id=" . $therm1_relay . "&module_id=" . $therm1_device. "&setpoint_mode=away";
    
$set_therm1 = file_get_contents($url_set_therm1);
echo $set_therm1 ;
}
if ($parameter == "therm1_set_program") {
$url_set_therm1 = "https://api.netatmo.net/api/setthermpoint?access_token=" .  $params['access_token'] . "&device_id=" . $therm1_relay . "&module_id=" . $therm1_device. "&setpoint_mode=program";
    
$set_therm1 = file_get_contents($url_set_therm1);
echo $set_therm1 ;
}
if ($parameter == "therm1_set_hg") {
$url_set_therm1 = "https://api.netatmo.net/api/setthermpoint?access_token=" .  $params['access_token'] . "&device_id=" . $therm1_relay . "&module_id=" . $therm1_device. "&setpoint_mode=hg";
    
$set_therm1 = file_get_contents($url_set_therm1);
echo $set_therm1 ;
}

if ($parameter == "therm2") {
$url_mesures_therm2 = "https://api.netatmo.net/api/getthermstate?access_token=" .  $params['access_token'] . "&device_id=" . $therm2_relay . "&module_id=".$therm2_device;
    
$mesures_therm2 = file_get_contents($url_mesures_therm2);
echo $mesures_therm2 ;
}
if ($parameter == "therm2_set_away") {
$url_set_therm2 = "https://api.netatmo.net/api/setthermpoint?access_token=" .  $params['access_token'] . "&device_id=" . $therm2_relay . "&module_id=" . $therm2_device. "&setpoint_mode=away";
    
$set_therm2 = file_get_contents($url_set_therm2);
echo $set_therm2 ;
}
if ($parameter == "therm2_set_program") {
$url_set_therm2 = "https://api.netatmo.net/api/setthermpoint?access_token=" .  $params['access_token'] . "&device_id=" . $therm2_relay . "&module_id=" . $therm2_device. "&setpoint_mode=program";
    
$set_therm2 = file_get_contents($url_set_therm2);
echo $set_therm2 ;
}
if ($parameter == "therm2_set_hg") {
$url_set_therm2 = "https://api.netatmo.net/api/setthermpoint?access_token=" .  $params['access_token'] . "&device_id=" . $therm2_relay . "&module_id=" . $therm2_device. "&setpoint_mode=hg";
    
$set_therm2 = file_get_contents($url_set_therm2);
echo $set_therm2 ;
}

// Section For Weather Station -----------------------------------
$api_url = "https://api.netatmo.net/api/getuser?access_token=" . $params['access_token'];
$requete = file_get_contents($api_url);
$url_devices = "https://api.netatmo.net/api/devicelist?access_token=" .  $params['access_token'];
$resulat_device = file_get_contents($url_devices);  
$json_devices = json_decode($resulat_device,true);
$json_objects = json_decode($resulat_device);
$module_interne = $json_devices["body"]["devices"][0]["_id"];
$module_externe = $json_devices["body"]["modules"][1]["_id"];
$module_interne2 = $json_devices["body"]["modules"][2]["_id"];
$module_interne3 = $json_devices["body"]["modules"][3]["_id"];
$module_interne4 = $json_devices["body"]["modules"][4]["_id"];



if ($parameter == "json") {
echo  $resulat_device;
}
if ($parameter == "json_viewer") {
print('    
<html>
<style type="text/css">
    body {
      font: 11pt arial;
    }
    #jsoneditor {
      width: 800px;
      height: 2000px;
    }
</style>
<head>
    <title><YAGDA></title>
</head>
<body>
');
	echo "nombre de devices: " . count($json_devices["body"]["devices"]) . "<br>";
		for ($i = 0; $i <= count($json_devices["body"]["devices"]) - 1; $i++) {
			echo "Station Name: " . $json_devices["body"]["devices"][$i]["station_name"];
			echo " - Device No: " . $i ." id: " . $json_devices["body"]["devices"][$i]["_id"] . " Name: " . $json_devices["body"]["devices"][$i]["module_name"] . "<br>";
		}
	echo "<br>nombre de modules: " . count($json_devices["body"]["modules"]) . "<br>";
		for ($i = 0; $i <= count($json_devices["body"]["modules"]) - 1; $i++) {
			echo "Parent Device: " . $json_devices["body"]["modules"][$i]["main_device"];
			echo " - Module No: " . $i ." id: " . $json_devices["body"]["modules"][$i]["_id"] . " Name: " . $json_devices["body"]["modules"][$i]["module_name"] . "<br>";
		}

print('
<br>
<link rel="stylesheet" type="text/css" href="jsoneditor/jsoneditor.css"/>
<script src="jsoneditor/jsoneditor.js"></script>
<div id="jsoneditor"></div>
<script>
  var container = document.getElementById(\'jsoneditor\');
  var options = {
    mode: "view"
  };
  var json = ');

  echo $resulat_device;

  print('
  var editor = new jsoneditor.JSONEditor(container, options, json);
</script>
');
}
if ($parameter == "names") {
	echo "nombre de devices: " . count($json_devices["body"]["devices"]) . "<br>";
		for ($i = 0; $i <= count($json_devices["body"]["devices"]) - 1; $i++) {
			echo "Station Name: " . $json_devices["body"]["devices"][$i]["station_name"];
			echo " - Device No: " . $i ." id: " . $json_devices["body"]["devices"][$i]["_id"] . " Name: " . $json_devices["body"]["devices"][$i]["module_name"] . "<br>";
		}
	echo "<br>nombre de modules: " . count($json_devices["body"]["modules"]) . "<br>";
		for ($i = 0; $i <= count($json_devices["body"]["modules"]) - 1; $i++) {
			echo "Parent Device: " . $json_devices["body"]["modules"][$i]["main_device"];
			echo " - Module No: " . $i ." id: " . $json_devices["body"]["modules"][$i]["_id"] . " Name: " . $json_devices["body"]["modules"][$i]["module_name"] . "<br>";
		}

}
if ($parameter == "selected_modules") {
echo "Selected Modules: <br>";
echo "mod interne ----- (int): " . $module_interne . "<br>";
echo "mod externe ---- (ext): " . $module_externe  . "<br>";
echo "mod interne2 (mod2): " . $module_interne2 . "<br>";
echo "mod interne3 (mod3): " . $module_interne3 . "<br>";
echo "mod interne4 (mod4): " . $module_interne4 . "<br>";
}
if ($parameter == "int") {
$url_mesures_internes = "https://api.netatmo.net/api/getmeasure?access_token=" .  $params['access_token'] . "&device_id=" . $module_interne . "&scale=max&type=Temperature,CO2,Humidity,Pressure,Noise&date_end=last";
$mesures_internes = file_get_contents($url_mesures_internes);
echo $mesures_internes ;
}
if ($parameter == "ext") {
$url_mesures_externes = "https://api.netatmo.net/api/getmeasure?access_token=" .  $params['access_token'] . "&device_id=" . $module_interne . "&module_id=" . $module_externe . "&scale=max&type=Temperature,Humidity&date_end=last";
$mesures_externes = file_get_contents($url_mesures_externes);   
echo $mesures_externes ;
}
if ($parameter == "mod2") {
$url_mesures_internes2 = "https://api.netatmo.net/api/getmeasure?access_token=" .  $params['access_token'] . "&device_id=" .  $module_interne . "&module_id=" . $module_interne2 . "&scale=max&type=Temperature,Humidity,CO2&date_end=last";
$mesures_internes2 = file_get_contents($url_mesures_internes2);
echo $mesures_internes2 ;
}
if ($parameter == "mod3") {
$url_mesures_internes3 = "https://api.netatmo.net/api/getmeasure?access_token=" .  $params['access_token'] . "&device_id=" .  $module_interne . "&module_id=" . $module_interne3 . "&scale=max&type=Temperature,Humidity,CO2&date_end=last";
$mesures_internes3 = file_get_contents($url_mesures_internes3);
echo $mesures_internes3 ;
}
if ($parameter == "mod4") {
$url_mesures_internes4 = "https://api.netatmo.net/api/getmeasure?access_token=" .  $params['access_token'] . "&device_id=" .  $module_interne . "&module_id=" . $module_interne4 . "&scale=max&type=Temperature,Humidity,CO2&date_end=last";
$mesures_internes4 = file_get_contents($url_mesures_internes4);
echo $mesures_internes4 ;
}

// Section Infos
if ($parameter == "") {
print('    
<html>
<style type="text/css">
    body {
      font: 11pt arial;
    }
</style>
<head>
    <title><YAGDA></title>
</head>
<body>
<br>
Available parameters:
<br><br>
For Netatmo thermostat:
<br><br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json_viewer_therm<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=xml_therm<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json_therm<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=names_therm<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=therm1<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=therm1_set_away<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=therm1_set_program<br>
<br><br>
For Netatmo Weather:<br><br>

http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=json_viewer<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=names<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=selected_modules<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=int<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=ext<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=mod2<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=mod3<br>
http://XXX.XXX.XXX.XXX/netatmo/thermtatmo.php?parameter=mod4<br>

');
}

?>

post-826-0-44498000-1439935685_thumb.jpg

Netatmo_Thermostat V3.2.vfib

thermtatmo.shared.php

  • Upvote 2
  • 1 mois après...
Posté(e)

Bonsoir, je viens de monter mon netatmo et je suis emm... Je voudrais déclencher ma chaudière via le netatmo

Faisable via IFTTT & DO

J'ai regardé le plugin, mais je ne vois pas la commande pour passer en manuel et mettre la T° de consigne

Je récupère bien via http direct 

 

https://api.netatmo.net/api/devicelist?access_token=xxx&app_type=app_thermostat  les param de mon netatmo mais en testant 

https://api.netatmo.net/api/setthermpoint?access_token=xxx&device_id=04:00:00:07:8b:7c&module_id=70:ee:50:07:90:c6&setpoint_mode=manual

J'ai {"error":{"code":9,"message":"Device not found"}}

A l'aide svp

Posté(e)
{"body":{"modules":[{"_id":"04:00:00:07:8b:7c","date_setup":{"sec":1444732642,"usec":642000},"main_device":"70:ee:50:07:90:c6",
"module_name":"Thermostat","type":"NATherm1"


"devices":[{"_id":"70:ee:50:07:90:c6","cipher_id":"enc:16:wG9\/XGBTiOv4lMOv

J'ai pris les id ici dans le résultat. 

$therm1_device = $therm_json_devices["body"]["modules"][1]["_id"];    04:00:00:07:8b:7c
$therm1_relay = $therm_json_devices["body"]["devices"][0]["_id"];     70:ee:50:07:90:c6
  • Upvote 2
Posté(e)

Oui, avec json_viewer j'obtiens : 

Warning: file_get_contents(https://api.netatmo.net/api/devicelist?access_token=xxx) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/kwartz/www/llc/thermtatmo.php on line 172
nombre de devices: 0

nombre de modules: 0

Ligne 172 : $resulat_device = file_get_contents($url_devices);  

 

Quand je rentre  https://api.netatmo.net/api/devicelist?access_token=xxx     j'ai {"error":{"code":9,"message":"Device not found"}}

 

J'ai eu les paramètres en entrant directement  https://api.netatmo.net/api/devicelist?access_token=xxx&app_type=app_thermostat  avec le bon access_token ( j'ai repris ce que tu avais mis en php )

J'obtiens : 

{"body":{"modules":[{"_id":"04:00:00:07:8b:7c","date_setup":{"sec":1444732642,"usec":642000},"main_device":"70:ee:50:07:90:c6","module_name":"Thermostat","type":"NATherm1","firmware":31,"last_message":1444851431,"last_seen":1444851431,"rf_status":93,"battery_vp":4787,"therm_orientation":3,"therm_relay_cmd":0,"dashboard_data":{"time_utc":1444851420,"device_id":22,"BoilerOn":0,"BoilerOff":10,"Temperature":22.9,"date_max_temp":1444849031,"date_min_temp":1444796151,"min_temp":17.4,"max_temp":23.2},"data_type":["Temperature","BoilerOn","BoilerOff","Sp_temperature"]}],"devices":[{"_id":"70:ee:50:07:90:c6","cipher_id":"enc:16:wG9\/XkkkkkU\/IJyh5ygkkklrxqKS0CrQfWv4LqCSzy+W7","date_setup":{"sec":1444732657,"usec":34000},"firmware":43,"heating_system":{"heating_energy":"gas","heating_system_window_seen":true,"home_size":210,"home_type":"house"},"hw_version":248,"last_status_store":1444851431,"last_upgrade":1440210137,"modules":["04:00:00:07:8b:7c"],"place":{"city":"Boussois","country":"FR","from_ip":true,"location":[4.0412001609802,50.289100646973],"timezone":"Europe\/Paris"},"setpoint":[],"setpoint_order":{"04:00:00:07:8b:7c":[]},"station_name":"Maison","therm_program":{"04:00:00:07:8b:7c":{"zones":[{"type":0,"name":"Confort","temp":19,"id":0},{"type":1,"name":"Nuit","temp":17,"id":1},{"type":2,"temp":12,"id":2},{"type":3,"temp":7,"id":3},{"type":5,"name":"\u00c9co","temp":16,"id":4}],"timetable":[{"id":1,"m_offset":0},{"id":0,"m_offset":405},{"id":4,"m_offset":450},{"id":0,"m_offset":990},{"id":1,"m_offset":1380},{"id":0,"m_offset":1845},{"id":4,"m_offset":1890},{"id":0,"m_offset":2100},{"id":1,"m_offset":2820},{"id":0,"m_offset":3285},{"id":1,"m_offset":4260},{"id":0,"m_offset":4725},{"id":4,"m_offset":4770},{"id":0,"m_offset":5040},{"id":1,"m_offset":5700},{"id":0,"m_offset":6165},{"id":4,"m_offset":6225},{"id":0,"m_offset":6750},{"id":1,"m_offset":7140},{"id":0,"m_offset":7605},{"id":1,"m_offset":8580},{"id":0,"m_offset":9165},{"id":1,"m_offset":10020}],"program_id":{"$id":"561cdf2ec8bd00cf718b45c3"},"name":"Default"}},"therm_program_order":{"04:00:00:07:8b:7c":[]},"type":"NAPlug","udp_conn":true,"wifi_status":59,"data_type":[]}]},"status":"ok","time_exec":3.8978931903839,"time_server":1444851642}
Posté(e)

quand on fait trop de requètes, l'api de netatmo renvoie un 404

 

regarde aussi ces lignes, comme j'ai deux thermostats, l'ordre n'est peut être pas bon....

 

$therm1_device = $therm_json_devices["body"]["modules"][1]["_id"];
$therm1_relay = $therm_json_devices["body"]["devices"][0]["_id"];
$therm2_device = $therm_json_devices["body"]["modules"][0]["_id"];
$therm2_relay = $therm_json_devices["body"]["devices"][1]["_id"];
Posté(e)

Pas logique ça. .. si tu n'appelle pas de fonction weather rien ne sera lancé dans cette section...

a mon avis tu floodais les serveurs netatmo ;-)

Sent from my Note4

Posté(e)

Super,

Tu pourra partager la fonction php quand tu sera sur que ça fonctionne bien ?

Je la rajouterai dans github.

 

Perso je n'ai pas été aussi loin, j'ai fait la programmation via l'appli netatmo officielle et je me contente de changer le mode (away, program, hors gel)

A mon sens la programmation des T° ne se fait qu'une fois et si un jour il faut une dérogation, on le fait sur le thermostat lui même. (WAF and KISS) ;-)

Posté(e)

Ah oui c'est vrai que en v4 on peut utiliser le https...

Si on peut se passer du php pour certaines fonctions c'est mieux.

Sent from my Note4

×
×
  • Créer...