Skip to content

Examples to use LUA script for switch

Smanar edited this page Mar 2, 2019 · 13 revisions

You have two way to make LUA scripts.

  • make a file called "script_device__That_You_Want_.lua
  • go to "Setting" / "More options" / "Event" / "LUA"

-- Some LUA exemples

time = os.date("*t")

commandArray = {}

-- Motion detector if (devicechanged['deCONZ - Motion Sensor'] == 'On') then print("Motion detector detection")

if (otherdevices['working day']== 'On') then
	commandArray['Scene:Morning light']='On'
else
	if ((time.hour >= 23) or (time.hour < 7)) then
		commandArray['Scene:night light']='On'
	else
		commandArray['Scene:normal light']='On'
	end
	if ((time.hour >= 12) and (time.hour < 20)) then
		commandArray['Scene:Light 2']='On'
	end
end

end

-- Door openend if (devicechanged["deCONZ - entry door"] == 'Open') then print("Dooor open") commandArray['Scene:Lumiere Entree']='On' end

-- Switch 1 if (devicechanged['deCONZ - Switch 1']) then print("Switch 1") local b = devicechanged['deCONZ - Switch 1'] if b == 'B1' then if (otherdevices['deCONZ - Coridor']== 'On') then commandArray['deCONZ - Cordidor'] = 'Off' else commandArray['Scene:Light Cordidor'] = 'On' end end end

end

return commandArray

I m using scene, because you can easily set light value, color or temporisation.