Page 2 of 2

Re: LUA scene string

Posted: Tuesday 22 December 2020 9:47
by waaren
bofisko wrote: Tuesday 22 December 2020 1:52 It is not working. I get tablecool and tableheat but no together table.
How can I do it? I need this in want.jpg in attachment.
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


Re: LUA scene string

Posted: Tuesday 22 December 2020 12:11
by bofisko
THANK YOU NOW I WORKING... If you send me privat message a I would like to somehow reward you for your perfect work.
And I apologize once again for my amateurism.

Re: LUA scene string

Posted: Tuesday 22 December 2020 12:15
by waaren
bofisko wrote: Tuesday 22 December 2020 12:11 THANK YOU NOW I WORKING
I do not look for another reward then your thx. Happy that I could be of any help.

Re: LUA scene string

Posted: Tuesday 22 December 2020 12:37
by bofisko
waaren wrote: Tuesday 22 December 2020 12:15
bofisko wrote: Tuesday 22 December 2020 12:11 THANK YOU NOW I WORKING
I do not look for another reward then your thx. Happy that I could be of any help.
Then just one thing - many thanks. And I will finish here by publishing a VD for measuring air conditioning consumption if anyone is interested.