Page 1 of 1

Help with Time Condition

Posted: 20 Aug 2017 07:57
by dronics
Hi all,
Whats the best practice for checking a Time Condition?
I've got a multiple triggers in the same flow (display on, off and time 00:00), there is a condition check for screen on but the only thing I can find for time is "Time Range". So at the moment I'm checking the time range 00:00 to 00:01.
Is there a better way to do this?
I'm a little worried that android doze/sleep might cause the trigger to happen later than 00:00 and then the condition will be false.
Any help is much appreciated.
Cheers,
dronics

Re: Help with Time Condition

Posted: 20 Aug 2017 08:44
by bogdyro
Hi. What is the logic of your flow ? When should the FLOW trigger ? Is it absolutely necessary to run at exactly midnight ?
ON Screen On, SCreen Off and time 00:00 ?
If so, then there is no need to check for a condition.
If you enable option allow in device doze mode in trigger TIME then the flow will run on that time. Just make sure that you don't have another trigger running -15 or +15 minutes around that time as it could get delayed.

Re: Help with Time Condition

Posted: 20 Aug 2017 11:12
by Desmanto
Triggers in automagic always use OR logic. Only one of them get triggered, the flow is executed.

We have to understand the difference between "event" and "state". Event is something happen instantenously, just single moment. While state is condition that persist for a period time. You can match the wording to daily language, event as when; state as while. Combined with automagic logic, it will become
Trigger : Event = When
Condition : State = While
Action : Action = Do

So you need to rephrase your intention. When you want the flow to be executed, While under what condition? The one triggered less frequently usually is the trigger. While the one which can stay the same state for a period of time usually is the condition.

Example :
I have a flow, which speak out greeting exactly at 08:00 and if my phone is connected to office's wifi. It seems there are two triggers. Time AND Wifi connected.
Triggers : Time AND Wifi Connected
Action : Speech Output

But in fact it isn't. What I want is actually, When time shows 08:00, while my phone is connected to Office's wifi, then do action : speak out the greeting.
Triggers : Time
Condition : Wifi Connected
Action : Speech Output.

I have a better explanation at the other forum. But the explanation linked each other, very difficult to chopped out a bit and translated here. I have to translated it all at once to avoid confusion. (while I even haven't finish typing it yet).

Re: Help with Time Condition

Posted: 20 Aug 2017 15:17
by dronics
Thanks for the replies guys. I should have known that I need to put my flow down, lol!
My flow is used to see how much I use my phone, based on "screen on" time, the 1 flow is really 3 little flows.
My trigger has 3 items, Display on/Display off/Time is 00:00.
1, Display on --> condition screen on = true --> run script 1
2, Display off --> condition scrren on = false --> run script 2
3, Time is 00:00 --> condition Time range 00:00 to 00:01 --> reset global variables
because of the 3 triggers I think I have to have a condition to make sure that each trigger starts the right action.
If I don't have the time range condition, and cuz I do have the screen on condition will the 00:00 trigger reset the global variables anyway?

Re: Help with Time Condition

Posted: 20 Aug 2017 15:58
by Desmanto
If it is 3 flows, first you have to tested them out as real 3 flows. So each flow only have one trigger.

But yeah, it will be waste, since each flow is one trick pony, only do one thing. So why not join them. You can join display on/off and identify the trigger using condition screen on.
But for the time, it is quite different trigger, I suggest you just split it to another flow for better flow management. So you have 2 flow, 1 for trigger display on/off, another is time 00:00.

If you still want to join them, it is still possible. You can add the condition expression before the condition screen on, to check if the trigger is from time 00:00.

Code: Select all

matches(trigger, "Time:.*")
Since you have 3 trigger, but only one have the name "Time" inside, this will separate the time trigger. If the trigger is time 00:00 (true), it will directly continue to reset the GloVar. If not, which mean the trigger is either one of the display on or off, it will continue to check if the screen is on, and continue to corresponding branch.

Don't use Condition time range in this case. Because if you do, and you turn on/off your screen during that special minute (00:00 - 00:01), you will keep reseting your GloVar during that minute. That will make that 1 minute not counted to your statistic. OK, I am hyperbolic :) , but still that is logic flaw that can probably harm our other flows which need to be accurate down to minute or even second.

Re: Help with Time Condition

Posted: 20 Aug 2017 17:17
by dronics
Thanks Desmanto, the match expression is a great help. I knew there had to be a way to identify the time condition.
Like you say it's a waste of a flow to separate the Time 00:00 --> reset global variable.
I'm surprised there isn't an easy way to have a condition match the time trigger, I'm thinking if I wanted multiple time triggers in the same flow then I wouldn't easily know how to match each of them. I'm sure there are ways and I'm only about 3 days into having automagic.
Thanks for you help.

Re: Help with Time Condition

Posted: 21 Aug 2017 06:57
by Desmanto
Actually I don't know your exact name for the trigger, that's why I use matches(). It can be made stricter, by using the exact trigger name. If you use everyday and don't change the default name, then your expression will be

Code: Select all

trigger == "Time: everyday 00:00"
No need to use matches(), as the expression above is better and tighter check.

That's a nice idea, to have a new conditon (probably name as "Triggerer), which check what is the trigger. This condition can access the trigger name directly, so we can choose from available trigger or key in our own, such "Manual" (execution). The input box will be similiar to execute flow action, where we can choose multiple trigger name.

But feature will be added in priority. This function can be easily done using expression, so I don't think it will have first priority, unless it is easy to be implemented (there are a lot of other feature requests queuing already). Beside, the trigger name can actually vary not just only limited to that flow. You have 3 triggers, we think there will be 4 possible trigger name; 3 from flow's trigger, 1 is manual. However, if you use execute flow from other flow, the trigger name will based upon the caller flow. So trigger name can be any name of your other flow's trigger. Thus, it is better to stick with expression, as we have more flexibility dealing with the name later.

Next, as I have finished my parallel style explanation; I see the chance to make use of it, to increase the perfomance of the flow. You have 3 triggers now, and do 2 time checking already. As you can see at my thread, it is better to make it parallel when we have multiple choice with only one allowed.

Your trigger are Display State: On, Display State: Off, Time: everyday 00:00 . It is better now to make 3 parallel condition expression to check each of them, rather than using 2 nested if. So you have 3 expression connected directly to trigger.
Condition Expression 1 : trigger == "Display State: On"
Condition Expression 2 : trigger == "Display State: Off"
Condition Expression 3 : trigger == "Time: everyday 00:00"
All connected in parallel, and have its own action afterward, which is not related to any other branch. Even though you ended up adding additional condition, but when executing, the time needed for screen on/off branch will reduce by approx 100 ms. This will be my best practice for flows with multiple triggers, especially for 3 triggers above.

I have used tasker for 3 years before switching to automagic. The profile has the feature to add exit task. First time switching, single profile with entrance task + exit task in tasker, will require 2 separate flows in automagic. I also think it is a waste. So later I found out almost similiar method (not this trigger name) to combine them into single flow, just by adding a single condition. I know this after 1,5 months using automagic. But still there are a lot one or two tricks pony flow those I haven't combine yet (too lazy to fix anything that is working properly already :)).

But now, after keep adding new flow everyweek, I know I should really consolidate the flows now. There is a group of speech output based on time trigger that I have used for a very long time (in tasker), total 8 flows. At first I still thought about using multiple time range to check them, quite time consuming for matching the time range (that's why I am lazy :D). But thanks to your question :!: , I realize I can just simply parallel checking the trigger name and combine them easily into single giant flow with 8 branches. No more nested if needed. 8 flows now can be consolidated into 1 flow.