I have a "Total" energy/usage counter, and a "Solar" energy/usage counter, they both work great, but i wanted to have a idea of how much energy i waste, so i tweaked a LUA script to update a "Waste" energy/usage counter, the problem is it registers the wasted energy but doesnt calculate the energy usage based on the value of the wasted energy.
I read somewere that LUA doesnt work correctly when calculating energy usage, and efectivly it does not do the computation, it just takes the energy value from the other counter, is there anyway to make this work on dzvents?
Thanks in advance

Code: Select all
-- Get current date & time
t1 = os.time()
local currentDate = os.date("*t"); -- sets up currentDate.[table]
-- (currentDate.year [full], .month [1-12], .day [1-31], .hour [0-23], .min [0-59], .sec [0-59], .wday [0-6 {Sun-Sat}])
sCurrentTime = currentDate.year .. "-" .. currentDate.month .. "-" .. currentDate.day .. " " .. currentDate.hour .. ":" .. currentDate.min .. ":" .. currentDate.sec
function update(device, id, power, energy, index)
commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy}
end
commandArray = {}
TotalPowerUsage, TotalEnergyUsage = otherdevices_svalues["Total"]:match("([^;]+);([^;]+)")
if tonumber(TotalPowerUsage) <=0 then
WastePowerBalance = -(TotalPowerUsage)
WasteEnergyBalance = TotalEnergyUsage
end
if tonumber(TotalPowerUsage) >=1 then
WastePowerBalance = 0
WasteEnergyBalance = TotalEnergyUsage
end
update("Waste", 98, WastePowerBalance, WasteEnergyBalance, 2) -- 98 is the ID of the dummy incoming device
return commandArray