[LIB] Variable file

Moderator: leecollings

Post Reply
sploutchi
Posts: 9
Joined: Friday 11 July 2014 10:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

[LIB] Variable file

Post by sploutchi »

Hi all !

I am trying to make a variable file with all my device.

In this file, I try to make a function to print all of them... but I'm stuck on this part.

You will find after an excerpt from my file variable.lua :

Code: Select all

-- -----------------------------------------
-- ------- Variables ------------
-- -----------------------------------------
local V={};

-- -----------------------------------------
-- Switch ON/OFF
-- -----------------------------------------
V.prise_Cuisine = ''
V.prise_Chambre = ''
V.prise_Salon = ''

-- -----------------------------------------
-- Les volets
-- -----------------------------------------
V.les_volets = {};
V.les_volets[1] = {volet="Volets Salon", fenetre = "Fenêtre salon", temperature="salon", idx="192"}

-- -----------------------------------------
-- Les chauffages avec fil pilote
-- -----------------------------------------
V.les_chauffages = {};
V.les_chauffages[1] = {chauffage="Chauffage Chambre", piece = "Chambre"}
V.les_chauffages[2] = {chauffage="Chauffage Salon", piece = "Salon"}
V.les_chauffages[3] = {chauffage="Chauffage SDB", piece = "Salle de Bain"}

-- -----------------------------------------
-- Les volets
-- -----------------------------------------
function V.afficher_variables ()
	for a,b in pairs(V) do
		print ("==> a : '".. a .. "'");
		print ("type : "..type(b));
		if (type(b) == "table") then 
			for x,y in pairs(b) do
				print ("====> x : '".. x .. "'");
				print ("type : "..type(y));
				if (type(y) == "table") then 
					for c,d in pairs(b) do
						print ("=======> c : '".. c .. "'");
						print ("=======> d : '".. d .. "'");
					end
				elseif (type(y) == "string") then 
					print ("====> y : '".. y .. "'");
				end				
			end
		elseif (type(b) == "string") then 
			print ("==> b : '".. b .. "'");
		end
	end
	return true;
end

return V;

And that's what the function afficher_variables print :

Code: Select all

2016-07-12 12:02:06.771 LUA: ==> a : 'thermostat_chambre_amis'
2016-07-12 12:02:06.771 LUA: type : string
2016-07-12 12:02:06.772 LUA: ==> b : 'THCAMIS'
2016-07-12 12:02:06.772 LUA: ==> a : 'les_volets'
2016-07-12 12:02:06.772 LUA: type : table
2016-07-12 12:02:06.772 LUA: ====> x : '1'
2016-07-12 12:02:06.773 LUA: type : table
2016-07-12 12:02:06.773 LUA: =======> c : '1'
2016-07-12 12:02:06.774 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_TEST.lua: ./variables.lua:58: attempt to concatenate local 'd' (a table value)
Can you help me ?
georgesattali
Posts: 84
Joined: Saturday 05 March 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: [LIB] Variable file

Post by georgesattali »

Hello,
is your script incomplete ?
where does 'thermostat_chambre_amis' come from, I can't see it in the code ?
Maybe, if you write on Windows and then copy to Linux there's a problem. check that maybe, or at least, put the complete script on the forum.

Also, probably the line

Code: Select all

for c,d in pairs(b) do
may be wrong, do you mean

Code: Select all

for c,d in pairs(y) do
?

See U, GD
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests