cout charge VE

Forum dédié aux problématiques concernant les scripts pour DomoticZ.
Entourez votre code et les logs avec les balises nommées code grâce au bouton <\>.
sphinxou
Messages : 231
Inscription : 03 déc. 2016, 13:37

cout charge VE

Message par sphinxou »

bonjour

je suis en phase de test avec ce script pour avoir le cout d'une charge de ma voiture électrique tout fonctionne sauf le compteur incrémentiel dans les log du compteur il ne prend pas les chiffres a virgule une idée?

merci

Code : Tout sélectionner

dofile('/home/domoticz/domoticz/scripts/lua/modules.lua')
--------  Paramètres  ---------
owl_name = "Charge_VE_CONSO"

-------------------------------
function update(device, id, INCREMENT, index)
    commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. tonumber(INCREMENT)}
    return
end

local function updatenum(dev, value1)
    local cmd = string.format("%d|0|%0.f", otherdevices_idx[dev], value1)
    table.insert (commandArray, { ['UpdateDevice'] = cmd } )
end
local prixHP = uservariables['prix_HP']
local prixHC = uservariables['prix_HC']
local couthp = uservariables['couthp']
local couthc = uservariables['couthc']
local lastValueCptElecGlobal = uservariables['LastValueCptElecGlobal']
 local conso_hp = tostring(uservariables['consoHP'])
local conso_hc = tostring(uservariables['consoHC'])
-- local consoDelta = tonumber(conso - lastValueCptElecGlobal)

commandArray = {}

if (devicechanged[owl_name] and otherdevices['charge VE'] == 'On') then

    datetime = os.date("*t") -- table is returned containing date & time information

    owl_value = otherdevices_svalues[owl_name]
    puissance,conso=owl_value:match("([^;]+);([^;]+)")
    conso = tonumber(conso/1000)
    
    consoDelta = tonumber(conso - lastValueCptElecGlobal)
   
    
     lastValueCptElecGlobal = tonumber(lastValueCptElecGlobal)
     
   

    
    -- Heure pleine de 7h à 23h
    if(datetime.hour >= 6 and datetime.hour < 22) then
        
        HC = conso_hc
        HP = consoDelta + conso_hp
        consoDeltacompteur = consoDelta * prixHP
        commandArray['Variable:consoHP'] = tostring(HP)
         commandArray['Variable:couthp'] = tostring((consoDelta*prixHP) + couthp)
    -- heure creuse
    else
        HC = (consoDelta + conso_hc)
        consoDeltacompteur = consoDelta * prixHC
        HP = conso_hp
        commandArray['Variable:consoHC'] = tostring(HC) 
         commandArray['Variable:couthc'] = tostring((consoDelta*prixHC) + couthc)
    end


    
    local facture = tostring(couthc) + tostring(couthp)
 
commandArray['Variable:LastValueCptElecGlobal'] = tostring(conso)

 print('Delta conso = '..tostring(consoDeltacompteur))

update(cout_ve, 7631, consoDeltacompteur,0)

end

if (devicechanged['Charge_VE']) == 'ON' then
    
    commandArray['charge VE']='On'

end
if (devicechanged['Charge_VE']) == 'Off' then
    
    commandArray['charge VE']='Off'

end
return commandArray
Domoticz 4.9700/ rfxcom /sonde diy/raspberry pi3+HDD/cirusms/contact de porte diy
Flying Domotic
Messages : 772
Inscription : 10 mars 2020, 15:26

Re: cout charge VE

Message par Flying Domotic »

Peut être qu'un envoyant des Watts et en divisant par 1000, ça pourrait arranger un peu les choses ?
sphinxou
Messages : 231
Inscription : 03 déc. 2016, 13:37

Re: cout charge VE

Message par sphinxou »

J'envoie des euros
Domoticz 4.9700/ rfxcom /sonde diy/raspberry pi3+HDD/cirusms/contact de porte diy
Flying Domotic
Messages : 772
Inscription : 10 mars 2020, 15:26

Re: cout charge VE

Message par Flying Domotic »

Alors peut être envoyer des cents et diviser par 100 à l'affichage
sphinxou
Messages : 231
Inscription : 03 déc. 2016, 13:37

Re: cout charge VE

Message par sphinxou »

Effectivement sa fonctionne

Merci
Domoticz 4.9700/ rfxcom /sonde diy/raspberry pi3+HDD/cirusms/contact de porte diy
Keros
Messages : 6638
Inscription : 23 juil. 2019, 20:57

Modération

Message par Keros »

Sujet déplacé dans la section dédiée aux Scripts.
Répondre