[RELEASE] Google Calendar Search

Google Calendar Search integrates Hubitat Elevation with a Google Calendar to toggle a virtual switch based on a calendar event. Special thanks to Mike Nestor and Anthony Pastor, members of the SmartThings Community, who originally created this app and @cometfish for porting their code to work on HE in 2019. I have taken this code and refactored it to make it simpler for my personal needs and hope it is useful for others. I have purposely published the code in the HubitatCommunity GitHub repository in hopes that this remains community code and others contribute to it as well.

Differences from SmartThings/Original Ported Version
  • Simpler solution using a switch instead of presence and contact sensor
    • Ability to set a default value of the switch that is used when there is no calendar entry. The switch will toggle from that value if there is a calendar event match. This is useful if you prefer the switch to be of a certain value in dependent rules and apps or viewing on a dashboard.
    • Simple Automation, Motion Lighting, etc apps allow restrictions based on the state of a switch and the GCal Switch can be used for those restrictions.
  • Original version uses Google Search features to find matching events and in my own use of it had many problems where an event was linked that shouldn't have been.
    • This version moved the processing of the search string match to HE.
    • Added ability to search location as well for a match.
  • Ability to enter multiple search strings separated by commas for the same switch:
    • By default the search string entered will be matched to the google calendar title/location using a starts with match
    • A contains search can be entered by inserting an asterisk within the search string. For example to match both Kids No School and Kids Late School, simply enter Kids*School
  • Caching of the day's calendar entries for a set period of time. This is useful when you have many switches checking the calendar for entries that run near the same time. For example I have 5 different search trigger apps that I set to run at 1 AM so instead of querying the calendar 5 times, the first one will cache the results so the others can leverage the cache. Default cache is 5 minutes.

This app allows you to create "search triggers" that will query Event Titles or Location in a designated Google Calendar for events that match a defined search string:

  • Each Search Trigger child app will create a virtual switch that will toggle based on results of the query
  • Within the switch you can set a default value of the switch that is used when there is no calendar entry and the switch will toggle from that value if there is a calendar match. This is useful if you prefer the switch to be of a certain value in dependent rules and apps or viewing on a dashboard.
  • Ability to enter multiple search strings separated by commas for the same switch
    • By default the search string entered will be matched to the google calendar title using a starts with match - calendar enter starting with search string will match
    • A contains search can be entered by inserting an asterisk within the search string. For example to match both Kids No School and Kids Late School, simply enter Kids*School
  • Set the end time of the calendar query. By default, events from the time of search through the end of the current day are collected. Adjust this setting to expand the search to the end of the following day or a set number of hours from the time of search.
  • Caching of the day's calendar entries for a set period of time. This is useful when you have many switches checking the calendar for entries that run near the same time. For example I have 5 different search trigger apps that I set to run at 1 AM so instead of querying the calendar 5 times, the first one will cache the results so the others can leverage the cache. Default cache is 5 minutes.
  • Scheduling:
    • Once Per Day at designated time
    • Every N Hours
    • Every N Minutes
    • Cron Expression
    • Utilize Rule Machine rules to invoke the "refresh" command on your GCal Switch by a set interval and perform the same action.

Example:

I have personally found this useful for the following scenarios:

  • Kids School Holidays - where switches will remain off when mode changes to Day
  • Parent Traveling - where the house will shut down differently based on one parent traveling
  • Guests - guest room lights will not turn off if a guest is staying over
  • USPS Holidays - mailbox alert to remind myself and neighbors that no mail will arrive today

Code and Installation Instructions:

14 Likes

