LUA scene string Topic is solved

Moderator: leecollings

bofisko
Posts: 23
Joined: Sunday 22 November 2020 17:44
Target OS: Windows
Domoticz version:
Contact:

LUA scene string

Post 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
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: 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])
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 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])
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: 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
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 it is better and working.
bofisko
Posts: 23
Joined: Sunday 22 November 2020 17:44
Target OS: Windows
Domoticz version:
Contact:

Re: LUA scene string

Post 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
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: 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?
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 »

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)
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: 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


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 »

THANKS IT IS SUPER!!!
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: 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.
bofisko
Posts: 23
Joined: Sunday 22 November 2020 17:44
Target OS: Windows
Domoticz version:
Contact:

Re: LUA scene string

Post 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?
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: 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.
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 »

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
Attachments
KLIMA_only_cool.zip
(1.33 KiB) Downloaded 58 times
VD.png
VD.png (13.04 KiB) Viewed 1395 times
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 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


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 »

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
bofisko
Posts: 23
Joined: Sunday 22 November 2020 17:44
Target OS: Windows
Domoticz version:
Contact:

Re: LUA scene string

Post 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
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:31 I need count 2 table together.
Thank or is there?
The totals are the sum of cooling and heating
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 »

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.
bofisko
Posts: 23
Joined: Sunday 22 November 2020 17:44
Target OS: Windows
Domoticz version:
Contact:

Re: LUA scene string

Post 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
Attachments
now.jpg
now.jpg (59.26 KiB) Viewed 1369 times
want.jpg
want.jpg (35.09 KiB) Viewed 1369 times
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest