Page 1 of 1

Help for a newbie in LUA !

Posted: Friday 22 April 2016 12:15
by sbisbilo
Hi guys,

I just started my first LUA script and I love it !

But I've got 1 question (for the moment!) : I'd like to create a script with all my PIR devices and if one of them is active so a dummy switch will be active. But I've got a lot of PIR devices names PIR_kitchen, PIR_garage,... and I like to know if in a LUA script you can call a group like PIR instead of all individual PIR devices, hope I'm understandable ^^

For the moment I've got :

Code: Select all

commandArray = {}

if (devicechanged['PIR_kitchen'] == 'On' ) or (devicechanged['PIR_garage'] == 'On' ) then 
        commandArray['Capteurs']='On'
end
if (devicechanged['PIR_kitchen'] == 'Off' ) or (devicechanged['PIR_garage'] == 'Off' ) then
        commandArray['Capteurs']='Off'
end
return commandArray
Thanks a lot

Re: Help for a newbie in LUA !

Posted: Friday 22 April 2016 14:00
by Eduard
Search for dzVents in the forum. Easy to use LUA scripting!

Re: Help for a newbie in LUA !

Posted: Friday 22 April 2016 15:43
by jvdz
This is an example how to test for a devicename starting with "PIR":

Code: Select all

commandArray = {}

for chgdev, chgsts in pairs(devicechanged) do
	if string.sub(chgdev, 1, 3) == "PIR" then
		-- do what you want when any device starting with pir changed status
		print(" Device:".. chgdev.." changed to:"..chgsts)
	end
end

return commandArray
Jos

Re: Help for a newbie in LUA !

Posted: Monday 25 April 2016 8:49
by sbisbilo
Thanks Eduard and jvdz :)
Firstable I'll use your code jvdz and secondly I'm gonna study dzVents Eduard !!!