Version History:

  • v1.0.0: Initial Release
  • v1.1.0: Added ability to search the location attribute of a calendar entry within a calendar search trigger.
    • Use case example: I have a motion sensor that turns on the lights in my crawl space and off after a set period of time once there is no active motion. Twice a year my HVAC company comes for preventative maintenance and they complain the lights are turning off on them. I now have a GCal Switch that queries my calendar for an entry where the location is "Crawl" and will turn on the switch that will disable this motion lighting app.
  • v1.2.0: Now support toggling switch at scheduled future time based on calendar event start and end times.
    • If a calendar event match is found and the start time is after the current time, a trigger will be scheduled to toggle the switch at the calendar event start and end times.
    • Each time refresh and poll are executed, any scheduled are removed and re-evaluated based on the calendar events and search criteria.
    • Only files you need to update are the parent GCal Search app and the GCal Switch driver
  • v1.2.1: Fixed a few bugs with scheduling of future events.
  • v1.3.0
    • Calendar names will now default to the "summaryOverride" value if available. This is a custom name applied to the calendar within Google. Based on request from @mikee385
    • Based on popular request, searches can now be periodic every N hours, every N minutes, or via Cron expression string along with previous once a day.
    • Only files you need to update are the parent GCal Search app and the GCal Search Trigger child app
  • v1.4.0: Added offset preference for start and end times so that the switch can toggle N number of minutes before/after event start and/or end dates based on @gertjan.deprez request.
  • v1.4.1:
    • Fixed bug and error in log when an offset was null in the search trigger app
    • Added ability to perform an exact match search where you prefix your search string with "="
    • Added ability to turn off case sensitive matching
    • Cleaned up help text within the GCal Search Trigger app
    • All files have been updated in GitHub
  • v2.0.0:
    • Added necessary files to integrate this with Hubitat Package Manager for installation and updates. Install and updates can now be done via HPM.
    • Added ability to configure the end date for the calendar query. Options include end of current day, end of next day, or a set number of hours from the current time. Request from @halfrican.ak
    • Improved UI formatting and instructional text within the parent and child apps.
  • v2.1.1:
    • Fixed bug with all day events and dates where calendar timezone doesn't match hub timezone. Thanks @mikee385 for the pull request!
    • Added logic to adjust the eventEndTime if there are sequential events that match the search string. This prevents the switch from turning off and on between events if periodic schedule is set. Thanks @mikee385 for the suggestion here.
    • HPM updated with new manifest so you should be prompted to update.
  • v2.2.1:
    • This release will require that you open one of the Search Trigger child apps and click done to save settings for caching purposes.
    • Fixed bug with Number of Hours from Current Time preference not showing.
    • Refactored caching functionality to work with Search range preferences.
    • Caching may have been used before that didn't contain all events. Reworded instructions a bit to be clearer.
    • HPM updated with new manifest so you should be prompted to update.
  • v2.2.2: Fixed a bug that @rakeshg reported with an error that occurred on a new install. HPM has been updated.
  • v2.2.3:
    • Fixed bug with caching of events.
    • Fixed bug with getting end date of search range and cast error. If required endTimeHours preference is not set for some reason, it will default to end of current day. Thanks @trevalex
    • Added toggle to hide offset preferences to help reduce confusion on this optional feature.
6 Likes

This is interesting. Didn't Google change things in regards to access to api?

Not that I am aware of. While creating the documentation I used a few of my gmail accounts to test this and all work fine. The app will never be officially published by Google and it’s used for personal use. My primary account has worked for over 5 years now.

1 Like

I'll have to check it out.

How does this differ from the one ported by @cometfish? I was using that before covid…

Summarized it here:

1 Like

Excellent work!

1 Like

Seems like I can finally shed my dependence on IFTTT now. I have been running that service for this purpose.

1 Like

Would this work for a public Google calendar rather than my own?

(The city of Columbus makes public their trash/recycling calendar, and I'd like to be able to integrate it with my Hubitat. I'm new, so I can't post links. Add a dot gov for the domain 311.columbus/AddrLookupnew.aspx)

If you can subscribe to that public calendar in your own google calendar you should be able to use it.

2 Likes

Hey neighbor! (Also a Columbus resident).
You can input your address on that page and get a calendar that can be added to your Google Calendar. Then you can use this like normal!

V1.1 posted to Github that allows querying the location attribute of a calendar entry. Please see details in post 2 above.

1 Like

Based in the UK I have been looking for this for ages, thank you to everyone who contributed to this.

I have installed the Driver code but cannot see how to add the Apps code, is it possible there is a video online to show the full process? I am happy to contribute ( pay ) for assistance.
Many thanks
Paul

Apps are similar process as Drivers but in a different section. Here is a Docs article on how to do it:
https://docs.hubitat.com/index.php?title=How_to_Install_Custom_Apps

There are two apps and here are the import URLs to make it easier:
Parent App: https://raw.githubusercontent.com/HubitatCommunity/Google_Calendar_Search/main/Apps/GCal_Search.groovy
Child App: https://raw.githubusercontent.com/HubitatCommunity/Google_Calendar_Search/main/Apps/GCal_Search_Trigger.groovy

Thank you Ritchie

I appreciate your time as will investigate this later.

Kindest regards
Paul

1 Like

I got as far as creating the Google API Client ID but could not see where to create the Google API Client Secret

I am happy to pay for someone's time on this, I want to be able to

  1. Read the diary for today
  2. Another routine reads it for 90 days from today
  3. Another reads it for 30 days from today and if keywords exist such as "reserved" or "wedding" then to have Echo Speaks ( installed and working ) to alert me to the content so I can take action.

The logic is that I have an online diary booking system that brings in our accommodation bookings, we mark off our accommodation in the hope of getting a wedding so the word "reserved" will appear in the diary. Within three months it's unlikely we will get a wedding booking in so I then want to release the room.

On the day I really want Alexa to notify me at intervals of the pending appointments.

Many thanks
Paul

Does this have a "power meter" like gcal. gcal takes up quite a lot of state size because of the power meter. All I need is a virtual switch. it's how I've always used gcal anyway. I just don't like the constant on/off power meter.

Sorry for being obtuse, but what are you asking? Not following the correlation between power and a calendar :rofl:

IDK but it is a thing lol.

Download the Hubitat app