Can the rest of my piston still evaluate if a "while" loop is also running?


#1

I have a “presence” piston with a bunch of different statements depending on whether I arrive at home, leave, arrive at a different location, etc.

One of the statements compares 2 variables, Distance1 and Distance 2 and performs actions based off the difference.

I also have a “while” loop set up like this:

if variable “isMoving” is true
then
while variable “isMoving” is true
do
set variable “Distance1” to presenceDevice’s distanceMetric
wait 5 minutes
set variable “Distance2” to presenceDevice’s distanceMetric
wait 5 minutes
end while

My question is this:
When the “while” loop is running, will the other statements farther up in the piston continue to evaluate or will they wait until 1 run through the loop is done (10 minutes)? Would “async” somewhere help this?


#2

I cannot see any trigger triggers in your sample above, but basically, a loop stays in the loop until the requirements are met…

… BUT …

If another trigger fires off during the WAIT, then the piston starts all over at the top.
(potentially causing issues with your WAIT)


#3

Hmm, ok. My triggers weren’t shown but they are above the while loop. What’s the best way for me to have a while loop running and updating variables every 5 minutes, but still allow the rest of the if statements above to run?


#4

I keep active triggers (presence, motion & location) far far away from any loops!!

All three of those triggers fires off so frequently, that you can practically count on a loop being broken.


#5

I would need to see what you have to elaborate furthur…


#6

All of my variables are local not global, so I can’t have multiple pistons running. Any tips?


#7

Sorry, but I cannot help you with this in a public forum.
(you have well over 100 triggers here!!!)

  • Presence Sensor 6’s presence changing to “present”
  • Presence Sensor 6’s presence changing to “not present”
  • Presence Sensor 7’s presence changing to “present”
  • Presence Sensor 7’s presence changing to “not present”
  • Presence Sensor 8’s presence changing to “present”
  • Presence Sensor 8’s presence changing to “not present”
  • Presence Sensor 9’s presence changing to “present”
  • Presence Sensor 9’s presence changing to “not present”
  • Presence Sensor 11’s presence changing to “present”
  • Presence Sensor 11’s presence changing to “not present”
  • Presence Sensor 6’s speed changing to 1
  • Presence Sensor 6’s speed changing to 2
  • Presence Sensor 6’s speed changing to 3
  • Presence Sensor 6’s speed changing to 4
  • Presence Sensor 6’s speed changing to ANYTHING
  • Presence Sensor 6’s distanceMetric changing to 1
  • Presence Sensor 6’s distanceMetric changing to 2
  • Presence Sensor 6’s distanceMetric changing to 3
  • Presence Sensor 6’s distanceMetric changing to 4
  • Presence Sensor 6’s distanceMetric changing to ANYTHING
  • Motion Sensor 1’s motion changes to active
  • Motion Sensor 1’s motion changes to inactive

When any of the above happens, the piston will start all over at the top, and run top to bottom…
(executing anything not blocked by conditions)


Pro Tip:

For what it’s worth, there is absolutely no way that I would ever do this in a single piston…

If (for some reason) your mind is set on a single piston and no @globals, :man_facepalming: then I would delete ALL waits and loops, and pray that the piston finished executing every line of code in under a second. (to prepare for the next trigger that is coming in any moment)


To see the chaos I am referring to, try turning your logging level to Full and drive to the gas station. Your entire log will fill up, and start deleting itself off the bottom before you return home in ten minutes.


#8

If you are willing to use @globals, you can easily track a single device in a separate piston;

pic

(I am home now, so this is currently returning 0 for me)


#9

Alright! You made a convincing case. There were so many triggers because I’ve got a super redundant home/away setup, but I also want to leverage positonal info from the webCoRE Presence Sensor. I rebuilt it as multiple pistons (including one only for the “while” loop) with global variables tonight and I’ll see how it goes once I start moving around tomorrow.

Thanks for your help!


#10

I have a piston that (I think) does something similar to yours, but with Life360

It sends location data to globals, to be read off by another piston:


#11

Thanks for sharing that! Mine uses the OpenMaps API to take the latitude and longitude from the WebCore Presence sensor and returns an address, so I’m not just limited to specific destinations I’ve added in Life360 or Webcore.

Part of the challenge is finding the best way to identify once I’ve stopped. Tried a few different approaches, still figuring out which is the most consistent.


#12

I use Tasker (for Android) to do just this. Whenever my phone disconnects from my car’s Bluetooth, this means I have parked my car. At that point, Tasker automatically grabs my GPS coordinates, and sends the data to a few different places. (webCoRE being one of them)

This keeps my triggers in webCoRE nice and lean…
(IE: it only runs once each time my car is parked)

Tasker works brilliantly, and is (by far) the best $3 I’ve spent in the last decade!!


#13

Wish there was an iOS equivalent strategy!


#14

I feel your pain…

Truth be told, Tasker is likely the number one reason why my main devices will always be Android. That amazing tool can solve soooo many dilemmas…


#15

"Mine uses the OpenMaps API to take the latitude and longitude from the WebCore Presence sensor and returns an address, "

That sounds cool. Life360 shows coordinates as well as the current address.

As to movement, Life360 also shows MPH, MPS, and KPH. You might be able to implement that to trigger when you’ve stopped moving… Say, less than 5 MPH for more than 5 minutes.


#16

How do you access the coordinates, speed, etc? When I look into the IDE for my Life360 device I only have 1 thing listed under “current states” and it’s “presence”.


#17

I’m guessing you’re using the new app. This is what the classic app shows.


#18

Do you pay for a subscription? I don’t, and I only see 1 button, “arrived”.


#19

I do have a subscription, but even without the subscription, this information should still be available. Are you on the classic app?


#20

Yes, Classic App. The IDE shows the same info with the “Life360 User” Device Handler. What does yours show?