Page 3 sur 3

Re: Récupérer valeur analogique (température) IPX800 V3 dans domoticz

Publié : 20 oct. 2019, 12:34
par mmikee02
Voici pour l'entrée analogique 2 , avec , comme sonde, une sonde de température TC100.

Code : Tout sélectionner

-- récupération de sortie analogique 2 (AN2) sur une IPX800 V.3
-- avec fonction arrondie
-- dans ce cas-ci : une sonde température TC100
time=os.date("*t")

IDX=XXX -- IDX du capteur virtuel que vous aurez créé pour l'occasion.

json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()  -- For Linux
 
local config=assert(io.popen('/usr/bin/curl "http://LOGIN:MOT_DE_PASSE@IP_DE_L'IPX/api/xdevices.json?cmd=30"'))

local blocjson = config:read('*all')
 config:close()
print (blocjson)
 local jsonValeur = json:decode(blocjson)

commandArray = {}

 if time.min%5==0 then --1 minute pour essai, 5 en fonctionnement normal pour moi
     
 function round(num, dec)
  local mult = 10^(dec or 1)
  return math.floor(num * mult + 0.5) / mult
  end

temp=(tonumber((jsonValeur.AN2)*0.00323)-0.25) / 0.028 --((X* 0.00323) - 0.25) / 0.028 formule de calcul dispo sur wiki gce : https://gce-electronics.com/helpdesk/knowledgebase.php?article=39
--print (temp) --  print valeur non arrondie

tempA2=round(temp) 

print (tempA2) -- un print avec valeur arrondie

commandArray['UpdateDevice'] = IDX .. '|0|' .. tostring(tempA2)

end

return commandArray