Multiple Simultaneous Executions of a SmartApp

Is it possible that there can be multiple simultaneous executions of a single SmartApp (or SmartDevice) ?
I am reading this:
http://docs.smartthings.com/en/latest/smartapp-developers-guide/state.html

And the example on atomicState seems to suggest that such a thing is possible. Could an ST engineer confirm this behavior or other developers who have observed it?

Could someone post some example code of how such a thing might happen?

It’s a pretty common set up, it’s just that you can’t guarantee which one will execute first.

For example, the new smart lighting smart app is designed to have multiple instances, one for each automation the person has set up.

So the automation that controls the guestroom lights on a time schedule might run at the same time as the automation that runs the entry lights when someone arrives home. Two different instances of the same app.

There’s also a limitation that anyone smart app can only schedule four future events. So someone might run multiple instances, each of which is handling four device schedules. That allows the back end to schedule more Efficiently, but it does mean multiple copies of the app running.

And some instances may be personalized to the user, like two different get up routines in the morning, and they are both running because both users are doing things that trigger them. So lots of reasons.

Again, though, there’s no way to enforce which runs first.

Let’s take a simple example.

Say I have an app that triggers on a presence sensor (I’m using this since in my experience they trigger randomly mostly!). Further assume that the app performs some heavy operation that will keep it running for a while before ending.

If the presence triggers twice within a short span of time (shorter than the time it takes for an app to complete running after triggering), will there be 2 instances of the smart app executing simultaneously?

Each individual instance is only allowed to run for 20 seconds. Presence is only detected every 30 seconds. So that particular one can’t happen.

It’s just going to depend on the exact situation, but they would have to be two distinct instances, so in most cases you’d either be trying to run multiple instances, or they wouldn’t happen.

2 Likes

So now I’m thinking that I could use schedule() to create two schedules, a few seconds apart. And I trigger the schedule creation based on presence. In this case, I guess I would have multiple instances of the same SmartApp running right?
With two quick schedules, I should not run into any rate limit problems too.

(This is just for testing and to understand the platform better).

I’ll leave that to the coding experts to answer. I don’t code my own stuff for SmartThings because groovy and text-to-speech really don’t go well together. :wink:

This will be a no go as well, as schedules more frequent that 60 sec typically get killed as well.

1 Like