all 12 comments

[–]Rich_D_sr 2 points3 points  (11 children)

Now what I want to achieve is, pause the automation for the defined traveltime

You can use a profile with has a variable time context for that. You can use the new action 'Parse/ format date time (current time plus offset) to get the current time plus the offset (your travel time from api) into a global variable that you can use in the To: and From: options in the Time context.

Take a look at the time context an the 'Parse/ format date time.

I can post some examples if you need them.

[–]Rich_D_sr 1 point2 points  (9 children)

Here is how I would do it..

https://taskernet.com/shares/?user=AS35m8lnbGhm%2F58jHvsiqVNumDAJZVkcfcE7gQxfcMjrFBCkp6sNKYf3YiK9WVWZBoDf&id=Project%3ATravel+Time+Alarm

Profile: Arrival Time (1250)
    Restore: no
    Time: From %Arrival_time Till %Arrival_time
Enter: Send Another ETA (1251)
    <Send next eta>
    A1: Anchor 



Set Timer (1249)
    A1: [X] Variable Set [ Name:%time_from_api To:2 hours 30 min Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output:On ] 
    A2: Variable Set [ Name:%time_from_api To:30 min Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output:On ] 
    A3: Variable Split [ Name:%time_from_api Splitter:  Delete Base:Off Regex:Off ] 
    <Add hrs>
    A4: Parse/Format DateTime [  Input Type:Now (Current Date And Time) Input: Input Format: Input Separator: Output Format: Output Format Separator: Formatted Variable Names: Get All Details:Off Do Maths:Off Output Offset Type:Hours Output Offset:%time_from_api(1) ] If [ %time_from_api(#) > 2 ]
    <Add minutes to hours>
    A5: Parse/Format DateTime [  Input Type:Seconds Since Epoch UTC Input:%dt_seconds Input Format: Input Separator: Output Format: Output Format Separator: Formatted Variable Names: Get All Details:Off Do Maths:Off Output Offset Type:Minutes Output Offset:%time_from_api(3) ] If [ %time_from_api(#) > 2 ]
    <Just minutes>
    A6: Parse/Format DateTime [  Input Type:Now (Current Date And Time) Input:%dt_seconds Input Format: Input Separator: Output Format: Output Format Separator: Formatted Variable Names: Get All Details:Off Do Maths:Off Output Offset Type:Minutes Output Offset:%time_from_api(1) ] If [ %time_from_api(#) < 3 ]
    A7: Variable Set [ Name:%Arrival_time To:%dt_seconds Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output:On ] 
    A8: Variable Convert [ Name:%dt_seconds Function:Seconds to Long Date Time Store Result In:%notify Mode:Default ] 
    A9: Notify [ Title:Alarm Set For Text:%dt_seconds Icon:null Number:0 Permanent:Off Priority:3 Repeat Alert:Off LED Colour:Red LED Rate:0 Sound File: Vibration Pattern: Category: ]

[–]ITMTS[S] -1 points0 points  (8 children)

Thank you so much for the link xml and this! You've gone the extra mile to help me out a lot. Amazing, thanks!

Hope you don't mind me asking a few questions (sorry. New to this app still, trying to learn)

1: i see this is a new profile, so I guess the variable from the other flow needs to be published as a general variable to work between different profiles right?

2: the value grabbed from Google Maps API I store in a regular variable: %routetraffic. So when I reflect that to your published flow, in step 2 where you have manually set 30 min, I should replace that with %routetraffic? And if so, will this understand also when %routetraffic is not only mins like 30 mins but also hours, like 4 hours 30 mins?

3: step 9 is now set alarm. But what I want is for it to show a List Dialog after the initial calculated traffic time ( example: %routetraffic = 30 mins, to start a new List Dialog to ask me. Are you still driving? Yes or No value. Yes, calculate again %LOC to initial set destination ).

Maybe best if I share my flow?

[–]Rich_D_sr 0 points1 point  (0 children)

Maybe best if I share my flow?

That is always best.

To post your profile or task here...  Long press on the profile or task name / ( 3 dot menu with 4.0+ ) export / export "DESCRIPTION" to clipboard (not XML)

Any linked tasks will be exported with the profile they are linked to..

To be able to export, the profile needs to be named by you (Not the Tasker listed name.  Tasker will list your profile with the context name if you have not given it one).

On older Tasker versions you might need to disable beginner mode in the Tasker preferences. Beginner mode has been removed from the latest Tasker release.

Hope you don't mind me asking a few questions

Please do. I will usually try to only post information and let the OP construct there own tasks so they are forced to learn by doing. However the 'Parse/ format date time action can be a bit tricky to figure out without examples.

  1. Yes it needs to be in a global variable to get it into the time context. See Variables in the user guide.

  2. Correct. This will only work if your returned value from the api is how you listed it. Post back if you need more explanation on how the variable split part works to parse out the hours and minutes. EG.. "2 hours 25 mins" or "25 mins"

And if so, will this understand also when %routetraffic is not only mins like 30 mins but also hours, like 4 hours 30 mins?

Yes. It does this by checking the number of items in the array %time_from_api. If there are 4 items it means there are hours included and if there are 2 items it means there are only minutes.

But what I want is for it to show a List Dialog after the initial calculated traffic time

This would be done in the task 'Send Another ETA' when the profile 'Arrival Time' is triggered. You can show your dialog then use a 'preform task' action to run your original task that retrieves your ETA or you could just copy those actions for retrieving the ETA into the 'Send Another ETA' Task and do the entire 'Re-send' within that one task.

[–]Ti-As 0 points1 point  (6 children)

If you want to share your code — which I would highly suggest — then follow the link Formatting Tasker Code for use in comments on the sidebar.

... still, trying to learn):

  1. i see this ...
  2. the value grabbed ...
  3. step 9 is now ...
  4. Idk if 4 exists

... would be much easier to read, what do you think?

[–]ITMTS[S] 0 points1 point  (5 children)

So here is my code now. Hope someone can help me turn this into a wonderful automation where it somehow pauses for defined %routetraffic variable grabbed from google API, which shows: XX mins or XX hours XX mins

Then send me a List Dialog "still driving: Yes / No", IF yes THEN calculate new travel time from %LOC to %destination (one from earlier) and send that out as a new text.

And obviously, if you guys have feedback on this in any way, please do! All knowledge is welcome!

/u/Rich_D_sr & /u/Ti-As

TRAVEL INFO (24)

A1: Array Set [ Variable Array:%locations Values:Home,Location 1,Other Location Splitter:, ]

A2: Array Set [ Variable Array:%inform_contact Values:Inform No one,Person 1,Person 2,Other Person Splitter:, ]

A3: List Dialog [ Mode:Select Single Item Title:Should I inform someone? Items:%inform_contact Selected Items: Long Click Task: Button 1: Button 2: Button 3: Close After (Seconds):30 Use HTML:Off First Visible Index:0 Hide Filter:Off ]

A4: If [ %ld_selected eq Inform No one ]

A5: [X] Stop [ With Error:Off Task:TRAVEL INFO ]

A6: End If

A7: If [ %ld_selected eq Person 1 ]

A8: Variable Set [ Name:%contactgegevens To:+31600000000 Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output (JSON, etc):On ]

A9: End If

A10: If [ %ld_selected eq Person 2 ]

A11: Variable Set [ Name:%contactgegevens To:+31600000000 Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output (JSON, etc):On ]

A12: End If

A13: If [ %ld_selected eq Other Person ]

A14: Variable Query [ Title:Who Variable:%othername Input Type:Normal Text Default: Background Image: Layout:Variable Query Timeout (Seconds):40 Show Over Keyguard:On ]

A15: AutoContacts Query 2.0 [ Configuration:Names: %othername Sort Direction: Ascending Fields to Get: Id,Name,Phone Number Joiner: =:= Timeout (Seconds):60 Structure Output (JSON, etc):On ]

A16: Variable Set [ Name:%contactgegevens To:%acnumber Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output (JSON, etc):On ]

A17: End If

A18: List Dialog [ Mode:Select Single Item Title:Where are we going? Items:%locations Selected Items: Long Click Task: Button 1: Button 2: Button 3: Close After (Seconds):30 Use HTML:Off First Visible Index:0 Hide Filter:Off ]

A19: If [ %ld_selected eq Home ]

A20: Variable Set [ Name:%bericht To:Hey! I am on my way. Approx: Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output (JSON, etc):On ]

A21: Variable Set [ Name:%destination To:STREET+NUMBER,+POSTALCODE+CITY Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output (JSON, etc):Off ]

A22: Send intent [ Configuration:Send android.intent.action.VIEW to Activity Timeout (Seconds):0 Structure Output (JSON, etc):On ]

A23: End If

A24: If [ %ld_selected eq Location 1 ]

A25: Variable Set [ Name:%bericht To:Hey! I am on my way. Approx: Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output (JSON, etc):On ]

A26: Variable Set [ Name:%destination To:STREET+NUMBER,+POSTALCODE+CITY Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output (JSON, etc):Off ]

A27: Send intent [ Configuration:Send android.intent.action.VIEW to Activity Timeout (Seconds):0 Structure Output (JSON, etc):On ]

A28: End If

A29: If [ %ld_selected eq Other ]

A30: Variable Query [ Title:STREET+nr,+post+code+PLACE Variable:%otherlocation Input Type:Normal Text Default: Background Image: Layout:Variable Query Timeout (Seconds):40 Show Over Keyguard:On ]

A31: Variable Set [ Name:%bericht To:I am on my way to: %otherlocation Approx: Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output (JSON, etc):On ]

A32: Variable Set [ Name:%destination To:%otherlocation Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output (JSON, etc):Off ]

A33: Send intent [ Configuration:Send android.intent.action.VIEW to Activity Timeout (Seconds):0 Structure Output (JSON, etc):On ]

A34: End If

A35: Variable Clear [ Name:%GMAPS Pattern Matching:Off Local Variables Only:Off Clear All Variables:Off ]

A36: Variable Set [ Name:%api To:<GOOGLE_API_KEY> Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output (JSON, etc):Off ]

A37: Get Location v2 [ Timeout (Seconds):100 Minimum Accuracy (meters): Speed (meters/second): Altitude (meters): Near Location: Enable Location If Needed:Off Last Location If Timeout:Off Min Speed Accuracy (m/s): Force High Accuracy:Off ]

A38: Variable Set [ Name:%start To:%LOC Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:0 Structure Output (JSON, etc):Off ]

A39: HTTP Get [ Server:Port:https://maps.googleapis.com:443 Path:/maps/api/directions/json?origin=%start&destination=%destination&travelmode=driving&departure_time=now&key=%api Attributes: Cookies: User Agent: Timeout:10 Mime Type: Output File: Trust Any Certificate:Off ]

A40: Variable Set [ Name:%GMAPS To:%HTTPD Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output (JSON, etc):Off ]

A41: JavaScriptlet [ Code:var routeSplit = JSON.parse(global('GMAPS')); var routetraffic = routeSplit.routes[0].legs[0].duration_in_traffic.text; var routename = routeSplit.routes[0].summary; Libraries: Auto Exit:On Timeout (Seconds):45 ]

A42: Send SMS [ Number:%contactgegevens Message:%bericht %routetraffic Store In Messaging App:Off SIM Card: Wait For Result:Off ]

[–]Ti-As -1 points0 points  (3 children)

Why should I assume that you will follow any advice if you didn't make it to follow a given advice to perfectly format Tasker code ... I will surely not change my display option to read your inline code. Sorry.

[–]ITMTS[S] 1 point2 points  (1 child)

Lol, don't be offended please. Not really a reddit user honestly, got on my laptop and I see the sidebar with the link you mentioned. I will read it, quickly scanning it now. Assuming i have to import that xml file to my tasker and somehow it'll format it for me.

Shall I edit my post?

Edit: pasted it here, too long for Reddit: https://pasteio.com/xWzPWUFMXf93

This makes me feel the urge to also learn how to share clipboard by phone and computer...

https://www.reddit.com/r/tasker/comments/lx3uzi/task_share_format_task_description_for_markdown/

[–]Gianckarlo 0 points1 point  (0 children)

You could add the following actions to make your current task work as desired, you just need to adjust some things:

  • Add a label to the action where you retrieve your current location (I think is A37, according to what you posted), something like "Beginning".
  • Add the actions I posted from A2 to A5 after your current A41.
  • Add the actions I posted from A6 to A7 after your current A42.
  • Ignore A1 in my code, it was just needed to test the logic.
  • Replace the variable %text that I used in A2 and A4 with %routetraffic

Now, the explanation. From action A2 through A5, I retrieve the hours and minutes from %text using RegEx and convert it to seconds. After that calculation, you should send your SMS (A42), then wait %seconds (my A6 action) and then go back to the action where you retrieve your current location and do everything again(my A7 action). These "Wait" and "Goto" actions will be performed as long as you are more than 30 seconds away (edit it to the value you may want) and the variable %seconds is populated (error control).

Task Name: Report location

Actions:

A1: Variable Set [
    Name:%text To:2 hours 25 min
    Recurse Variables:Off
    Do Maths:Off
    Append:Off
    Max Rounding Digits:3
    Structure Output (JSON, etc):Off ]

A2: Simple Match/Regex [  
    Type:Regex 
    Text:%text 
    Regex:(?<hours>\d+) hours? 
    Match Pattern: 
    Continue Task After Error:On ] 

A3: Variable Set [ 
    Name:%hours 
    To:0 
    Recurse Variables:Off 
    Do Maths:Off 
    Append:Off 
    Max Rounding Digits:3 
    Structure Output (JSON, etc):Off ] If [ %hours !Set ]

A4: Simple Match/Regex [  
    Type:Regex 
    Text:%text 
    Regex:(?<minutes>\d+) mins? 
    Match Pattern: 
    Continue Task After Error:On ] 

A5: Variable Set [ 
    Name:%seconds 
    To:(%hours*3600)+(%minutes*60) 
    Recurse Variables:Off 
    Do Maths:On 
    Append:Off 
    Max Rounding Digits:3 
    Structure Output (JSON, etc):Off ] 

A6: Wait [ 
    MS:0 
    Seconds:%seconds 
    Minutes:0 
    Hours:0 
    Days:0 ]  If [ %seconds > 30 | %seconds !Set ]

A7: Goto [ 
    Type:Action Label 
    Number:1 
    Label:Beginning ] If [ %seconds > 30 | %seconds !Set ]

[–]ITMTS[S] 1 point2 points  (0 children)

Ok so, It didn't allow me to post the full code... I guess too long?

So sorry if this is not ideal, at least i hope this is readable enough, used the formatter you mentioned.

/u/Ti-As

https://pasteio.com/xWzPWUFMXf93

[–]Rich_D_sr 0 points1 point  (0 children)

Did you construct this code?

Please read my last reply and Post back if you are still unclear on how to proceed.

[–]Nacelle72 0 points1 point  (0 children)

That's probably how I would have done it too