Global variable trigger - not triggering

Post your questions and help other users.

Moderator: Martin

coconutxyz
Posts: 38
Joined: 16 Sep 2019 12:51

Re: Global variable trigger - not triggering

Post by coconutxyz » 26 Jan 2020 08:14

since it represents the current connection state, it is triggered multiple times per day

i guess single glovar for every state is the safest and simplest way

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

Re: Global variable trigger - not triggering

Post by Desmanto » 26 Jan 2020 08:58

Oh, you use the glovar trigger and still check the value. If that is the case, then current 10 glovar is the way to go. Maybe you can append some tag to the name, so you don't have to see/scroll glovar all the time. Such as global_z_homewifi, global_z_officewifi, etc. This way, all your glovar trigger will be at the end of the list.

Other way to really save the space is you must combine all the flows which use glovar trigger into single giant flow, separated by multiple parallel expression. This way, the glovar only trigger once, and then branch accordingly. You still need 2 glovar, 1 the triggerer, the other is the glovar map.
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.

User avatar
Rafi4
Posts: 281
Joined: 01 Dec 2017 05:23

Re: Global variable trigger - not triggering

Post by Rafi4 » 26 Jan 2020 23:59

Hi coconutxyz

use global variable in json format. You can use map, boolean, list or any . For example as below

Trigger = global_trigger
Action = get the value of the variable global_trigger (list,map or any)
Condition = enter the last value which was modified.

I think this is the most perfect solution for you.
If not please post.

if you don't understand, I can make a simple flow and share here.

From record4
No.1 Automation app in play store Automagic Premium
Samsung Galaxy j2 non rooted.
Android 5.1.1

coconutxyz
Posts: 38
Joined: 16 Sep 2019 12:51

Re: Global variable trigger - not triggering

Post by coconutxyz » 28 Jan 2020 11:39

Thanks rafi4,

i dont understand this part-->

Action = get the value of the variable global_trigger (list,map or any)
Condition = enter the last value which was modified.

User avatar
Rafi4
Posts: 281
Joined: 01 Dec 2017 05:23

Re: Global variable trigger - not triggering

Post by Rafi4 » 28 Jan 2020 12:46

Hi coconutxyz
Are you know about json? If yes you can add any type of values list,map or boolean . The variable converts into string. So every time when you add any values into the variable the trigger global_trigger will be executes the flow.

Trigger = global_trigger
Action = get the desired value
Condition = use the value in expression.

I hope I have explained in a better way.
If you still have doubts ? post.

From record4
No.1 Automation app in play store Automagic Premium
Samsung Galaxy j2 non rooted.
Android 5.1.1

coconutxyz
Posts: 38
Joined: 16 Sep 2019 12:51

Re: Global variable trigger - not triggering

Post by coconutxyz » 28 Jan 2020 13:02

Hi Rafi,

unfortunately i don't know about json but can the trigger global variable act upon changes in json file but not map/list?

User avatar
Rafi4
Posts: 281
Joined: 01 Dec 2017 05:23

Re: Global variable trigger - not triggering

Post by Rafi4 » 28 Jan 2020 13:39

Hi coconutxyz
Every value trigger the flow list ,map or any type of values the variable contains.

To use json
Action = script

For example
Js= fromJSON(global_trigger)
Add any thing here

Finally
global_trigger = toJSON(js);

Example script for understanding

create_list=fromJSON(getMapValue(global_json,"Count"));
set_values=newMapFromValues("Count time",triggertime,"Count text","{value} started at");
addElement(create_list,set_values);
global_json["Count"]=toJSON(create_list);

From record4
No.1 Automation app in play store Automagic Premium
Samsung Galaxy j2 non rooted.
Android 5.1.1

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

Re: Global variable trigger - not triggering

Post by Desmanto » 28 Jan 2020 18:54

@coconutxyz : Rafi4's method is the toJSON() method I mention in my previous post. If you convert the map into JSON before storing to glovar, the glovar now contain (JSON) string instead of map object. Hence it always get triggered, even you only change one of the key from the map.

To do this, you have to convert toJSON() before storing, and always use fromJSON() when retrieving value from the glovar. (as shown above by Rafi4). Only one glovar is needed. However, this still pose the same problem, which is all 10 flows will be triggered at the same time. To save the flow count, you have combine all of them into single flow.
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.

coconutxyz
Posts: 38
Joined: 16 Sep 2019 12:51

Re: Global variable trigger - not triggering

Post by coconutxyz » 29 Jan 2020 14:00

I have a rough idea but Rafi's script got me good lol, need some time to digest it

Post Reply