Page 1 sur 1

cout charge VE

Publié : 08 juin 2024, 08:06
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

Re: cout charge VE

Publié : 08 juin 2024, 15:15
par Flying Domotic
Peut être qu'un envoyant des Watts et en divisant par 1000, ça pourrait arranger un peu les choses ?

Re: cout charge VE

Publié : 08 juin 2024, 15:17
par sphinxou
J'envoie des euros

Re: cout charge VE

Publié : 08 juin 2024, 15:27
par Flying Domotic
Alors peut être envoyer des cents et diviser par 100 à l'affichage

Re: cout charge VE

Publié : 09 juin 2024, 08:03
par sphinxou
Effectivement sa fonctionne

Merci

Modération

Publié : 09 juin 2024, 08:57
par Keros
Sujet déplacé dans la section dédiée aux Scripts.