how to run a script ONLY ONCE at start of indigo

Posted on
Wed Apr 25, 2018 11:17 am
kw123 online
User avatar
Posts: 5393
Joined: May 12, 2013
Location: Dallas, TX

how to run a script ONLY ONCE at start of indigo

Has someone figured out how to run eg a script (or action ...) only ONCE at startup?

setting a variable to "started" does not work as you need to reset it when indigo shuts down .. and there is no mechanism for that either ..

anyway looking for suggestions.


Karl

Posted on
Wed Apr 25, 2018 11:28 am
Colorado4Wheeler offline
User avatar
Posts: 2351
Joined: Jul 20, 2009
Location: Colorado

Re: how to run a script ONLY ONCE at start of indigo

Why not write a file to the filesystem?

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Wed Apr 25, 2018 11:38 am
jay (support) offline
Site Admin
User avatar
Posts: 14068
Joined: Mar 19, 2008
Location: Austin, Texas

Re: how to run a script ONLY ONCE at start of indigo


Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Apr 25, 2018 2:20 pm
Colorado4Wheeler offline
User avatar
Posts: 2351
Joined: Jul 20, 2009
Location: Colorado

Re: how to run a script ONLY ONCE at start of indigo

jay (support) wrote:

Wow, I didn't even know that was a thing. I love learning new tricks.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Wed Apr 25, 2018 3:01 pm
jay (support) offline
Site Admin
User avatar
Posts: 14068
Joined: Mar 19, 2008
Location: Austin, Texas

Re: how to run a script ONLY ONCE at start of indigo

Colorado4Wheeler wrote:
jay (support) wrote:

Wow, I didn't even know that was a thing. I love learning new tricks.


LOL - been in there since Indigo 2 I believe.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Apr 25, 2018 3:25 pm
Colorado4Wheeler offline
User avatar
Posts: 2351
Joined: Jul 20, 2009
Location: Colorado

Re: how to run a script ONLY ONCE at start of indigo

While I would like to know every last possible thing that I can code into Indigo, I'm not you :shock: :lol:. Besides, that's a pretty obscure little technique that I bet hasn't been used by many and glazed over by most when reading the docs :roll: :wink: .

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Wed Apr 25, 2018 3:41 pm
jay (support) offline
Site Admin
User avatar
Posts: 14068
Joined: Mar 19, 2008
Location: Austin, Texas

Re: how to run a script ONLY ONCE at start of indigo

Colorado4Wheeler wrote:
While I would like to know every last possible thing that I can code into Indigo, I'm not you :shock: :lol:. Besides, that's a pretty obscure little technique that I bet hasn't been used by many and glazed over by most when reading the docs :roll: :wink: .


Actually, it's probably the best way to start up stay-open scripts (things that query data sources, populate variables, etc.) that should pretty much always be running while the server is running. We recommended it for background scripts like the old iTunes Sync script for example.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Apr 25, 2018 4:43 pm
kw123 online
User avatar
Posts: 5393
Joined: May 12, 2013
Location: Dallas, TX

Re: how to run a script ONLY ONCE at start of indigo

thats great !!

Now how about when indigo shuts down ..

how about a basic plugin that runs, does nothing, Only when indigo shuts it down it does an action when
Code: Select all
try:
  while True:
       time.sleep(10)
except: pass

###do the action here


would that work?

Posted on
Wed Apr 25, 2018 5:10 pm
jay (support) offline
Site Admin
User avatar
Posts: 14068
Joined: Mar 19, 2008
Location: Austin, Texas

Re: how to run a script ONLY ONCE at start of indigo

Or implement the shutdown() method:

Code: Select all
def shutdown(self):
     # do any cleanup necessary before exiting


It would just have to do whatever it wanted to do quickly since I think we only wait for a plugin to shut down gracefully for 10 seconds.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Apr 25, 2018 5:14 pm
kw123 online
User avatar
Posts: 5393
Joined: May 12, 2013
Location: Dallas, TX

Re: how to run a script ONLY ONCE at start of indigo

Can shutdown() still call/ execute an indigo action ?


Sent from my iPhone using Tapatalk

Posted on
Wed Apr 25, 2018 10:09 pm
kw123 online
User avatar
Posts: 5393
Joined: May 12, 2013
Location: Dallas, TX

Re: how to run a script ONLY ONCE at start of indigo

Yes it can and it works fine.
Have written a plugin if anyone is interested



Sent from my iPhone using Tapatalk

Posted on
Thu Apr 26, 2018 5:42 am
DaveL17 offline
User avatar
Posts: 3839
Joined: Aug 20, 2013

Re: how to run a script ONLY ONCE at start of indigo

I never thought about using shutdown() with a server shutdown, but that makes sense. Do running plugins always shut down in alphabetical order? If that's the case, would "zzzPlugin" be "guaranteed" last to go?

Posted on
Thu Apr 26, 2018 8:50 am
jay (support) offline
Site Admin
User avatar
Posts: 14068
Joined: Mar 19, 2008
Location: Austin, Texas

Re: how to run a script ONLY ONCE at start of indigo

DaveL17 wrote:
I never thought about using shutdown() with a server shutdown, but that makes sense. Do running plugins always shut down in alphabetical order? If that's the case, would "zzzPlugin" be "guaranteed" last to go?


First, remember that shutdown() will also be called if the plugin is disabled or restarted - so you're not guaranteed that the server is also shutting down.

There is no explicit order of plugin shutdowns (that is, there is an order, but we don't publish it because it probably will change periodically as we do more backend server work so you shouldn't assume there is).

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Apr 26, 2018 8:54 am
DaveL17 offline
User avatar
Posts: 3839
Joined: Aug 20, 2013

Re: how to run a script ONLY ONCE at start of indigo

Thanks Jay. Then the trigger seems like the best bet to key on a server shutdown.


Sent from my iPhone using Tapatalk

Posted on
Thu Apr 26, 2018 9:04 am
jay (support) offline
Site Admin
User avatar
Posts: 14068
Joined: Mar 19, 2008
Location: Austin, Texas

Re: how to run a script ONLY ONCE at start of indigo

Unfortunately, at the moment there isn't a Server Shutdown trigger that corresponds to the Server Startup trigger. It's been on the list for many years, but just doesn't seem to have a very high demand.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Who is online

Users browsing this forum: No registered users and 0 guests