[GUIDE][Difficulty: Advanced] Read Google Calendar Events for the Day

Search This thread

htctouchdsds

New member
Nov 25, 2007
1
0
Hello,

you wrote: "Replace MYCALENDAR with the name of the calendar you want to pull from."

Which name should I take? The Link to my Google Calendar? The icon of Google Calendar is named as "Kalender" on my mobile, but the included Calender of Android also called "Kalender".
 
Last edited:

LeftyGR

Senior Member
Oct 18, 2011
2,120
1,712
Bloomington, IL
So I've been playing with this all day. Got it to work with the calendar i want pretty quickly. What I've been trying to do is:

1. Get it to ignore events for the day that have already passed, and no longer currently active.

2. Get it to ignore events past a predefined time in the future (like 4 hours from current time).

I can get tasker to do quite a bit, but I am pretty inexperienced with variables.
 

Javi22

Senior Member
Feb 26, 2011
2,041
188
Madrid
I have been working on modifying these tasks to meet my requirements, and would like to share the results with everyone.
I had a few issues with the way the original calendar task handled overlapping events. All day events and items that overlapped, sometimes either showed the wrong time, or showed multiple times, or did not show at all. Almost made me wake up late one morning.
For all day events, I I set a variable at the beginning to no, and the first event that was not a all day event I set it to yes. from then on, all day events were ignored.
For overlapping events, right before the if loop that parsed all the events I set up a for loop to pass overlapping events to the for loop one at a time. This created the need to rearrange the doublecheck variable, so I appended each event as it went through the for loop and had to search through the variable separately before the loop.

I also split it into two profiles, one that runs in the evening and will set my alarm for work in the morning, and another that runs in the morning that notify's me verbally and with a popup.

I can write a whole Guide if anyone wants to see what I did so they can incorporate it, but for now I just attached the profiles. Let me know if anyone's interested!
I tried the profile from OP, but I needed some for tomorrow events too... So thanks a lot both of you!

However I want to set only an specific calendar in your task, not to read all. I don't know how to proceed, any idea?

This is because I have got some calendar that It's not working well. The task tells me that I have 26 events and keeps telling me the same event separated by 15min time

Thanks in advance
 

Double_U

Member
Oct 20, 2012
17
3
Love this and it works fine for me. Just wondering, as a tasker noob, how do it get it to use military time, so instead of announcing an appointment at 1.00 pm, I'd like it to say 13.00 hours. Any way to do that???
 

nay.e

New member
Aug 4, 2016
2
0
Hi ! :) I've been looking on my problem:
Hi ! Glad to see your post ! Unfortunately i have a problem with the IF condition, probably with the %event(#) neq 0 case ((( any ideas ?

However, it seems that the red flag on the right is not an error, the screenshot has it as well...
Is there any reason why the calendar shoud be google ?

Thanks in advance,
 
Last edited:

kurokirasama

Senior Member
Jun 19, 2012
303
21
Hi, this task seems great!

I'm new to tasker, i downloaded it like a week ago, so i would lime to know if its possible to modify it so that it will only read the events if there is a reminder set up...

Regards,
 

robdhayes

Member
May 14, 2015
12
2
Is it possible to have it pull events from multiple calendars? I'd like to do mine, my wife's, and my hockey team's schedule.

edit: Nevermind... disabled the If statement defining the *CALENDAR*

Now to figure out how to add tomorrow's events as well...
 
Last edited:

sdfgsteve

Senior Member
Dec 24, 2013
94
19
EDIT: I've redone and separated this a bit. I found a few problems with it (two calendar entries with the same name after each other won't get listed, for example) so I've jiggled around with it.

It now uses a global array of upcoming events, within a user-defined time period, and stored a bit more information. Given how long it can take to run for some people with lives (unlike me!) who have many calendar entries, I figured it was best to do this and then let the user run it during the night or something on a trigger. Then, it'll be much quicker when the user actually comes to query the list, because the hard work has been done for them. The task ReadEvents is just one possible implementation of how you can access the global list, by all means shove it in a widget, a notification, anywhere you like (an added bonus of doing the hard work elsewhere).

