Page 1 of 1

How to convert "execute group [in integer]"

PostPosted: Sat Aug 22, 2020 8:53 am
by macpro
I'm converting a script that executes an action group with a delay:

Code: Select all
repeat with i from 1 to 45
   execute group "Slaapkamer Wekker - Snooze" in (40 * i)
end repeat


The python documentation has no option to specify a delay.
How should I convert this?

Re: How to convert "execute group [in integer]"

PostPosted: Mon Aug 24, 2020 9:38 am
by jay (support)
Code: Select all
# This will run the script with i going from 1 to 45:
for i in range(1, 46):
    # sleep for the number of seconds
    self.sleep(40 * i)
    # execute the action group
    indigo.actionGroup.execute(ID_OF_ACTION_GROUP)


Note you'll want to run this as an external script since it's a long-running script.

Re: How to convert "execute group [in integer]"

PostPosted: Mon Aug 24, 2020 10:07 am
by macpro
Thanks.

I had to add
Code: Select all
import time
because self. sleep wasn't recognised.
And the multiplier had to go.
Code: Select all
time.sleep(40)

Re: How to convert "execute group [in integer]"

PostPosted: Mon Aug 24, 2020 1:23 pm
by matt (support)
Instead try using:

indigo.activePlugin.sleep(40)

which will be more friendly if the Indigo Server is trying to restart and wants to shutdown the script.

Re: How to convert "execute group [in integer]"

PostPosted: Mon Aug 24, 2020 1:34 pm
by macpro
That works also.

I use time.sleep also in other Python scripts. Should I replace them everywhere with indigo.activePlugin.sleep?

Re: How to convert "execute group [in integer]"

PostPosted: Mon Aug 24, 2020 2:02 pm
by jay (support)
Sorry, self.sleep is for plugins... :oops:

Yes, any scripts that are run from Indigo should use indigo.activePlugin.sleep() in case the server needs to restart while a script is sleeping.