Help for a newbie in LUA !

Moderator: leecollings

Post Reply
sbisbilo
Posts: 11
Joined: Monday 07 March 2016 17:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Help for a newbie in LUA !

Post 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
Eduard
Posts: 139
Joined: Monday 19 January 2015 9:14
Target OS: -
Domoticz version:

Re: Help for a newbie in LUA !

Post by Eduard »

Search for dzVents in the forum. Easy to use LUA scripting!
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Help for a newbie in LUA !

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
sbisbilo
Posts: 11
Joined: Monday 07 March 2016 17:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Help for a newbie in LUA !

Post by sbisbilo »

Thanks Eduard and jvdz :)
Firstable I'll use your code jvdz and secondly I'm gonna study dzVents Eduard !!!
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests