how to run a script ONLY ONCE at start of indigo

User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

how to run a script ONLY ONCE at start of indigo

Post by kw123 »

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
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

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

Post by Colorado4Wheeler »

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
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

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

Post by jay (support) »

Jay (Indigo Support)
Twitter | Facebook | LinkedIn
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

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

Post by Colorado4Wheeler »

jay (support) wrote:Run it from an Indigo Server Startup trigger?
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
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

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

Post by jay (support) »

Colorado4Wheeler wrote:
jay (support) wrote:Run it from an Indigo Server Startup trigger?
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
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

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

Post by Colorado4Wheeler »

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
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

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

Post by jay (support) »

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
User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

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

Post by kw123 »

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?
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

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

Post by jay (support) »

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
User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

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

Post by kw123 »

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


Sent from my iPhone using Tapatalk
User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

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

Post by kw123 »

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



Sent from my iPhone using Tapatalk
User avatar
DaveL17
Posts: 7321
Joined: Tue Aug 20, 2013 11:02 am
Location: Chicago, IL, USA
Contact:

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

Post by DaveL17 »

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?
I came here to drink milk and kick ass....and I've just finished my milk.

My Plugins and Scripts
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

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

Post by jay (support) »

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
User avatar
DaveL17
Posts: 7321
Joined: Tue Aug 20, 2013 11:02 am
Location: Chicago, IL, USA
Contact:

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

Post by DaveL17 »

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


Sent from my iPhone using Tapatalk
I came here to drink milk and kick ass....and I've just finished my milk.

My Plugins and Scripts
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

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

Post by jay (support) »

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

Return to “Karl's Plugins and Scripts”