• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

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

Search This thread

MishaalRahman

Retired Editor in Chief
Nov 2, 2015
1,042
2,133
www.xda-developers.com
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.
 

Attachments

  • Get_Events.tsk.xml
    5.5 KB · Views: 9,920
Last edited:

AKW

Senior Member
Oct 6, 2015
597
571
Jacksonville
I love this task. I've been using it for a hot minute. I have it run immediately after another task that uses an HTTP get to pull and read the weather for the day as well. Great combo to use with an "Alarm Dismissed" trigger like you suggested.
 
  • Like
Reactions: Fam Money

Medfordite

Senior Member
Aug 29, 2012
155
28
Portland
how about if you have multiple calendars?

I second the motion.

I have one exclusively for my work schedule, and one for my personal schedule. It would be ideal to be able to add several calendars at once.

For example, today I had work and a service repair call for my place. Yesterday, I had work, my child had an appointment and a Parent Teacher Meeting all in different calendars. To know that there are three events or all on one schedule that lists the agenda would be cool.
 

Erlonbie123

Senior Member
Feb 23, 2015
75
7
in topic "5", when you say "app" what exactly I have to do? I didn't get it. Sorry I'm a newbie

---------- Post added at 02:56 AM ---------- Previous post was at 02:52 AM ----------

in topic "5", when you say "app" what exactly I have to do? I didn't get it. Sorry I'm a newbie

omg, nevermind, sorry! lol
 
K

kitkat85

Guest
You can use just a couple of actions of CalendarTask plugin in order to that.
 

daede86

Senior Member
Oct 16, 2010
487
39
Milano
i love your idea, it's amazing thanks!!

i'm trying to work in a mod: i don't like the voiceover option, i prefer to receive a notification with the list of events. then if i click on the notification it should open the calendar to check the details.

my mod:

- removed 15. alert, 15. alert, 17. alert
- replaced 19. alert with "Notify sound": Title "Daily Agenda"; Text: "%eventtosay"; Action: "open google calendar"; if "%calevents(#) >0

doing like that i receive a notification with sound (i've added the calendar icon too) instead the voice over.

I have 2 problems, i hope you can help me:
1. all the events are showed once at the time in the same notification (e.g. if i have 3 events, i receive a notification with event 1, than change to event 2 and event 3 in few seconds); it would be nice to have a a list with all the events
2. when i click on the action to open the calendar, it opens the calendar in background without closing the notification panel (see the screenshot)

any suggestions??

thanks a lot!!
 

Attachments

  • Screenshot_2016-03-11-16-16-06.png
    Screenshot_2016-03-11-16-16-06.png
    108.9 KB · Views: 1,791
Last edited:

flash629

Member
Feb 15, 2016
18
1
Raleigh
Great work

Hi, I like the calendar program. I have a question. Where do you get the Calendar Task plugin for reading different events? For example
Personal Calendar: Sister Birthday
Appointments: Dr. Appointment.

Etc.
Another feature that would be good is to read the events out for the week or have a drop down box with selecting By Week or By Day.
 
Last edited:

j03x2

Senior Member
Aug 10, 2012
61
5
I'm trying to make tasker read my events of tomorrow. I changed %date + (60*60*25) and %date + (60*60*48)
Now I want it to say the day and date of tomorrow (for instance "14.03.2016. Tomorrow is Monday.").
I can't use the default variables like %DATE and %DAYW, because they are for the current day.

I already tried converting the schedstart value from seconds back to date.
 
Last edited:
K

kitkat85

Guest
Hi, I like the calendar program. I have a question. Where do you get the Calendar Task plugin for reading different events? For example
Personal Calendar: Sister Birthday
Appointments: Dr. Appointment.

Etc.
Another feature that would be good is to read the events out for the week or have a drop down box with selecting By Week or By Day.
You find it on the play store obviously
 

flash629

Member
Feb 15, 2016
18
1
Raleigh
Weather

I like the program, but please forgive me. I'm using this routine but changing MyCalendar to *. For example: --> If %event(#) neq 0 AND %event1 !~ %doubleevent AND %calendar1 ~ *.
That will read ALL my calendars. The problem comes up after reading the "Event" it will keep on telling me the weather. That's what I'd like to stop. I may have 3 events in different calendars and it reads those events plus the weather for each.

I guess what's happening is because the "Events" are in different calendars I get the weather from each.

Is there away I can just get the weather once?

Thanks for your help.
 

Stiruam

New member
Mar 17, 2016
1
0
Utrecht
Nice script! I tried using it for my university calendar but unfortunately it doesn't get the events right.

Today I have three events, one from 9:30 till 11:30, one from 11:30 till 13:30 and another one from 13:30 till 14:30. The script says I have 20 events today. It says all the events in 15 minute increments. Thats 5 (hours) x 4 (events per hour) = 20.

How would I solve this issue? Unfortunately this makes the script not very useful.
 
Last edited:

flash629

Member
Feb 15, 2016
18
1
Raleigh
Please answer

In a previous post it was suggested that taking out the if statement would give you all your events for the day for all your calendars. I took mine out and it said that I had 72 events.

I changes the If statement in line 6 %calendar1 ~ *Appointments* to %calendar1 ~ ** and what I get is double events. For example Work event at 5:30am then again Work event at 7:15. I don't understand this.

I hope this post is monitored.
 

MishaalRahman

Retired Editor in Chief
Nov 2, 2015
1,042
2,133
www.xda-developers.com
In a previous post it was suggested that taking out the if statement would give you all your events for the day for all your calendars. I took mine out and it said that I had 72 events.

I changes the If statement in line 6 %calendar1 ~ *Appointments* to %calendar1 ~ ** and what I get is double events. For example Work event at 5:30am then again Work event at 7:15. I don't understand this.

I hope this post is monitored.

You still need the Variables --> Variable Set. Name %doubleevent, To %event1 and the If statement: %event1 !~ %doubleevent otherwise you will get double events like you mentioned.
 
Thank you MishaalRahman,

I have read numerous solutions to pulling events from Google Calendar, but none so elegant. I have recently discovered phones and more recently discovered Tasker. My skills are quite rusty but with the help others (you included) I am finding my way. This is a wonderful resource.

As some have already pointed out, this is a great task to include in a wake-up profile. However, not all of us work or sleep on a regular schedule. I remember the 'good ole days' when I could get by on just two jobs.

A moving time segment from 'now' to 'set_length' would be ideal. I think I can work that out. But Event location (address) to pass to Google Maps or Waze as a destination is a topic for which I haven't found much information. Do you (or anyone else) have any suggestions?
 
  • Like
Reactions: MishaalRahman

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