In Python, how to execute ActionGroup with a delay?

Posted on
Sun Jul 17, 2016 12:14 am
thatdamncat offline
Posts: 11
Joined: Jul 03, 2016

In Python, how to execute ActionGroup with a delay?

In the UI when specifying an Action Group as the action for something, you can "Delay by" some time period. Is it possible to do the same thing in an embedded Python script? I see I can execute a specific Action Group, e.g. using
Code: Select all
indigo.actionGroup.execute(123)
but there is no obvious way to schedule the execution after some delay.

My use case is actually to be able to use a variable (containing the number of seconds) when delaying actions. The UI doesn't let me do this currently, so I deduced I should do this in script. But then I realized I couldn't execute delayed Action Groups.

Am I missing something? What's a suggested way to do this? For more context, I have a process of turning some lights off after an absence of motion. I want the amount of time to be configurable as a variable, because I expect I'll need to tweak it up/down at times.

Thanks!

Posted on
Sun Jul 17, 2016 7:16 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: In Python, how to execute ActionGroup with a delay?

In the case of a script, you just delay the script before executing the action:

Code: Select all
import time
time.sleep(NUMBEROFSECONDSHERE)
indigo.actionGroup.execute(123)


If you are delaying for more than 10 seconds, you'll want to make your script an external script (rather than embedded - typed into the text box on the Execute Script action). Embedded scripts have a maximum of 10 seconds to complete, but script files are started in their own process and can run as long as necessary.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jul 17, 2016 11:08 am
thatdamncat offline
Posts: 11
Joined: Jul 03, 2016

Re: In Python, how to execute ActionGroup with a delay?

Thanks Jay.

Any plans to allow the value of a variable for the "Delay by" time?

Posted on
Sun Jul 17, 2016 3:48 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: In Python, how to execute ActionGroup with a delay?

You can get the variable value in the script and use it in the delay:

Code: Select all
import time
delayVar = indigo.variables[IDOFVARIABLEHERE]
time.sleep(int(delayVar.value))
indigo.actionGroup.execute(123)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 11 guests