use variables in triggers - is it possible?

Post your questions and help other users.

Moderator: Martin

Post Reply
ZSasha
Posts: 103
Joined: 11 Oct 2013 03:48

use variables in triggers - is it possible?

Post by ZSasha » 05 Jan 2014 00:54

Is it possible to use a variable in trigger's configuration?

Let's say in "Timer" trigger - right now it should be defined manually. Is it possible to put a variable there and then change the variable at some other place/flow to adjust the trigger? Currently it says "incorrect value".

The same is for "location" trigger for example - I want to be able to dynamically define a location when "location" trigger can start a flow.
Currently it does not seem to be possible - if I put a variable instead of real coordinates, the system converts it to 0.0;0.0 straight away.

Or may it be considered as a feature request?

Thanks.

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: use variables in triggers - is it possible?

Post by MURTUMA » 05 Jan 2014 10:30

You can use the trigger "variable" and define those variables on other flows.

Take a look on this example on time variables: http://automagic4android.com/flow.php?i ... 6f42ed2b58

ZSasha
Posts: 103
Joined: 11 Oct 2013 03:48

Re: use variables in triggers - is it possible?

Post by ZSasha » 05 Jan 2014 10:58

em... looks like you did not get me...
I want to be able to use a global_variable in a trigger's configuration, not as a trigger itself.

Let's say I have two flows - flow1 asks a user something like "how often you want to be notified ...?" and when the user put X minutes - then the second flow2 is being called by each X minutes.
And the second flow uses "Timer" trigger to start itself each X minutes with global_variable as a parameter that had been defined in flow 1 instead of being hardcoded into a trigger as it is now.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: use variables in triggers - is it possible?

Post by Martin » 06 Jan 2014 17:48

Most triggers don't allow variables since the triggers would need to be re-registered in the system when the variable is modified which does not work well for some triggers.
There's a special trigger Global Variable Date/Time that executes a flow when the time stored in the variable is reached. You can use this trigger to build a flow that's executed periodically in a user defined interval by setting the global variable to the next point in time with a script.

ZSasha
Posts: 103
Joined: 11 Oct 2013 03:48

Re: use variables in triggers - is it possible?

Post by ZSasha » 06 Jan 2014 20:57

Thank you for the Explanation, Martin.

Timer was just an example. Actually I faced this challenge when I was trying to create a flow for GPS positioning.
My wife is often get lost in "urban jungles" so I decided to create a flow for her to notify her when she reaches some place.

I just wanted to make it as user-friendly for her as possible which means NOT to make her change triggers, settings or anything so I thought it would be me who would send coordinates to her phone remotely.
I was going to use "Location" trigger with "interesting" coordinates being setup/changed dynamically.

However if this is not possible - I could probably use different approach to achieve this goal?
But waking up the phone each 10 seconds (because a bus could pass a great distance in one minute) in order to obtain the current coordinates and then perform some computations to calculate a distance between the current coordinates and the destination - well, it does not seem to be a really great solution.
Am I probably missing something?


As you said that a trigger needs to be registered and that's why they need to have a "static" config - isn't it possible to temporarily de-register a trigger, change its settings and re-register it back in the system?
Probably not now but may be it is something that could be considered for future releases?

Regards.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: use variables in triggers - is it possible?

Post by Martin » 07 Jan 2014 17:39

Theoretically it would be possible to do this for the location trigger but I'm not sure if this would match the expectation of the users in all cases.
The location methods offered by Android usually execute the 'entering' trigger when a location trigger is registered and the current location is within the defined area. So when you send the same location or nearly the same location to the device it would execute the flow again.

Maybe it would be possible to do something like this by creating a generic flow that imports the location flow and enables the flow:
-trigger 'SMS Received: All containing IMPORT FLOW!'
-action 'Dropbox Download Files: /flow.xml to /sdcard/flow.xml'
-action 'Import Flows/Widget: /sdcard/flow.xml'
-action 'Set Flow State: Enable {imported_flow_names,listformat,comma}'

I've never tested this but it should allow to execute almost anything on the remote phone.

Regards,
Martin

Post Reply