Page 1 of 1

Turn lights on/off with PIR activation order.

Posted: Monday 10 January 2022 14:43
by Phil C
Hi Guys,
Want to start getting into dzvents rather than blocky, first thing I would like to do is turn a light switch on or off depending on PIR activation order.

I have 2 pir’s, landing2 and landing3, what I would like to do is turn suite lights on if landing2 PIR triggered first then landing3, or if landing3 PIR triggered first then landing2 second turn suite lights off.

I really don’t have a clue, have read up on some dzvents on the domoticz website, back can’t see anyth8ng close to this.
Could anyone help me with the code please.

Thanks
Phil

Re: Turn lights on/off with PIR activation order.

Posted: Monday 10 January 2022 15:35
by madpatrick
There is a lot of information on the forum you can use. Just read the scripts and you will learn quickly
Here is a basic start to try
Adjust it to your setup

Code: Select all

local scriptVersion         = 'Versie 1.0 '
local scriptVar             = '-=# Script name #=-'


return {
	on = 	{
		devices = {300, 400}  --Replace number by the device you want to use as a trigger
		},
		
		        logging = { level = domoticz.LOG_INFO,
                marker      = scriptVar },
       	        
	execute = function(dz, device)
	    
        local lamp1 = dz.devices(100)   --Replace by device number
        local lamp1 = dz.devices(100)   --Replace by device number
        local PIR1 = dz.devices(300)    --Replace by device number
        local PIR2 = dz.devices(400)    --Replace by device number


       if PIR1.state == "On" then
        lamp1.switchOn().checkFirst()
        lamp2.switchOn().checkFirst().AfterSec(10)
                         dz.log('Lamps are ON', dz.LOG_FORCE)
    elseif  PIR2.state == "On" and lamp1.state=="On" then
        lamp1.switchOff()
    
  end
end
}