A countdown type feature (where you can get how long it is until the event starts) is easy to do, as I've stored the start time as seconds - just subtract %TIMES from %event1 before it's formatted, then shove it through the SecondsToDHMS task and it'll give you days, hours, minutes, and seconds until the event starts. I'm toying with building that in and adding it as a parameter, so depending on how you call the ReadEvents task it'll either just give you the time it starts, how long until it starts, or both.

I've also put in explanations - you might need to scroll the code window across to see them. Any questions/comments/suggestions/errata please feel free to point them out. I don't have multiple calendars, so I'm not sure how it would work with that - I've incorporated what others have said, but from what I see it might be a little bit more involved to get everything. Please report back!

Also a huge thanks to @MishaalRahman for giving me the framework to begin with - I've no problem manipulating data, but it can be a bugger in Android/Tasker to figure out which trick you need to do to pull it out of the hat!

Code:
Task: Get Events
1.  Array Clear %CalEvents                                                                                      // Clear existing array
2.  Variable Convert %DATE to Date Time To Seconds                                                              // Get the current time, convert it into seconds since epoch
3.  Variable Set %intervalorday to 0                                                                            // Choose whether to check forward from the beginning of the current day, or from the present moment
4.  Variable Set %interval to 24                                                                                // How many hours to look forward
5.  Variable Set %testinterval to 60*15 DO MATHS                                                                // How granular the search through the calendar is (60 seconds times 15 minutes)
6.  Variable Set %schedstart to %TIMES                                                                          // We start now.  There's no point looking back in time.
7.  Variable Set %schedend to %date + (60*60*%interval) IF %intervalorday eq 0                                  // If we want to check from the beginning of the day, set the end time for (beginning of day + chosen interval)
8.  Variable Set %schedend to %TIMES + (60*60*%interval) IF %intervalorday eq 1                                 // If we want to check from now, set the end time for (now + chosen interval)
9.  Test App Calendar Title data %schedstart store as %event LABEL TEST NEXT EVENT                              // Get title, calendar, start time, end time, and location from the current position of the counter in the calendar
10. Test App Calendar Calendar data %schedstart store as %calendar                                              //
11. Test App Calendar Start (Seconds) data %schedstart store as %eventstart                                     //
12. Test App Calendar End (Seconds) data %schedstart store as %eventend                                         //
13. Test App Calendar Location data %schedstart store as %eventlocation                                         //
14. If %event(#) neq 0 & %eventstart1%eventend1%eventlocation1%event1 !~ %doubleevent                           // If we find something at the current position in the calendar, and it's not the fingerprint of something else we've seen
15.      Variable Set %eventdurations to %eventend1-%eventstart1                                                // Find the duration of the event (in seconds)
16.      Perform Task SecondsToDHMS %par1 %eventdurations return %evenduration                                  // Get a human legible format of the duration
17.      Array Push %CalEvents position 9999 value %eventstart1::%event1::%eventlocation1::%eventduration      // Add the information to the global list of upcoming events                                                                                                      
18.      Variable Set %doubleevent to %eventstart1%eventend1%eventlocation1%event1                              // Set the signature for the current entry                                                                                                                        
19. End If                                                                                                      //                                                                                                                                                                
20. Variable Add %schedstart value %testinterval                                                                // Increment the counter                                                                                                                                          
21. Goto Action Label TEST NEXT EVENT                                                                           // Check the next position                                                                                                                                        

Task: SecondsToDHMS
1.  Variable Set %days to floor(%par1 / 86400) DO MATHS 
2.  Variable Set %hours to floor((%par1 % 86400) / 3600) DO MATHS                                                                                                                                                                                                                 
3.  Variable Set %minutes to floor((%par1 % 3600) / 60) DO MATHS
4.  Variable Set %seconds to %par1 % 60
5.  Variable Set %return to %days day APPEND, IF %days eq 1
6.  Variable Set %return to %hours hour APPEND, IF %hours eq 1
7.  Variable Set %return to %minutes minute APPEND, IF %hours eq 1
8.  Variable Set %return to %seconds second APPEND, IF %seconds eq 1
9.  Variable Set %return to %days days APPEND, IF %days > 1
10. Variable Set %return to %hours hours APPEND, IF %hours > 1
11. Variable Set %return to %minutes minutes APPEND, IF %minutes > 1
12. Variable Set %return to %seconds seconds APPEND, IF %seconds > 1
13. Return %return

Task: ReadEvents
1.  IF %CalEvents(#) > 0                                                                                        // If there any events in the global list    
2.     For %event in %CalEvents()                                                                               // Iterate through them
3.         Variable Split %event splitter ::                                                                    // Split the entry up
4.         Array Push %calevents position 9999 value %event IF %event1 > %TIMES                                 // If the event hasn't passed yet, add it to the local list
5.     End For                                                                                                  //
6.     Say You have no events today. IF %calevents(#) eq 0                                                      // If all the events have passed, say there aren't any upcoming
7.     IF %calevents(#) > 0                                                                                     // If there are events still to come
8.         Say You have one upcoming event IF %calevents(#) eq 1                                                // Say if there's one
9.         Say You have %calevents(#) upcoming events IF %calevents(#) > 1                                      // Say if there's more
10.       For %event in %calevents()                                                                            // Iterate through the local list
11.           Variable Split %event splitter ::                                                                 // Split the entry
12.           Variable Convert %event1 Seconds to Medium Date Time store in %time                               // Convert the time from seconds to something humans can understand
13.           Say %time: %event2: at %event3: for %event4                                                       // Say the event
14.       End For                                                                                               //
15.   End If                                                                                                    //
16. Else                                                                                                        //
17.    Say You have no upcoming events                                                                          // If there's nothing in the global list, then there can't be any upcoming, so tell the user.
 

Attachments

  • GetEvents.tsk.xml
    5 KB · Views: 289
  • ReadEvents.tsk.xml
    4.1 KB · Views: 196
  • SecondsToDHMS.tsk.xml
    4.2 KB · Views: 214
Last edited:

Necromancer3

Senior Member
Jun 14, 2012
192
48
I've done similar, with help from your code.

My query starts from the end of the day moving backwards (from midnight backwards to 6 AM), pushing new events to the start of an array (2nd array for saving the event time).
So the first event of the day ends up first in the array.
the query is set up for 15 min interval (900s).
Then run a for loop taking out the event and its time.
Using a separate task to convert the time into audible AM/PM time (aka introduction to subroutines)

Code:
Calendar# (284)
A1: Variable Convert [ Name:%DATE Function:Date Time to Seconds Store Result In:%start_time ]
A2: Variable Set [ Name:%index To:%start_time + (60*60*24) Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ]
A3: Variable Set [ Name:%end_time To:%start_time + (60*60*5) Recurse Variables:eek:ff Do Maths:eek:n Append:eek:ff ]
A4: Variable Set [ Name:%index To:%index - 900 Recurse Variables:eek:ff Do Maths:eek:n Append:eek:ff ]
A5: Test App [ Type:Calendar Title Data:%index Store Result In:%events ]
A6: For [ Variable:%event Items:%events(:) ]
A7: If [ %arr1 Set ]
<new event (not duplicate)>
A8: If [ %arr(>) !~ %event ]
<save event in arr if not duplicate>
A9: Array Push [ Variable Array:%arr Position:1 Value:%event Fill Spaces:eek:ff ]
<save event time in arr if not duplicate>
A10: Array Push [ Variable Array:%arr_time Position:1 Value:%index Fill Spaces:eek:ff ]
<duplicate event>
A11: Else
<update event start time>
A12: Variable Set [ Name:%arr_time1 To:%index Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ]
A13: End If
A14: Else
A15: Array Push [ Variable Array:%arr Position:1 Value:%event Fill Spaces:eek:ff ]
A16: Array Push [ Variable Array:%arr_time Position:1 Value:%index Fill Spaces:eek:ff ]
A17: End If
A18: End For
A19: Goto [ Type:Action Number Number:4 Label: ] If [ %index > %end_time ]
A20: Say [ Text:No events today Engine:Voice:com.google.android.tts:eng-usa Stream:3 Pitch:5 Speed:5 Respect Audio Focus:eek:n Network:eek:ff Continue Task Immediately:eek:ff ] If [ %arr(#) eq 0 ]
A21: [X] Flash [ Text:There are no events today Long:eek:ff ] If [ %arr(#) eq 0 ]
A22: Say [ Text:eek:ne event Engine:Voice:com.google.android.tts:eng-usa Stream:3 Pitch:5 Speed:5 Respect Audio Focus:eek:n Network:eek:ff Continue Task Immediately:eek:ff ] If [ %arr(#) eq 1 ]
A23: [X] Flash [ Text:There is one event Long:eek:ff ] If [ %arr(#) eq 1 ]
A24: Say [ Text:%arr(#) events Engine:Voice:com.google.android.tts:eng-usa Stream:3 Pitch:5 Speed:5 Respect Audio Focus:eek:n Network:eek:ff Continue Task Immediately:eek:ff ] If [ %arr(#) > 1 ]
A25: [X] Flash [ Text:There are %arr(#) events Long:eek:ff ] If [ %arr(#) > 1 ]
A26: For [ Variable:%index Items:1:%arr(#) ] If [ %arr(#) > 0 ]
A27: Variable Set [ Name:%time To:%arr_time(%index) Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ]
A28: Perform Task [ Name:Time24To12 Priority:%priority+1 Parameter 1 (%par1):%time Parameter 2 (%par2): Return Value Variable:%time Stop:eek:ff ]
A29: Variable Split [ Name:%time Splitter:| Delete Base:eek:ff ]
A30: Say [ Text:%arr(%index) at %time1 %time2 %time3 Engine:Voice:com.google.android.tts:eng-usa Stream:3 Pitch:5 Speed:5 Respect Audio Focus:eek:n Network:eek:ff Continue Task Immediately:eek:ff ]
A31: [X] Flash [ Text:%arr(%index) at %time1 %time2 %time3 Long:eek:ff ]
A32: End For

Code:
Time24To12 (278)
A1: [X] Variable Convert [ Name:%DATE Function:Date Time to Seconds Store Result In:%index ]
A2: [X] Variable Set [ Name:%index To:%index + (60*60*6) Recurse Variables:eek:ff Do Maths:eek:n Append:eek:ff ]
A3: Variable Set [ Name:%index To:%par1 Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ]
A4: Variable Convert [ Name:%index Function:Seconds to Date Time Store Result In:%time ]
A5: Variable Set [ Name:%space To:  Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ]
A6: Variable Split [ Name:%time Splitter:%space Delete Base:eek:ff ]
A7: Variable Set [ Name:%time To:%time2 Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ]
A8: Variable Split [ Name:%time Splitter:. Delete Base:eek:ff ]
A9: [X] Flash [ Text:%time1 Long:eek:ff ]
A10: Variable Set [ Name:%ttime To:%time1-12 Recurse Variables:eek:ff Do Maths:eek:n Append:eek:ff ]
A11: Variable Set [ Name:%time1 To:%ttime Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ] If [ %ttime > 0 ]
A12: Variable Set [ Name:%time1 To:%time1/1 Recurse Variables:eek:ff Do Maths:eek:n Append:eek:ff ]
A13: Variable Set [ Name:%time2 To:%time2/1 Recurse Variables:eek:ff Do Maths:eek:n Append:eek:ff ]
A14: Variable Set [ Name:%time2 To:  Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ] If [ %time2 eq 0 ]
A15: Variable Set [ Name:%time2 To:o %time2 Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ] If [ %time2 < 10 ]
A16: Variable Set [ Name:%AM_PM To:PM Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ] If [ %ttime > 0 ]
A17: Variable Set [ Name:%AM_PM To:PM Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ] If [ %ttime = 0 ]
A18: Variable Set [ Name:%AM_PM To:AM Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ] If [ %ttime < 0 ]
A19: Variable Set [ Name:%result To:%time1|%time2|%AM_PM Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ]
A20: Return [ Value:%result Stop:eek:n ]
A21: [X] Flash [ Text:%result Long:eek:ff ]
 

Attachments

  • Calendar_.tsk.xml
    7.4 KB · Views: 284
  • Time24To12.tsk.xml
    5.2 KB · Views: 157
Jul 15, 2015
14
3
Pensacola
EDIT: I've redone and separated this a bit. I found a few problems with it (two calendar entries with the same name after each other won't get listed, for example) so I've jiggled around with it.

It now uses a global array of upcoming events, within a user-defined time period, and stored a bit more information. Given how long it can take to run for some people with lives (unlike me!) who have many calendar entries, I figured it was best to do this and then let the user run it during the night or something on a trigger. Then, it'll be much quicker when the user actually comes to query the list, because the hard work has been done for them. The task ReadEvents is just one possible implementation of how you can access the global list, by all means shove it in a widget, a notification, anywhere you like (an added bonus of doing the hard work elsewhere).

A countdown type feature (where you can get how long it is until the event starts) is easy to do, as I've stored the start time as seconds - just subtract %TIMES from %event1 before it's formatted, then shove it through the SecondsToDHMS task and it'll give you days, hours, minutes, and seconds until the event starts. I'm toying with building that in and adding it as a parameter, so depending on how you call the ReadEvents task it'll either just give you the time it starts, how long until it starts, or both.

I've also put in explanations - you might need to scroll the code window across to see them. Any questions/comments/suggestions/errata please feel free to point them out. I don't have multiple calendars, so I'm not sure how it would work with that - I've incorporated what others have said, but from what I see it might be a little bit more involved to get everything. Please report back!

Also a huge thanks to @MishaalRahman for giving me the framework to begin with - I've no problem manipulating data, but it can be a bugger in Android/Tasker to figure out which trick you need to do to pull it out of the hat!
I'm curious how you had this set up and working...? Can you please explain what your profile ----> task and how they're called?
 

sdfgsteve

Senior Member
Dec 24, 2013
94
19
I'm curious how you had this set up and working...? Can you please explain what your profile ----> task and how they're called?

I've got it all tied to when the alarm is cancelled. Then it calls a task which reads out the time and date, calls the ReadEvents task, then calls my CatchUp task (for telling me about missed calls, missed texts etc)
 

afarkas

Senior Member
Oct 19, 2013
253
25
attila-farkas.sk
Nearly exactly what i need

First of all - thank you very much for this task... it is nearly what i need :)

But there are some strange things happening...

I have multiple calendars on my google account. When changing *MYCALENDAR* to my account name before the @ (*john.doe*) the task says i have no event... but i have... in my MAIN calendar...
When removing the if condition for setting the calendar, i got one event... from a NON-MAIN calendar...
Only one, even if there are 2 other NON-MAIN calendars that have events...
Strange, no?
 

afarkas

Senior Member
Oct 19, 2013
253
25
attila-farkas.sk
This one is finally working for me... although, not exactly as i need...

Could you please point me what is needed to be changed to:
- widen the timespan? (to set it from 00:01 to 23:59 instead of 6:00 - 22:00)?
- how to prevent to say "at 6" for all day events?
- how to make to read events only from one specific calendar (among 8 i have)?

Thank You


I have been working on modifying these tasks to meet my requirements, and would like to share the results with everyone.
I had a few issues with the way the original calendar task handled overlapping events. All day events and items that overlapped, sometimes either showed the wrong time, or showed multiple times, or did not show at all. Almost made me wake up late one morning.
For all day events, I I set a variable at the beginning to no, and the first event that was not a all day event I set it to yes. from then on, all day events were ignored.
For overlapping events, right before the if loop that parsed all the events I set up a for loop to pass overlapping events to the for loop one at a time. This created the need to rearrange the doublecheck variable, so I appended each event as it went through the for loop and had to search through the variable separately before the loop.

I also split it into two profiles, one that runs in the evening and will set my alarm for work in the morning, and another that runs in the morning that notify's me verbally and with a popup.

I can write a whole Guide if anyone wants to see what I did so they can incorporate it, but for now I just attached the profiles. Let me know if anyone's interested!
 

N1ghtr08d

Senior Member
Feb 15, 2011
783
189
Dublin
Is there any way to make this profile check events that are happening several days from now? I want it to notify me on Thursday if the following Monday is a bank holiday.
I'm still a relative beginner at Tasker so I'm kinda lost.
 

alienyd

Senior Member
Dec 1, 2010
287
96
Is there any way to make this profile check events that are happening several days from now? I want it to notify me on Thursday if the following Monday is a bank holiday.
I'm still a relative beginner at Tasker so I'm kinda lost.
interesting idea!
I think you could try the following steps:
- on Thursday, run the task
- in the part when you calculate the interval to check for events, add +3600*24*4, this will create an offset of 4 days ahead for the interval check.
- you will need to have the bank holiday marked clearly, such as a certain name pattern or something like that so that the task can detect it.
I hope this could help a bit.
 

Puma711

New member
Jul 9, 2017
2
0
In step 19 it reads the event and its start time. I would like to include the time the event ends. Would you tell me how to do that?
 

Top Liked Posts

  • There are no posts matching your filters.
  • 16
    You're a busy person, and you've decided to organize your busy life by placing all your events on Google Calendar. If this describes you, then you might like to know that you can query Calendar for its events and set it up to notify you however you want. This means you don't have to open the app or even display a widget if you want to see what your events for the day are. Here's how.

    This guide is based heavily off of the work of redditor CallMeLucky but written to be more friendly and with more documentation. Credits for the implementation go to him.

    Prerequisites

    • Google Calendar

    Instructions

    1. Create a new task, and name it "Get Events."
    2. Variables --> Variable Convert. Convert %DATE, set the Function to "Date Time to Seconds" and Store Result In %date.
    3. Variables --> Variable Set. Name %schedstart and set To
      Code:
      %date + (60*60*6)
      This sets the start time to 6AM in the morning. If you want to make it earlier, change the 6 to a different number. CHECK DO MATHS!
    4. Variables --> Variable Set. Name %schedend and set To
      Code:
      %date + (60*60*24)
      This sets the end time to midnight. CHECK DO MATHS!
    5. App --> Test App. Type "Calendar Title", Data %schedstart, Store Result In %event. Set the Label to "TEST NEXT EVENT." This is querying Google Calendar using the time to see if there's an event at that time.
    6. App --> Test App. Type "Calendar Calendar", Data %schedstart, Store Result In %calendar. This is querying the calendar to see, if there's an event, which calendar it belongs to.
    7. Task --> If. If %event(#) neq 0 AND %event1 !~ %doubleevent AND %calendar1 ~ *MYCALENDAR*. This will basically check to see if %event is empty or if it matches the previous event, which in either case means there is no new event at this time. Replace MYCALENDAR with the name of the calendar you want to pull from.
    8. Variables --> Variable Convert. Name %schedstart, set Function to "Seconds to Long Date Time." Store Result In %time. Once you've found an event, convert the time it starts at to a human readable time.
    9. Variables --> Variable Split. Name %time, splitter is 2016. We know what today's date is, so let's split the variable to only give us the time today and not the date.
    10. Variables --> Array Push. Name %calevents, Position 999, Value should be
      Code:
      %event1, at %time 2
      Here, we're pushing the event title and its time into an array that we'll read from later.
    11. Variables --> Variable Set. Name %doubleevent, To %event1. Save the event title so when we do our next check we compare to see if it matches, if so, don't save it again!
    12. Task --> End If.
    13. Variables --> Variable Add. Name %schedstart, Value 900. Increment the time to check next by 15 minutes (ie. move up through the day).
    14. Task --> Goto. Type "Action Label" and label should be "TEST NEXT EVENT". Check If and set it to If %schedstart < %schedend. Basically, loop back if we're still in the same day testing the calendar.
    15. Alert --> Say. Text: "You have no events today." Check If and set it to if %calevents(#) eq 0
    16. Alert --> Say. Text: "You have one event today." Check If and set it to if %calevents(#) eq 1.
    17. Alert --> Say. Text: "You have %calevents(#) events today." Check If and set it to if %calevents(#) > 1.
    18. Task --> For. Variable %eventtosay, Items %calevents:)). In this for loop, we're simply reading the calendar events we've found in order.
    19. Alert --> Say. Text: "%eventtosay"
    20. Task --> End For.

    Here are screenshots of the task:
    JmIPouF.jpg

    8OQ3Cfz.jpg

    6Qp6j9g.jpg


    Now you might ask, what do I do with this task? That's up to you! You can have this task run whenever your alarm is dismissed if you're using an app like AlarmPad, or you can make it run when you dismiss an NFC tag using an app like Trigger.

    Below, I am attaching the XML file for the task that you can import. IF YOU IMPORT THIS, YOU MUST EDIT ACTION #6 (THE IF ACTION) AND CHANGE *MYCALENDAR*. REPLACE "MYCALENDAR" WITH THE NAME OF THE CALENDAR YOU WANT TO PULL FROM. You can import a task by putting it in /sdcard/Tasker/tasks. Then when inside Tasker, long-press on the Tasks tab up top and press import.
    8
    I have been working on modifying these tasks to meet my requirements, and would like to share the results with everyone.
    I had a few issues with the way the original calendar task handled overlapping events. All day events and items that overlapped, sometimes either showed the wrong time, or showed multiple times, or did not show at all. Almost made me wake up late one morning.
    For all day events, I I set a variable at the beginning to no, and the first event that was not a all day event I set it to yes. from then on, all day events were ignored.
    For overlapping events, right before the if loop that parsed all the events I set up a for loop to pass overlapping events to the for loop one at a time. This created the need to rearrange the doublecheck variable, so I appended each event as it went through the for loop and had to search through the variable separately before the loop.

    I also split it into two profiles, one that runs in the evening and will set my alarm for work in the morning, and another that runs in the morning that notify's me verbally and with a popup.

    I can write a whole Guide if anyone wants to see what I did so they can incorporate it, but for now I just attached the profiles. Let me know if anyone's interested!
    3
    EDIT: I've redone and separated this a bit. I found a few problems with it (two calendar entries with the same name after each other won't get listed, for example) so I've jiggled around with it.

    It now uses a global array of upcoming events, within a user-defined time period, and stored a bit more information. Given how long it can take to run for some people with lives (unlike me!) who have many calendar entries, I figured it was best to do this and then let the user run it during the night or something on a trigger. Then, it'll be much quicker when the user actually comes to query the list, because the hard work has been done for them. The task ReadEvents is just one possible implementation of how you can access the global list, by all means shove it in a widget, a notification, anywhere you like (an added bonus of doing the hard work elsewhere).

    A countdown type feature (where you can get how long it is until the event starts) is easy to do, as I've stored the start time as seconds - just subtract %TIMES from %event1 before it's formatted, then shove it through the SecondsToDHMS task and it'll give you days, hours, minutes, and seconds until the event starts. I'm toying with building that in and adding it as a parameter, so depending on how you call the ReadEvents task it'll either just give you the time it starts, how long until it starts, or both.

    I've also put in explanations - you might need to scroll the code window across to see them. Any questions/comments/suggestions/errata please feel free to point them out. I don't have multiple calendars, so I'm not sure how it would work with that - I've incorporated what others have said, but from what I see it might be a little bit more involved to get everything. Please report back!

    Also a huge thanks to @MishaalRahman for giving me the framework to begin with - I've no problem manipulating data, but it can be a bugger in Android/Tasker to figure out which trick you need to do to pull it out of the hat!

    Code:
    Task: Get Events
    1.  Array Clear %CalEvents                                                                                      // Clear existing array
    2.  Variable Convert %DATE to Date Time To Seconds                                                              // Get the current time, convert it into seconds since epoch
    3.  Variable Set %intervalorday to 0                                                                            // Choose whether to check forward from the beginning of the current day, or from the present moment
    4.  Variable Set %interval to 24                                                                                // How many hours to look forward
    5.  Variable Set %testinterval to 60*15 DO MATHS                                                                // How granular the search through the calendar is (60 seconds times 15 minutes)
    6.  Variable Set %schedstart to %TIMES                                                                          // We start now.  There's no point looking back in time.
    7.  Variable Set %schedend to %date + (60*60*%interval) IF %intervalorday eq 0                                  // If we want to check from the beginning of the day, set the end time for (beginning of day + chosen interval)
    8.  Variable Set %schedend to %TIMES + (60*60*%interval) IF %intervalorday eq 1                                 // If we want to check from now, set the end time for (now + chosen interval)
    9.  Test App Calendar Title data %schedstart store as %event LABEL TEST NEXT EVENT                              // Get title, calendar, start time, end time, and location from the current position of the counter in the calendar
    10. Test App Calendar Calendar data %schedstart store as %calendar                                              //
    11. Test App Calendar Start (Seconds) data %schedstart store as %eventstart                                     //
    12. Test App Calendar End (Seconds) data %schedstart store as %eventend                                         //
    13. Test App Calendar Location data %schedstart store as %eventlocation                                         //
    14. If %event(#) neq 0 & %eventstart1%eventend1%eventlocation1%event1 !~ %doubleevent                           // If we find something at the current position in the calendar, and it's not the fingerprint of something else we've seen
    15.      Variable Set %eventdurations to %eventend1-%eventstart1                                                // Find the duration of the event (in seconds)
    16.      Perform Task SecondsToDHMS %par1 %eventdurations return %evenduration                                  // Get a human legible format of the duration
    17.      Array Push %CalEvents position 9999 value %eventstart1::%event1::%eventlocation1::%eventduration      // Add the information to the global list of upcoming events                                                                                                      
    18.      Variable Set %doubleevent to %eventstart1%eventend1%eventlocation1%event1                              // Set the signature for the current entry                                                                                                                        
    19. End If                                                                                                      //                                                                                                                                                                
    20. Variable Add %schedstart value %testinterval                                                                // Increment the counter                                                                                                                                          
    21. Goto Action Label TEST NEXT EVENT                                                                           // Check the next position                                                                                                                                        
    
    Task: SecondsToDHMS
    1.  Variable Set %days to floor(%par1 / 86400) DO MATHS 
    2.  Variable Set %hours to floor((%par1 % 86400) / 3600) DO MATHS                                                                                                                                                                                                                 
    3.  Variable Set %minutes to floor((%par1 % 3600) / 60) DO MATHS
    4.  Variable Set %seconds to %par1 % 60
    5.  Variable Set %return to %days day APPEND, IF %days eq 1
    6.  Variable Set %return to %hours hour APPEND, IF %hours eq 1
    7.  Variable Set %return to %minutes minute APPEND, IF %hours eq 1
    8.  Variable Set %return to %seconds second APPEND, IF %seconds eq 1
    9.  Variable Set %return to %days days APPEND, IF %days > 1
    10. Variable Set %return to %hours hours APPEND, IF %hours > 1
    11. Variable Set %return to %minutes minutes APPEND, IF %minutes > 1
    12. Variable Set %return to %seconds seconds APPEND, IF %seconds > 1
    13. Return %return
    
    Task: ReadEvents
    1.  IF %CalEvents(#) > 0                                                                                        // If there any events in the global list    
    2.     For %event in %CalEvents()                                                                               // Iterate through them
    3.         Variable Split %event splitter ::                                                                    // Split the entry up
    4.         Array Push %calevents position 9999 value %event IF %event1 > %TIMES                                 // If the event hasn't passed yet, add it to the local list
    5.     End For                                                                                                  //
    6.     Say You have no events today. IF %calevents(#) eq 0                                                      // If all the events have passed, say there aren't any upcoming
    7.     IF %calevents(#) > 0                                                                                     // If there are events still to come
    8.         Say You have one upcoming event IF %calevents(#) eq 1                                                // Say if there's one
    9.         Say You have %calevents(#) upcoming events IF %calevents(#) > 1                                      // Say if there's more
    10.       For %event in %calevents()                                                                            // Iterate through the local list
    11.           Variable Split %event splitter ::                                                                 // Split the entry
    12.           Variable Convert %event1 Seconds to Medium Date Time store in %time                               // Convert the time from seconds to something humans can understand
    13.           Say %time: %event2: at %event3: for %event4                                                       // Say the event
    14.       End For                                                                                               //
    15.   End If                                                                                                    //
    16. Else                                                                                                        //
    17.    Say You have no upcoming events                                                                          // If there's nothing in the global list, then there can't be any upcoming, so tell the user.
    2
    how about if you have multiple calendars?

    Then simply remove the if condition that requires you to set a specific calendar
    2
    @EnIXmA

    The note at the end of the numbered instructions reads in part, "IF YOU IMPORT THIS, YOU MUST EDIT ACTION #6 (THE IF ACTION) AND CHANGE *MYCALENDAR*. REPLACE "MYCALENDAR" WITH THE NAME OF THE CALENDAR YOU WANT TO PULL FROM."

    I'm sure you recall that when you linked to the various Google services (including calendar), you were asked for the email address of your Gmail account. In this case, you would enter (without the quotes), "*[email protected]*" to replace "*MYCALENDAR*" in step 6.

    As an aside, I set AutoSync off and run a profile that turns it on for a few minutes every hour. When AutosSync is turned on it attempts to sync all enabled accounts. So when I am ready to use this profile for my morning agenda, I turn on AutoSync about 5 minutes prior to running 'GetEvents'.

    I have taken this nifty task and am modifying it to retrieve my 'next' event. If there is a location stored in the event, that information will be passed to Maps for navigation (per the VERY useful tip from the OP located in post 21). I only need to sync Calendar if I have added an event that will occur within the hour. Keeping AutoSync off is just another way to save battery.

    Hope this helps.

    I am using Google calender, in step 6 what should I can be “my calender”to? Google calendar or leave it as it is?
    Should I change something in step 5 too?

    Keeps saying you have no events today