Salut à tous,
après avoir continué à chercher, je suis arriver à un script qui me convient.
Voici ma solution pour d'autres "galériens".
Il faut créer:
- 3 compteurs virtuels de type "instantanée et compteur" et récupérer leurs IDX en mode graphique via Domoticz
- 3 variables utilisateurs de type "entier" (pour moi totalP1, totalP2 et totalP3) en mode graphique via Domoticz
- 1 variable utilisateur de type "chaîne" (pour moi lastupdate) en mode graphique via Domoticz
- créer un fichier de nom script_device_VOTRENOM.lua
- y coller le code suivant (en modifiant pour vos données, IDX,...)
Code : Tout sélectionner
--script permettant des lires des donnees de sonde OWL et de remplir des compteurs virtuels (instantannée et total)
-- Initialisation des variables locales
local totalP1 = uservariables['totalP1']
local totalP2 = uservariables['totalP2']
local totalP3 = uservariables['totalP3']
local lastupdate = uservariables['lastupdate']
commandArray = {}
if devicechanged['Sondes - OWL'] then
function timedifference (s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
--on recupere la date d'execution du script
update = (otherdevices_lastupdate['Sondes - OWL'])
--print(update)
--on calcule l'intervalle de temps en secondes entre deux executions du script
intervalle = timedifference(lastupdate)
--print(intervalle)
--on recupere les valeurs en Amperes des sondes OWL
l1, l2, l3 = string.match(otherdevices_svalues['Sondes - OWL'], "(%d+.%d*);(%d+.%d*);(%d+.%d*)")
--print(l1)
--print(l2)
--print(l3)
--on les transforme en Watt
p1 = l1 * 230
--print(p1)
p2 = l2 * 230
--print(p2)
p3 = l3 * 230
--print(p3)
--on calcule le delta (entier) en Wh a aujouter au compteur total
deltaP1 = math.floor(p1/3600*intervalle)
--print(deltaP1)
deltaP2 = math.floor(p2/3600*intervalle)
--print(deltaP2)
deltaP3 = math.floor(p3/3600*intervalle)
--print(deltaP3)
--on incremente les compteurs totaux
totalP1 = deltaP1 + totalP1
totalP2 = deltaP2 + totalP2
totalP3 = deltaP3 + totalP3
--print(totalP1)
--print(totalP2)
--print(totalP3)
--mise a jour variablees locales
commandArray['Variable:totalP1'] = tostring(totalP1)
commandArray['Variable:totalP2'] = tostring(totalP2)
commandArray['Variable:totalP3'] = tostring(totalP3)
commandArray['Variable:lastupdate'] = tostring(update)
--on exporte les donnees P et totalP vers les compteurs virtuels
p1 = tonumber(p1)
totalP1 = tonumber(totalP1)
commandArray[1]={['UpdateDevice']= 50 .. "|0|" .. p1 .. ';' .. totalP1 }
p2 = tonumber(p2)
totalP2 = tonumber(totalP2)
commandArray[2]={['UpdateDevice']= 55 .. "|0|" .. p2 .. ';' .. totalP2 }
p3 = tonumber(p3)
totalP3 = tonumber(totalP3)
commandArray[3]={['UpdateDevice']= 56 .. "|0|" .. p3 .. ';' .. totalP3 }
end
return commandArray
Si vous voyez des améliorations, faites signe.