Delay between switches

Moderator: leecollings

Post Reply
Lorccan
Posts: 32
Joined: Wednesday 21 December 2016 10:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Delay between switches

Post 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?
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Delay between switches

Post 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
The most dangerous phrase in any language is:
"We always done this way"
Lorccan
Posts: 32
Joined: Wednesday 21 December 2016 10:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Delay between switches

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest