MacroDroid Variables Don't Update Until Subsequent Run

02ranger

New member
Hi! I'm new to MacroDroid and moving some of my Tasker macros to MD because it seems to run a lot of them more quickly and reliably. I have one workflow, 2 macros, that mark my GPS location when my phone disconnects from my car's bluetooth. I actually save the last three parking locations as well as the timestamp for each and then have a separate macro that I run to display a dialog of those times and open Google Maps to the selected location.

The problem I'm facing is that the variables don't seem to update, either in the Variables screen or when I open the List macro, unless I run the "Location" macro again. So if I parked my car at 10:00PM, 11:00PM, and 8:00AM the next day previously and now I'm parking at 9:00AM. After the Location macro runs, and I know it's running because I get a notification with the correct time (9:00AM), the dialog will show the times of 8:00AM, 11:00PM, and 10:00PM. It's not until the Location macro runs again that the dialog and the variables inside MD are updated to drop the 10:00PM time and show 9:00AM, 8:00AM, and 11:00PM. But by this time the location macro has run after 9:00AM so 9:00AM should be the second entry, not still the first.

Any ideas why the variables don't seem to update correctly until after a subsequent run of the Location macro?

I've included screenshots, but if I need to post more information please let me know. I couldn't get a full screenshot of the Location macro, but there are no constraints and that's the last action in the macro.

Screenshot_20231205_110208_MacroDroid.jpg

Screenshot_20231205_110215_MacroDroid.jpg
 

Qarboz

Well-known member
For complete screenshot use "Share as image" in the three dot menu in macro editing.

For your problem, you need to set the ParkingTime variable before set ParkTime[0] variable. Simply, you move the action up one line
 

02ranger

New member
For complete screenshot use "Share as image" in the three dot menu in macro editing.

For your problem, you need to set the ParkingTime variable before set ParkTime[0] variable. Simply, you move the action up one line
Well I feel dumb, now. That corrected it, though. Thank you!

I also noticed that it doesn't seem to update the GPS coordinates every time the macro is run. For instance, I marked my location at one place, drove to a location that's only 3 minutes away and the macro ran automatically there when I cut off the car but the coordinates were for the previous location. I then manually reran the macro at the new location after I'd been there a few minutes and got the new location. Should I be using something other than "Share Location" to get current coordinates?

Also, thanks for the tip on the image share.
 

Qarboz

Well-known member
Well I feel dumb, now. That corrected it, though. Thank you!

I also noticed that it doesn't seem to update the GPS coordinates every time the macro is run. For instance, I marked my location at one place, drove to a location that's only 3 minutes away and the macro ran automatically there when I cut off the car but the coordinates were for the previous location. I then manually reran the macro at the new location after I'd been there a few minutes and got the new location. Should I be using something other than "Share Location" to get current coordinates?

Also, thanks for the tip on the image share.
Before Share Location action, use Force Location Update action and Wait Before Next Action action (10...60 sec). The correct wait will have to be found experimentally
 

Dm114

Well-known member
Before Share Location action, use Force Location Update action and Wait Before Next Action action (10...60 sec). The correct wait will have to be found experimentally
According to @MacroDroidDev it should be maximum 30 seconds.
Unfortunately it still doesn't work unless an app using GPS is already running.

Can you succeed with the piece of macro attached (with GPS previously forced ON if not yet, of course)?

Do you know whether Force Location has to be repeated or not (i.e. inside or outside the loop)?
 

Attachments

  • 20231206_081241.jpg
    20231206_081241.jpg
    227.7 KB · Views: 14

02ranger

New member
Unfortunately it still doesn't work unless an app using GPS is already running.

Can you succeed with the piece of macro attached (with GPS previously forced ON if not yet, of course)?

Do you know whether Force Location has to be repeated or not (i.e. inside or outside the loop)?
In that macro snippet you posted, do you erase the LatLon variable somewhere prior? I'm not sure how it wouldn't immediately break out of the loop considering the last_loc_latlong would always be coordinates, I think, unless that variable does get cleared at some point.
 

Dm114

Well-known member
In that macro snippet you posted, do you erase the LatLon variable somewhere prior? I'm not sure how it wouldn't immediately break out of the loop considering the last_loc_latlong would always be coordinates, I think, unless that variable does get cleared at some point.
No, the working variable doesn't have to be cleared as Magic Text "last_loc_latlong" is supposed to be refreshed on every call (that's the case when another app using GPS is already running).

The issue is that the string returned is an error message (not matching the regex constraint).
 

02ranger

New member
No, the working variable doesn't have to be cleared as Magic Text "last_loc_latlong" is supposed to be refreshed on every call (that's the case when another app using GPS is already running).

The issue is that the string returned is an error message (not matching the regex constraint).
So that means if it did a GPS lookup 10 minutes ago for some other app the variable last_loc_latlong will not actually be the location found 10 minutes ago, it will be empty or some other string until the lookup initiated by MacroDroid is complete?
 

Dm114

Well-known member
So that means if it did a GPS lookup 10 minutes ago for some other app the variable last_loc_latlong will not actually be the location found 10 minutes ago, it will be empty or some other string until the lookup initiated by MacroDroid is complete?
You don't need to make any lookup, just have an app using GPS currently running to get current "last_loc_latlong" every time you use this Magic text. No need to use Force Location Update neither.
 
Last edited:

02ranger

New member
You don't need to make any lookup, just have an app using GPS currently running to get current "last_loc_latlong" every time you use this Magic text. No need to use Force Location Update neither.
Do you have any suggestions for a good way to do this in my current macro? I thought about having Google Maps open, wait 5 seconds or so, then save the location and close Maps, but I wasn't sure if it could all be done while the phone was locked and in my pocket without my intervention. I'm using a Samsung S23+ without root.
 

Dm114

Well-known member
Do you have any suggestions for a good way to do this in my current macro? I thought about having Google Maps open, wait 5 seconds or so, then save the location and close Maps, but I wasn't sure if it could all be done while the phone was locked and in my pocket without my intervention. I'm using a Samsung S23+ without root.
Unfortunately it still doesn't work unless an app using GPS is already running.

Can you succeed with the piece of macro attached (with GPS previously forced ON if not yet, of course)?

Do you know whether Force Location has to be repeated or not (i.e. inside or outside the loop)?
How would you trigger your macro if the phone is in your pocket? Anyway, honestly I don't know if it'll run with a locked device: just try it.

According to launching Google Maps (I use Waze) it's probably a good idea. Hint: you must not have to wait a number a seconds but wait untill Goggle Maps app is on the foreground.

For the rest, you can use the few lines attached to my previous post #5 (it's what I'm using and it works fine).
 

02ranger

New member
How would you trigger your macro if the phone is in your pocket? Anyway, honestly I don't know if it'll run with a locked device: just try it.

According to launching Google Maps (I use Waze) it's probably a good idea. Hint: you must not have to wait a number a seconds but wait untill Goggle Maps app is on the foreground.

For the rest, you can use the few lines attached to my previous post #5 (it's what I'm using and it works fine).
Sorry, you're right that I just need to try it. I just wasn't in a location where I could try it right then but I'll try later and report how it works.

With regards to the trigger, it triggers on BT Disconnect, specifically from my car's bluetooth radio, so it's always locked and in my pocket when it triggers.
 
Top