Mode Checking

I have an app where I set the mode based on certain conditions. It works ok, just puzzled about a couple things.

When I do presence control there is a routine called that checks if either my wife or I are home. It also checks if the mode is currently away. If those conditions are met it sets the mode to home. Again, works just fine.

But what happens if wife and I both arrive at same time the routine gets called twice. which it should. And this usually happens within a fraction of a second from each other. When the routine gets called the first time it sets the mode to home. When it gets called the second time it apparently still thinks the mode is away and sets the mode to home a second time. In other words the mode status hasn't updated yet.

I have verified that this is what is happening by some debug statements, looking at the events, etc.

To check the mode I use location.mode. Is there a way to force the check to update the status?

Again this really isn't hurting anything, except I get a notification when the mode changes and I usually get 2 notifications of the mode changing to home.

To clarify the notification, I subscribe to mode change. So it sees the mode change to home twice in a row with no other mode in between. So in theory the mode didn't change, but the subscription sees a change somehow. In the hub events it shows the mode changing to home twice in a row with nothing in between either.

This should not happen. We will look into it.

1 Like

If it helps. This only happens if the mode set routine is called twice very quickly. A few minutes ago we got home, but my presence and wife's presence were about 15 seconds apart. So I only got the 1 home set. Here is my routine that I use. For presence I set a virtual presence device for either of us based on several different presence indicators on our phones.

def AutoalarmP() {
if ((setPerson1.currentpresence == "present" || setPerson2.currentpresence == "present") && location.mode == "Away") {
location.setMode("Home")
// log.debug "present executed"
}

}