Page 1 of 2

LUA scene string

Posted: Sunday 20 December 2020 13:10
by bofisko
Please can you someone help me with lua scene in fibaro HC2?

I have string = "cool=0/0/0/0/0/10/59/206/46/37/36/23"

I would like to take number between "/" and assigned it for a month of the year. ( there are 12 number whitch show value device for month of the year)
Which command, function I should use for it?

Thanks

Re: LUA scene string

Posted: Sunday 20 December 2020 14:06
by waaren
bofisko wrote: Sunday 20 December 2020 13:10 I would like to take number between "/" and assigned it for a month of the year. ( there are 12 number whitch show value device for month of the year)
Which command, function I should use for it?

Code: Select all

local myString = "cool=0/0/0/0/0/10/59/206/46/37/36/23"
local myTable = {}
local myMonth = 12

for str in myString:gmatch("(%d+)" ) do
    table.insert(myTable, str)
end

print('Month: ' .. myMonth ..' ==> device: '.. myTable[myMonth])

Re: LUA scene string

Posted: Sunday 20 December 2020 18:54
by bofisko
THANK YOU IT IS WORKING!!
I get my years consumption from my DAIKIN per mouth.

I write this lua. I know that i possible to write better but it is my first work.
If someone to want to simplify I would like for it.

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)
local a = {}
local b = {}

r,s,e = Daikin:GET("/aircon/get_year_power_ex") 
if e == 0 then  
	i = 0
	for v in string.gmatch(r, '([^,]+)') do
	    i = i + 1  
 	    a[i] = v
	end

local myString = a[4]
local myTable = {}
local myMonth = 1

for str in myString:gmatch("(%d+)" ) do
    table.insert(myTable, str)
end

fibaro:debug('Month: ' .. myMonth ..' ==> device: '.. myTable[myMonth])
fibaro:debug('Month: ' .. myMonth+1 ..' ==> device: '.. myTable[myMonth+1])
fibaro:debug('Month: ' .. myMonth+2 ..' ==> device: '.. myTable[myMonth+2])
fibaro:debug('Month: ' .. myMonth+3 ..' ==> device: '.. myTable[myMonth+3])
fibaro:debug('Month: ' .. myMonth+4 ..' ==> device: '.. myTable[myMonth+4])
fibaro:debug('Month: ' .. myMonth+5 ..' ==> device: '.. myTable[myMonth+5])
fibaro:debug('Month: ' .. myMonth+6 ..' ==> device: '.. myTable[myMonth+6])
fibaro:debug('Month: ' .. myMonth+7 ..' ==> device: '.. myTable[myMonth+7])
fibaro:debug('Month: ' .. myMonth+8 ..' ==> device: '.. myTable[myMonth+8])
fibaro:debug('Month: ' .. myMonth+9 ..' ==> device: '.. myTable[myMonth+9])
fibaro:debug('Month: ' .. myMonth+10 ..' ==> device: '.. myTable[myMonth+10])
fibaro:debug('Month: ' .. myMonth+11 ..' ==> device: '.. myTable[myMonth+11])

Re: LUA scene string

Posted: Sunday 20 December 2020 23:44
by waaren
bofisko wrote: Sunday 20 December 2020 18:54 I write this lua. I know that i possible to write better but it is my first work.
If someone to want to simplify I would like for it.
You could try this

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)
local a = {}

