Staying at the same position -> action

Post your questions and help other users.

Moderator: Martin

Post Reply
nobody1407
Posts: 2
Joined: 31 Dec 2017 08:44

Staying at the same position -> action

Post by nobody1407 » 05 Jan 2018 06:31

Hi Folks!
I have a question about automagic flows. I would like to disable Bluetooth and enable WiFi, if I stay at the same location more than a few minutes.
If I leave the location, it should be enable Bluetooth and disable WiFi.

Is it possible to save the last location with radius x Meter and compare it with a new one?
The expression (location1 == location2) can't working, but this is for understanding.

Maybe it is better to see the flow:
photo_2018-01-05_07-23-24.jpg
photo_2018-01-05_07-23-24.jpg (66.11 KiB) Viewed 8940 times

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Staying at the same position -> action

Post by Desmanto » 05 Jan 2018 14:44

You are trying Geofencing but for static location. It is possible to compare location 1 to 2, by saving previous location to gloVar first, example {global_last_position}. Make sure you save it as the type location, it should be location type already if you assign directly from the trigger's variable {location}.

Then you can use expression

Code: Select all

location == global_last_position
somewhere before the end of the flow, add a new script to save current location to the glovar

Code: Select all

global_last_position = location;
If you understand the concept already, you can actually combine both of them into the same expression. (no need additional script at the end of the flow)

Code: Select all

test = location == global_last_position;
global_last_position = location;
test
We compare current location with previous one, save it in {test}. Then save current location to glovar. Finally check the result of the test. In expression, the last executed statement (even inside a if()) must always evaluated to true or false, thus the test should be the last.

But location is very sensitive, move a bit, and you probably have a different coordinate. So it is better to calculate the distance. You can calculate it using distance(). The result is in meters. The expression below check if the distance of current location vs previous location is more than 20 meters.

Code: Select all

dis = distance(location, global_last_position);
global_last_position = location;
dis > 20
I think this is not the best way to check for the static location. You have wifi AP nearby, just use wifi connected/disconnected as the trigger, or wifi available as the condition. Since you need timer, probably geofencing concept from the other thread can be used. viewtopic.php?f=6&t=7137
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

nobody1407
Posts: 2
Joined: 31 Dec 2017 08:44

Re: Staying at the same position -> action

Post by nobody1407 » 06 Jan 2018 21:57

Thanks for your answer and the correct way to control WiFi and Bluetooth, it works perfect! :)

Post Reply