Skip to content

Instantly share code, notes, and snippets.

@tisseurdetoile
Created February 24, 2016 08:19
Show Gist options
  • Save tisseurdetoile/f06509b67eadb2996b2a to your computer and use it in GitHub Desktop.
Save tisseurdetoile/f06509b67eadb2996b2a to your computer and use it in GitHub Desktop.
Domoticz
------------------------------------------------------------------------------
--
-- Copyright © 2016 Le TisseurDeToile <webmaster@tisseurdetoile.net> and released under
-- the GNU General Public License, v2 or later.
-- NOTA : don't forget to create variable
--
-- Installation :
-- Créer les variables Utilisateurs suivantes : CONSO_LAST, CONSO_LAST_HC, CONSO_LAST_HP
-- Créer deux capteur virtuel : Capteur electrique ent noter leur index
------------------------------------------------------------------------------
--
local capteurGlobal = 'CONSO'
local debug = 'OUI' -- mode debug
local meter_base = 'CONSO_LAST'
local flagHC = 'HC'
local delta = 0
local inc = 0
local idxCptHP = '57'
local idxCptHC = '59'
------------------------------------------------------------------------------
-- Fonction de mise à jour
function update(id, power, energy)
commandArray[inc]= {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy}
inc = inc + 1
return
end
commandArray = {}
if (devicechanged[capteurGlobal]) then
conso_last = tonumber(uservariables['CONSO_LAST'])
if not conso_last then
conso_last = 0
end
-- Recuperation des valeurs du compteur global
local consoCumule
local consoInstant
consoInstant, consoCumule = otherdevices_svalues[capteurGlobal]:match("([^;]+);([^;]+)")
consoInstant = tonumber(consoInstant)
consoCumule = tonumber(consoCumule)
delta = consoCumule - conso_last
commandArray['Variable:CONSO_LAST'] = tostring(consoCumule)
local conso_hc = tonumber(uservariables['CONSO_LAST_HC'])
local conso_hp = tonumber(uservariables['CONSO_LAST_HP'])
if (debug == 'OUI') then
print('conso_last = '..tostring(conso_last))
print('delta = '..tostring(delta))
print('Inst = '..tostring(consoInstant))
print('Cum = '..tostring(consoCumule))
if (otherdevices[flagHC] == 'On') then
print('période : Heure Creuse')
else
print('période : Heure Pleine')
end
end
if (otherdevices[flagHC] == 'On') then
-- Periode heures creuse
commandArray['Variable:CONSO_LAST_HC'] = tostring(conso_hc + delta)
update(idxCptHC, consoInstant, conso_hc)
update(idxCptHP, 0, conso_hp)
else
commandArray['Variable:CONSO_LAST_HP'] = tostring(conso_hp + delta)
update(idxCptHP, consoInstant, conso_hp)
update(idxCptHC, 0, conso_hc)
end
end
return commandArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment