Page 1 of 1

Delay between switches

Posted: Thursday 23 February 2017 12:39
by Lorccan
I am switching on 2 switches via a LUA script. Optimally, I would like to have a delay of ~6 seconds between them.

I could do this via a Scene with an On Delay for the second switch, but I only need the delay if Switch 1 was initially OFF and then switched to ON by th script. (I can check the status of Switch 1 with the script, so I can determine whether I need to switch it.)

I know that it's not advisable to put a delay in a device script, but I don't think the 6 seconds is going to cause any problems with my setup.

Can anyone suggest please a way to do what I want, or should I just go with the Scene and an extra delay each time?

Re: Delay between switches

Posted: Thursday 23 February 2017 12:46
by emme
does this could help?

EVENT DEVICE

Code: Select all

local switch1 = 'Put here the name of your first switch'
local switch2 = 'Put here the name of your second (delayed) switch'
local onDelay = 6 -- set the seconds you want to delay

if devicechanged[switch1] and otherdevices[switch1] == 'On'
    commandArray[switch2] = 'On AFTER '..onDelay
end
in this way you can switch switch1 manually and the other light will delay 6 secs...

if you want to do it IN the script, it would be not necessary a device event... it could be whatever you want

Code: Select all

local switch1 = 'Put here the name of your first switch'
local switch2 = 'Put here the name of your second (delayed) switch'
local onDelay = 6 -- set the seconds you want to delay

if otherdevices[switch1] == 'Off'
    commandArray[switch1] = 'On'
    commandArray[switch2] = 'On AFTER '..onDelay
end

Re: Delay between switches

Posted: Thursday 23 February 2017 13:54
by Lorccan
Thanks for the fast reply. I forgot to mention that Switch 2 is relying on an os.execute call as it's talking directly to an amplifier, but I can get around that by creating a dummy switch as you suggest and call the os.execute when it is triggered.