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

Search This thread

blue_shrink

New member
Jan 21, 2018
1
2
Mmistake at step 10

There is just a little mistake at step 10 : code should read "%event1, at %time2" instead of "%event1, at %time 2".
As a beginner at Tasker, it took me quite a bit of time to find it :p
Anyway, wonderful task ! Tnx !
 
  • Like
Reactions: wvallen and valk791

crueltyfate

Member
May 14, 2013
13
1
Hey,

I've got a question. I've adapted the script(s) found in this guide/the comments so it will only show an event if it is within an hour.

However, I'm trying to show a certain picture for each specific event (recurring daily events). To do so, I've tried to compare the title of an event with the list of events.

At the moment, the events are stored as Calevents1, Calevents2 and so on.
Currently, I'm trying to use:
If
%Calevents() ~R %Calevents1
Popup with image
End if

However, which the current syntax it will show me popup if there is any task, not just the task Calevents1.
Does anyone have a better idea of how to get this to worK?

Thank you!

EDIT: Alright, I figured out one way to do it. For those who want to know, you can use this syntax to compare the stored events with the current event:
%Calevents1 ~R %event2
popup with image 1
else if
%Calevents2 ~R %event2
popup with image 2
end if

However, the downside of this is that if the calendar events change, the combinations between action and picture will be messed up.
So do keep in mind that this would only work if the same activities occur everyday, which might make it quite pointless for a lot of you.

A better way would be to search for matches between a word and the name of an event, however I have not yet been able to figure out how to do this.
 
Last edited:

ChrisN82

New member
Feb 28, 2019
4
0
Thanks, this helped a lot, did some modification to get events from iCal, will post this here later.
 

ThiaJay

New member
Sep 19, 2019
1
0
Thanks for this. I picked up the modified version that included extra arrays for dealing with overlaps (can't see an attach file option to make it obvious which one I am referring to).

I want to use this to pull any instance from the calendar called Leave or Public Holiday to set my finger volume to loud during weekdays when my phone would otherwise need to be silent. I also therefore need to remove the notifications built into this.

Could someone please assist?
 
Last edited:

IconBoy

Senior Member
Sep 19, 2006
132
27
Thank you githyanki for the two files.
I used the Calendar_Today.prf.xml one and that worked, whereas the OP task kept saying "No events for today".

How can your task speak the time as "Sport at nine thirty" instead of "Sport at zero nine colon thirty" or preferably "Half past nine"?

Attached is a task I got from Tasker Google Groups that speaks the time e.g. "It's one minute past twelve" and ideally, I'd appreciate having the events read out in a similar way. Is it possible?
 

Attachments

  • Speak_Time.tsk.xml
    9.7 KB · Views: 13

bush911

Senior Member
Oct 12, 2012
804
341
重庆
Google Nexus 5
Google Pixel
I am here led by Google Search.
It's been 4 years, your Calendar_Today.prf.xml still works.
Thank you so much!
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!
 
  • Like
Reactions: githyanki

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