r,s,e = Daikin:GET("/aircon/get_year_power_ex") 
if e == 0 then  
	for v in r:gmatch('([^,]+)') do
	    table.insert(a, v)
	end

	local myTable = {}

	for str in a[4]:gmatch("(%d+)" ) do
		table.insert(myTable, str)
		fibaro:debug('Month: ' .. #myTable ..' ==> device: '.. myTable[#myTable])
	end

end

Re: LUA scene string

Posted: Monday 21 December 2020 10:51
by bofisko
Thank it is better and working.

Re: LUA scene string

Posted: Monday 21 December 2020 11:09
by bofisko
Thanks your script working perfect.
Can you help me for the last time?

after this script I would like take acurrent Month from the my system and debug power the current month.
and also I would like to calculated consumption for the whole year.
So I will be have total consumption and current month consumption
It poible lat time?
Thanks

Re: LUA scene string

Posted: Monday 21 December 2020 11:23
by waaren
bofisko wrote: Monday 21 December 2020 11:09 after this script I would like take acurrent Month from the my system and debug power the current month.
and also I would like to calculated consumption for the whole year.
So I will be have total consumption and current month consumption
It poible lat time?
Thanks
Cannot answer this yet because I don't have enough information.
Please describe in detail
  • is this a script within domoticz or on the os level?
  • where you get the data?
  • how is the data formatted?
  • where does it need to go?

Re: LUA scene string

Posted: Monday 21 December 2020 12:27
by bofisko
Hi,
I put your script which you send me and I very thanks for it. I would like to modificate. I wrote some on the end of your script but not working for actual Month. ( because I am stupid)
I want to take from your script created table, number of Month (#myTable) and compare from number of current Month from the system fibaro
( date = os.date("*t", os.time()) - fibaro date
thisMonth = date.month ) - fibaro actual number of Month

script:

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)
local a = {}

r,s,e = Daikin:GET("/aircon/get_year_power_ex") 
if e == 0 then  
	for v in r:gmatch('([^,]+)') do
	    table.insert(a, v)
	end

	local myTable = {}

	for str in a[4]:gmatch("(%d+)" ) do
		table.insert(myTable, str)
		fibaro:debug('Month: ' .. #myTable ..' - '.. myTable[#myTable])
	end

date = os.date("*t", os.time()) -- date from fibaro
thisMonth = date.month  -- month from fibaro --now 12
for myTable in str do 
  if  #myTable == thisMonth then
      fibaro:debug('Month: ' .. #myTable ..' - '.. myTable[#myTable])
 end  
end



I had wrote in my system this before putting yours upadate script  and it was working but I know that is not very good:

jan = myTable[myMonth]
feb=myTable[myMonth+1]
mar=myTable[myMonth+2]
apr=myTable[myMonth+3]
maj=myTable[myMonth+4]
jun=myTable[myMonth+5]
jul=myTable[myMonth+6]
aug=myTable[myMonth+7]
sep=myTable[myMonth+8]
okt=myTable[myMonth+9]
nov=myTable[myMonth+10]
dec=myTable[myMonth+11]

YEAR =  jan+feb+mar+apr+maj+jun+jul+aug+sep+okt+nov+dec

fibaro:debug(YEAR)

Re: LUA scene string

Posted: Monday 21 December 2020 13:16
by waaren
bofisko wrote: Monday 21 December 2020 12:27 I wrote some on the end of your script but not working for actual Month.
I am not sure I completely understand what you want but can you try this and share the result?

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 yearTotal = 0

	for str in a[4]:gmatch("(%d+)" ) do
		table.insert(myTable, str)
		fibaro:debug('Month: ' .. #myTable ..' - '.. myTable[#myTable])
		yearTotal = yearTotal + tonumber(str)
	end

	thisMonth = math.floor(os.date('%m'))
	fibaro:debug('Month: ' .. thisMonth ..' - '.. myTable[thisMonth])
	fibaro:debug('YearTotal: ' .. yearTotal)

	fibaro:debug('-- Now dumping table a')
	tprint(a)

	fibaro:debug('-- Now dumping table myTable')
	tprint(myTable)

end



Re: LUA scene string

Posted: Monday 21 December 2020 14:01
by bofisko
THANKS IT IS SUPER!!!

Re: LUA scene string

Posted: Monday 21 December 2020 14:20
by bofisko
waaren wrote: Monday 21 December 2020 13:16
bofisko wrote: Monday 21 December 2020 12:27 I wrote some on the end of your script but not working for actual Month.
I am not sure I completely understand what you want but can you try this and share the result?
Ewerithing is was working but there was only one little little problem in line 21 fibaro:debug(pre .. tostring(value) . There missing at the end of the symbol )
Now it i working Thank you very much for help me.

Re: LUA scene string

Posted: Monday 21 December 2020 20:42
by bofisko
It working but now I found that the data from strings a[4] are just cool data. data from strings a[2] are for heat. It possible to cool+heat (a[4] and a[2] together?

Re: LUA scene string

Posted: Monday 21 December 2020 21:03
by waaren
bofisko wrote: Monday 21 December 2020 20:42 It working but now I found that the data from strings a[4] are just cool data. data from strings a[2] are for heat. It possible to cool+heat (a[4] and a[2] together?
As asked before please share the output you see. That will make it easier to help.

Re: LUA scene string

Posted: Tuesday 22 December 2020 0:22
by bofisko
ok:
API my daikin: http://192.168.1.180/aircon/get_year_power_ex

string from API DAIKIN: ( number are consumption by months this year, prev year)

ret=OK,curr_year_heat=0/0/0/0/0/0/0/1/1/0/0/0,prev_year_heat=0/29/31/35/30/12/0/0/0/0/0/0,curr_year_cool=0/0/0/0/0/0/61/164/46/37/36/25,prev_year_cool=0/0/0/0/0/91/33/70/34/5/0/0

You givi me your script and I put in virtual device. But it is only for curr_year_cool. I would like to have consumption by month cool+heat and total consumption in my fibaro. Picture virtual device and VD in attachment. flb is file from fibaro export.

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 yearTotal = 0
	local i=1
	for str in a[4]:gmatch("(%d+)" ) do
		table.insert(myTable, str)
    	text ="ui.Label"..(i)..".value"
		fibaro:call(id, "setProperty", text, "".. myTable[#myTable]*0.1 .. " kWh")
    	i=i+1
    	yearTotal = yearTotal + tonumber(str)
	end
  fibaro:call(id, "setProperty", "ui.Label13.value",'' .. yearTotal*0.1 .. " kWh")
 
thisMonth = math.floor(os.date('%m'))
fibaro:call(id, "setProperty", "ui.Label14.value", "" .. myTable[thisMonth]*0.1 .. " kWh")
end

Re: LUA scene string

Posted: Tuesday 22 December 2020 1:13
by waaren
bofisko wrote: Tuesday 22 December 2020 0:22 ok:

You givi me your script and I put in virtual device. But it is only for curr_year_cool. I would like to have consumption by month cool+heat and total consumption in my fibaro. Picture virtual device and VD in attachment. flb is file from fibaro export.
This should get you going..

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 yearTotal = 0
	
	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

	local myHeatingTable, heatingTotal = sum(a[2])
	local myCoolingTable, coolingTotal = sum(a[4])

	fibaro:debug('-- Now dumping table a')
	tprint(a)

	fibaro:debug('-- Now dumping heating and cooling tables')
	tprint(myHeatingTable)
	tprint(myCoolingTable)

	thisMonth = math.floor(os.date('%m'))
	fibaro:debug('Month total : ' .. thisMonth ..' - '.. ( myHeatingTable[thisMonth] + myCoolingTable[thisMonth] ) )
	fibaro:debug('Year total: ' .. ( heatingTotal + coolingTotal ) )

end



Re: LUA scene string

Posted: Tuesday 22 December 2020 1:22
by bofisko
You are quickly. I will try it and send you result. Now I am going sleep because her is 2 o'clock in the morning. Thanks

Re: LUA scene string

Posted: Tuesday 22 December 2020 1:31
by bofisko
Sorry. but I think you probably didn't understand me. I would need this
January = cool january ( first number in string curr_year_cool) + heat january( first number in string curr_year_heat) and put in value in fibaro
February = cool february ( first number in string curr_year_cool) + heat february ( first number in string curr_year_heat)
.....

I need count 2 table together.

Thank or is there?

MP

Re: LUA scene string

Posted: Tuesday 22 December 2020 1:40
by waaren
bofisko wrote: Tuesday 22 December 2020 1:31 I need count 2 table together.
Thank or is there?
The totals are the sum of cooling and heating

Re: LUA scene string

Posted: Tuesday 22 December 2020 1:46
by bofisko
so How can I get sum january and putting to value1 ? and How can I get um february? and puting to value2 etc?
Please because i do not understanding.

Re: LUA scene string

Posted: Tuesday 22 December 2020 1:52
by bofisko
It is not working. I get tablecool and tableheat but no together table. For example August there is iny table heat 1 , in table coll 164. I need prin table together and I need August 1+164= 165. After that i need send 165 to "ui.label8.value" which representative august. Other september in heat is 1 , september in coll is 46 I need 1+46=47 and after send number 47 to "ui.label9.value" which representative august.

I need split myHeatingTable + myCoolingTable to one togethertable and after take from this togethertable send value of the month to value 1-12.
MP
How can I do it? I need this in want.jpg in attachment.
mp
thanks