Global variable trigger - not triggering

Post your questions and help other users.

Moderator: Martin

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

Global variable trigger - not triggering

Post by coconutxyz » 18 Jan 2020 11:01

Not sure if this is a well known bug, searched for it a bit and cant find anything.

i've created a flow A to change a variable global_homewifi to 1 or 0 depending if wifi is connected to home network or not. 1 = connected and 0 being the opposite. Then subsequently a new flow B with global variable trigger for global_homewifi that disable data and vibrate mode etc with expression if global_homewifi == 1 and enable data if false.

problem is flow A recognizes the wifi connection status and change the variable accordingly but flow B is not triggering at all..My understanding is that global variable will trigger when a different value is assigned....Any insight?

Micky Micky
Posts: 179
Joined: 16 Oct 2019 17:38

Re: Global variable trigger - not triggering

Post by Micky Micky » 19 Jan 2020 11:42

Check that you haven't got a space at the end of the variable in the trigger.

Hope this helps.
Crude but it works.

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

Re: Global variable trigger - not triggering

Post by coconutxyz » 19 Jan 2020 12:16

thanks but it is spaceless plus i directly select variable instead of typing, does it work for you?

edit: apparently {} is unnecessary, im idiot

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

Re: Global variable trigger - not triggering

Post by Desmanto » 19 Jan 2020 18:19

Glad you figure it out. Glovar trigger only working for non object variable. Which mean you can't use list/map variable type for this. If your glovar is a list/map, and you change any element inside it (adding, deleting, modifying element value), it won't trigger the changes. Because the value stored there seems to be a pointer, and the pointer only change when you point it to another list/map. (assign to other object)
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 » 20 Jan 2020 14:33

yea, a shame that list/map is not usable for global variable trigger. i really like that though

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

Re: Global variable trigger - not triggering

Post by Desmanto » 20 Jan 2020 17:44

You can actually still use glovar trigger. You just have to use another glovar as dummy triggerer. Everytime you modify your glovar list/map, you need to add additional script to modify the dummy glovar. Easiest way is just to +1 to that dummy glovar. Then at your flow that use dummy glovar trigger, act on that dummy glovar, then add script to retrieve the data from the glovar list/map. The dummy glovar can be any name, maybe global_dummy_trigger
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 » 22 Jan 2020 13:49

so say i got 10 items in a glovar map, i will have to create 10 dummy?

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

Re: Global variable trigger - not triggering

Post by Desmanto » 23 Jan 2020 17:53

That is one way to do it, but defeat the purpose. Depends on your need, you might have to create 10 dummy glovar along with 10 glovar map; or 10 dummy glovar with single glovar map.

There are several other way too. The best one is to still have 1 dummy glovar, used by 10 flow, and 1 glovar map. Then at the glovar map, create an identifier, let say "id". When changing the map value, set this global_map["id"] to the identifier you want to be triggered. You can't use flow name here, since a trigger can be used in multiple flow. You also don't use execute flows, since again, same idea; you have to change the execute flow action all the time if you reuse the trigger somewhere.

Example there is flow A to change the glovar map and then want it to be triggered by identifier X, which are used in flow B, C, D.

Code: Select all

global_map["var"] = "set to whatever value you change";
global_map["id"] = "X";
global_dummy = global_dummy + 1;
This prepare the "var" in the map. The "var" can be multiple keys, not just that. "id" refer to the identifier.

Once above code is executed, global_dummy has changed. It then triggered in flow B, C, D. All flow which contains the the global_dummy trigger, check using expression

Code: Select all

global_map["id"] == "X";
true, continue the flow., which mean all the flow B, C, D continue to the main branch. In flow D which has id of "Y", also triggered. But the expression checks for "Y" and get false, won't continue to main flow.

The downside is if you use the trigger global_dummy in 10 flows, all 10 flows triggered when it changed. But only the one with the correct identifier will continue to execute to main branch. I don't know if this might impact perfomance, since Martin ever suggest than we don't use the glovar this way too much.

I don't know if this is confusing or takes much more work. There are still other way, such as using toJSON() first before storing to glovar (this ensure always trigger). Or use Send Broadcast paired with General Broadcast, you can pass the map in the extra. Or use execute flow, but the flows name set to global map. I need to know what is the usage case to give best solution.
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 » 24 Jan 2020 08:22

ok this is indeed confusing lol, previously i had a glovar map/list with 10 items inside - homewifi, officewifi, plugged in,carbluetooth etc to indicate the current state for each item and they will change to 1 or 0 depending if they are connected or not. I will then use glovar trigger to check if 1 then do X action and vice versa.

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

Re: Global variable trigger - not triggering

Post by Desmanto » 25 Jan 2020 15:36

How many times do you use each trigger? I imagine this method is only useful if you use each trigger more than once. If only used once, instead of creating complicated script to prepare the status of the state; why don't just use execute flow. You still need at least single line script (or other action) to modify the glovar.

All other way to make it triggers based on single dummy glovar, require all flow to be triggered at once. So either you save glovar space and sacrifice runtime (10 flows triggered but only one continue), or use 10 glovar space but save runtime (only 1 flow triggered per glovar).

This is the consequence of saving some user created state and have to use it as trigger. I just check that I have only use glovar trigger twice, and both flows have be disabled for long time. I use several glovar datetime though, as it is useful to save battery life (compared to use long sleep time).
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.

Post Reply