Adding the values of one month for these two tables together is what I showed in my previous post. Below script will do that for all months.
The code is all standard Lua, without any link to domoticz, so please visit the official Lua documentation site if you need more clarification
Code: Select all
local id = fibaro:getSelfId();
local ip = fibaro:get(id, "IPAddress");
local port = fibaro:get(id, "TCPPort");
local Daikin = Net.FHttp(ip, port)
function tprint (t, indent, done)
local done = done or {}
indent = indent or 0
for key, value in pairs (t) do
pre = (string.rep (" ", indent)) -- indent it
if type (value) == "table" and not done[value] then
done [value] = true
fibaro:debug(pre .. tostring (key) .. ":");
tprint (value, indent + 2, done)
elseif type(value) == 'function' and not done[value] then
fibaro:debug( pre .. (tostring (key) .. "()"))
else
pre = pre .. (tostring (key) .. ": ")
fibaro:debug(pre .. tostring(value))
end
end
end
r,s,e = Daikin:GET("/aircon/get_year_power_ex")
if e == 0 then
local a = {}
local myTable = {}
for v in r:gmatch('([^,]+)') do
table.insert(a, v)
end
local function sum(line)
local total = 0
local myTable = {}
for str in line:gmatch("(%d+)" ) do
table.insert(myTable, str)
total = total + tonumber(str)
end
return myTable, total
end
-- creating heating and cooling table
local myHeatingTable, heatingTotal = sum(a[2])
local myCoolingTable, coolingTotal = sum(a[4])
-- creating totalized table and sum
local myTotalizedTable = {}
local yearTotal = 0
for key, value in ipairs(myHeatingTable) do
table.insert(myTotalizedTable, value + myCoolingTable[key] )
yearTotal = yearTotal + myTotalizedTable[#myTotalizedTable]
end
fibaro:debug('-- Now dumping table a')
tprint(a)
fibaro:debug('-- Now dumping heating and cooling and Total tables')
tprint(myHeatingTable)
tprint(myCoolingTable)
tprint(myTotalizedTable)
thisMonth = math.floor(os.date('%m'))
fibaro:debug('Month total : ' .. thisMonth ..' - '.. myTotalizedTable[thisMonth] )
fibaro:debug('Year total: ' .. yearTotal )
end