LUA scene string Topic is solved

Moderator: leecollings

User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA scene string

Post 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

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
bofisko
Posts: 23
Joined: Sunday 22 November 2020 17:44
Target OS: Windows
Domoticz version:
Contact:

Re: LUA scene string

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA scene string

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
bofisko
Posts: 23
Joined: Sunday 22 November 2020 17:44
Target OS: Windows
Domoticz version:
Contact:

Re: LUA scene string

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest