Re: Ecodevices GCE : lecture Base index
Publié : 18 sept. 2016, 13:43
Bien vu pour les corrections
. J'ai voulu aller trop vite.
Reprenez le contrôle de votre domotique
https://easydomoticz.com/forum/
Code : Tout sélectionner
-- EcoDevices
-- == CONFIGURATION =========================================================================
-- Mettre ici l'adresse de l' Eco Devices
local ECO_DEVICES = '192.168.1.10'
-- Mettre ici les index correspondant aux différents capteurs virtuels Domoticz. On les trouve
-- dans la colonne Idx de la page Réglages / Dispositifs (0 : pas utilisé)
local T1_id = 0
local T2_id = 0
local C1_id = 487
local Mul_C1 = 0.1
local C2_id = 0
local Mul_C2 = 100 -- L'Eco Devices renvoie des ml en decimales, mais le compteur Domoticz n'affiche
-- que des entiers
-- == FIN CONFIGURATION =====================================================================
-- ------------------------------------------------------------------------------------------
-- Fonction pour extraire la sortie console d'une commande
--
function os.capture(cmd, raw)
local handle = assert(io.popen(cmd, 'r'))
local output = assert(handle:read('*a'))
handle:close()
if raw then
return output
end
output = string.gsub(
string.gsub(
string.gsub(output, '^%s+', ''),
'%s+$',
''
),
'[\n\r]+',
' '
)
return output
end
-- ------------------------------------------------------------------------------------------
-- Fonction pour mettre à jour les consommations
--
local function update(commandArray, id, power, energy, type)
if (type < 2) then
table.insert(commandArray, {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy})
else
table.insert(commandArray, {['UpdateDevice'] = id .. "|0|" .. energy})
end
return
end
-- ------------------------------------------------------------------------------------------
-- ------------------------------------------------------------------------------------------
-- Chargement du decodeur JSON
json = (loadfile "/home/pi/domoticz/scripts/lua/json.lua")()
commandArray = {}
-- Path to curl
local curl = '/usr/bin/curl'
-- url à joindre
local url = ' http://' .. ECO_DEVICES .. '/api/xdevices.json?cmd=10/'
local url = ' http://' .. ECO_DEVICES .. '/api/xdevices.json?cmd=20/'
local retour = os.capture(curl .. url, true);
-- print('capture ' .. retour)
local jsonData = json:decode(retour)
if (T1_id ~= 0) then
update(commandArray, T1_id, tonumber(jsonData.T1_PAPP), tonumber(jsonData.T1_BASE), 1)
end
if (T2_id ~= 0) then
update(commandArray, T2_id, tonumber(jsonData.T2_PAPP), tonumber(jsonData.T2_BASE), 1)
end
if (C1_id ~= 0) then
update(commandArray, C1_id, 0, tonumber(jsonData.INDEX_C1) * Mul_C1, 2)
end
if (C2_id ~= 0) then
update(commandArray, C2_id, 0, tonumber(jsonData.Day_C1) * Mul_C2, 2)
end
return commandArrayCode : Tout sélectionner
-- EcoDevices
-- == CONFIGURATION =========================================================================
-- Mettre ici l'adresse de l' Eco Devices
local ECO_DEVICES = '192.168.1.10'
-- Mettre ici les index correspondant aux différents capteurs virtuels Domoticz. On les trouve
-- dans la colonne Idx de la page Réglages / Dispositifs (0 : pas utilisé)
local T1_id = 0
local T2_id = 0
local C1_id = 0
local Mul_C1 = 1
local C2_id = 488
local Mul_C2 = 100 -- L'Eco Devices renvoie des ml en decimales, mais le compteur Domoticz n'affiche
-- que des entiers
-- == FIN CONFIGURATION =====================================================================
-- ------------------------------------------------------------------------------------------
-- Fonction pour extraire la sortie console d'une commande
--
function os.capture(cmd, raw)
local handle = assert(io.popen(cmd, 'r'))
local output = assert(handle:read('*a'))
handle:close()
if raw then
return output
end
output = string.gsub(
string.gsub(
string.gsub(output, '^%s+', ''),
'%s+$',
''
),
'[\n\r]+',
' '
)
return output
end
-- ------------------------------------------------------------------------------------------
-- Fonction pour mettre à jour les consommations
--
local function update(commandArray, id, power, energy, type)
if (type < 2) then
table.insert(commandArray, {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy})
else
table.insert(commandArray, {['UpdateDevice'] = id .. "|0|" .. energy})
end
return
end
-- ------------------------------------------------------------------------------------------
-- ------------------------------------------------------------------------------------------
-- Chargement du decodeur JSON
json = (loadfile "/home/pi/domoticz/scripts/lua/json.lua")()
commandArray = {}
-- Path to curl
local curl = '/usr/bin/curl'
-- url à joindre
local url = ' http://' .. ECO_DEVICES .. '/api/xdevices.json?cmd=20/'
local retour = os.capture(curl .. url, true);
-- print('capture ' .. retour)
local jsonData = json:decode(retour)
if (T1_id ~= 0) then
update(commandArray, T1_id, tonumber(jsonData.T1_PAPP), tonumber(jsonData.T1_BASE), 1)
end
if (T2_id ~= 0) then
update(commandArray, T2_id, tonumber(jsonData.T2_PAPP), tonumber(jsonData.T2_BASE), 1)
end
if (C1_id ~= 0) then
update(commandArray, C1_id, 0, tonumber(jsonData.INDEX_C1) * Mul_C1, 2)
end
if (C2_id ~= 0) then
update(commandArray, C2_id, 0, tonumber(jsonData.Day_C1) * Mul_C2, 2)
end
return commandArray