Execute actionGroup with delay

Posted on
Mon Dec 07, 2020 3:13 am
pauerbuk offline
Posts: 17
Joined: Jan 29, 2013

Execute actionGroup with delay

Hi, i'm very new to pyton, sorry:
Wanting to upgrade to version 7.4, i am trying to convert all Applescripts to pythons.
In Applescript it was possible to execute a delayed ActionGroup; in pyton, this command:
Code: Select all
indigo.actionGroup.execute(343928657, delay=6300)

returns: "Pyton argument types in".
Why? how can I do?
Thanks in advance.

Mac mini 2,4 Ghz Intel Core 2 Duo - El Captain 10.11.1

Posted on
Mon Dec 07, 2020 5:37 am
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Execute actionGroup with delay

As far as I know, this is still the recommended method to script an action group delay:

Code: Select all
import time
time.sleep(NUMBEROFSECONDSHERE)
indigo.actionGroup.execute(123)
https://forums.indigodomo.com/viewtopic.php?f=107&t=16487#p119910

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Dec 07, 2020 8:33 am
pauerbuk offline
Posts: 17
Joined: Jan 29, 2013

Re: Execute actionGroup with delay

It is a crazy thing :oops: :oops: :oops:
thanks anyway! This delay the script?

Mac mini 2,4 Ghz Intel Core 2 Duo - El Captain 10.11.1

Posted on
Mon Dec 07, 2020 9:07 am
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Execute actionGroup with delay

When executed, the script will pause for 'NUMBEROFSECONDSHERE' seconds before continuing.

Code: Select all
import time


# do first stuff

indigo.activePlugin.sleep(60)
indigo.actionGroup.execute(123)

# do second stuff
When executed, the 'first stuff' will happen right away. Then the script will pause for 60 seconds (during which nothing will happen), and then the script will execute the action group and continue on with the 'second stuff'.
Last edited by DaveL17 on Mon Dec 07, 2020 10:18 am, edited 1 time in total.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Dec 07, 2020 10:14 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Execute actionGroup with delay

Note that you don't want to do that in an embedded script since those have to execute/complete in 10 seconds.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Dec 08, 2020 3:35 am
pauerbuk offline
Posts: 17
Joined: Jan 29, 2013

Re: Execute actionGroup with delay

I think I'll keep forever version 7.3 with Applescript that works so well ...

Mac mini 2,4 Ghz Intel Core 2 Duo - El Captain 10.11.1

Posted on
Tue Dec 08, 2020 3:50 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Execute actionGroup with delay

I was thinking about this as a diversion from working on something else and I think the easiest way to send a (non-blocking) delayed actiongroup.execute() command is to run it in its own thread. I tested this approach with a 5 second delay and it works well. Presumably it will work just as well with your 6300 second delay, but I didn't test that. :D

Code: Select all
import threading
import time

def actionGroupDelay(action_id, seconds):
    indigo.activePlugin.sleep(seconds)
    indigo.actionGroup.execute(action_id)

indigo.server.log(u"Do some stuff")

# =========================  Execute Delayed Action  ==========================
t = threading.Thread(target=actionGroupDelay, args=[1450401770, 5])  # Replace with your action id, time in seconds
t.start()
# =============================================================================

indigo.server.log(u"Do some more stuff")
When I run this code, "Do some more stuff" appears in the log instantly, and the action group is executed after 5 seconds. There are other ways to do this, but I think this is probably the most straightforward.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Wed Dec 09, 2020 11:38 am
pauerbuk offline
Posts: 17
Joined: Jan 29, 2013

Re: Execute actionGroup with delay

Thank you very much Dave! I will try as soon as possible, and I'll let you know the result.

Mac mini 2,4 Ghz Intel Core 2 Duo - El Captain 10.11.1

Posted on
Wed Dec 09, 2020 11:58 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Execute actionGroup with delay

The easier solution, IMO, is to just use the script he posted first as an external script if for no other reason that it's more straight-forward.

The threading option is interesting - just not sure what side effects it might have when used as an embedded script on other scripts scheduled by Indigo. It might work fine but we've never really tested it.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Dec 09, 2020 7:06 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Execute actionGroup with delay

jay (support) wrote:
The threading option is interesting - just not sure what side effects it might have when used as an embedded script on other scripts scheduled by Indigo. It might work fine but we've never really tested it.

I did some tests with Jon (Autolog) where we both ran the threaded version from within an embedded script (I went as high as 60 seconds on the delay) and both Indigo and the delayed execute never missed a beat. That said, YMMV and I would strongly encourage you to take Jay's advice and run the code in a linked script.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Thu Dec 10, 2020 3:54 am
pauerbuk offline
Posts: 17
Joined: Jan 29, 2013

Re: Execute actionGroup with delay

Hi Dave, you are great!
I tried your code with a 60 second delay, (in an embedded script ): the script doesn't time out and executes correctly.
The server is responsive, so you maybe gave me the solution.
However I also tried assigning a variable in Indigo from the calling script, and then using it in the external script with delay, but if this method works it's better !!!
Thank you again - bye

Mac mini 2,4 Ghz Intel Core 2 Duo - El Captain 10.11.1

Posted on
Thu Dec 10, 2020 5:58 am
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Execute actionGroup with delay

Glad we were able to find something that works for you. I would still encourage you to save the script to disk and run it as a linked script as there's not really anything but upside to doing it that way. I run all of my scripts from files and it works great. You can keep all of your scripts in one place, and use a plain text editor to read and write them.

Good luck!

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Thu Dec 10, 2020 10:40 am
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Execute actionGroup with delay

I took the liberty of making a small tweak to Dave's post by changing the time.sleep() call to instead be indigo.activePlugin.sleep(). The advantage of the latter (which can also just be called via self.sleep() from plugins) is that the Indigo Server can more politely (not force kill) the python process using Indigo's special version of the sleep method. For delays of just a second or two it that doesn't really matter, but if one is doing longer delays the modified sleep() will listen for the process stop messages coming from the Indigo Server whereas time.sleep() just blocks.

Image

Posted on
Thu Dec 10, 2020 11:05 am
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Execute actionGroup with delay

That doesn't seem fair. I don't get the chance to change any of your posts. :D

I'm crafting a simple shim for this and will change the sleep call there as well.

(Thanks Matt!)

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 9 guests