[RELEASE] Google Calendar, Task, and Gmail Search and Gmail Notification Device

Unfortunately no. When the app wakes up to search the calendar is searches for events from the current time to the end span specified. You can set it to search as often as you want and if a match is found in the future scheduled jobs are set to toggle the switch based on the calendar start and end times within Google Calendar.

What I don’t understand is your calendar entry screenshot. Is the an event in Google Calendar with defined start of 630 PM and end time of 630 AM? Or is that an all day event?

I'm not exactly sure either. It is a calendar entry that starts at 6:30 PM and ends at 6:30 AM the following morning, spanning midnight of course. So technically, I should be able to start my search at 6 AM in the morning (near the end of my night shift) and still be able to trigger on that event. Correct?

Would you mind explaining the use case a bit more? So far I understand you work until 630 AM on some mornings and you want to check 30 minutes before at 6 to know whether to turn on your truck.

By default this app will toggle a switch (turn on or off based on your preference) the entire span of a calendar entry. So the switch could be in the On state from 630 PM to 630 AM and then Off the rest of the day. Then your other automation could check to see if the GCal Switch is On at 6AM and do whatever. Or you could set an end offset of -30 to turn off the switch 30 minutes early which could then trigger a rule too that checks the weather. Many options. But the main thing is that this app can query this Google Calendar and that the entry has defined start and end time stamps vs being an all day event.

Good info and suggestions. Let me play with it. Thanks.

Michael - not sure why one of my calendar setups did not work. I had 2 "Holiday" events set up (one for Thanksgiving Day and one for the day after Thanksgiving). The Thanksgiving day entry worked but the one for the next day did nothing.

Here are some screenshots of the setup and the event log:

Setup 1:


Setup 2:

Setup 3:

App Setup:

Event Log:


Google Calendar:
Screen Shot 2021-11-26 at 7.18.16 AM

Any idea what could have happened?

1 Like

It’s because you have it query at 11:55 PM. When it ran it still found Thanksgiving Day since there was 5 minutes left of its event and then the scheduled job turned it off at 11:59:59. I have my daily searches run after midnight to prevent this. Mine run at 12:30, 12:31, etc. but anything after midnight should work since the all day events end at 11:59:59.

2 Likes

Hmmm - should it not have found the event for the next day? My search covers that...

@rakeshg When I re-read your post with screenshots I thought that the sequential events setting should have covered this use case. I did a little debugging by setting up my test calendar with your two All Day holidays. Unfortunately sequential events won't work with All Day Events because:
item.eventEndTime(Sat Nov 27 23:59:59 EST 2021) >= newItem.eventStartTime(Sat Nov 27 00:00:00 EST 2021)

Notice they are a second apart. But I can see how this would be useful so I did upload a new version to address this by checking for all day events and if both are, I add a second to the time to see if they match.

v2.5.2 has been uploaded to Github and HPM has been updated.

1 Like

Thanks - will update. I saw today that it found the holiday (Day after Thanksgiving) when it ran at 11:55 PM on November 26. It flipped the switch and then turned it off again at 11:59 PM.

I guess the other workaround would have been to schedule it to run more frequently! Many thanks for the quick response and fix :pray:t3:

2 Likes

@ritchierich there's a small bug if the app is syncing additional switches and the event is multi-day. In #poll, it won't set the syncValue value if the current value and the new value are already the same but then it syncs the child switch to an empty value and in the app, that results in turning it off (or on depending on the default - it falls into the else case). An easy fix that seems to work for me is to guard the syncChildSwitches call on line 110 in the driver. e.g.,

    if (syncValue) {
      logMsg.push("syncing child switch to ${syncValue}")
      syncChildSwitches(syncValue)
    }
2 Likes

@rvrolyk Thanks for letting me know! I have uploaded v2.5.3 to Github to correct this issue. HPM has been updated as well.

4 Likes

Does anyone have a simple example of how to capture the attributes of a GCal switch to use in a rule machine to help me get started? I would like to use the start and end date/times to to make various announcements between those times.
Thank you.

First off welcome to the HE Community. You don’t need the start and end values in a rule if you have the switch toggling based on the event times. Your rule just needs to check the switch state since it will only toggle if an event is found.

I would actually like to do do some preparation announcements slightly prior to the event. I suppose I cold have an additional switch, for that, but was hoping to be able to access those date/ times and not double the number of switches.

This is possible via offset setting where you can have the switch toggle X minutes before/after the event time. Then your rule can be set to trigger based in the switch toggling to make the announcement.

1 Like

I’ll give it a try.
Thanks for your help.

1 Like

Hi, I'm excited to start using this app! I installed it this morning and had some trouble with authentication. The Github instructions direct the user to select "Desktop app" as the application type when creating Credentials within the OAuth client ID. I did this and successfully generated a Client ID and Client Secret, but the app in Hubitat would not except them. When I looked at the Hubitat logs, I got the following error:

something went wrong: groovyx.net.http.HttpResponseException: status code: 401, reason phrase: Unauthorized, [error:invalid_client, error_description:Only clients of type 'TVs and Limited Input devices' can use the OAuth 2.0 flow for TV and Limited-Input Device Applications. Please create and use an appropriate client., error_uri:OAuth 2.0 for TV and Limited-Input Device Applications  |  Google Identity  |  Google Developers]

That suggested to me that the correct application type is "TVs and Limited Input devices" not "Desktop app." I went back to the Google Cloud console, generated a new set of Client ID and Client Secret with the "TVs and Limited Input devices" application type, and that got everything working. Unless I did something wrong, maybe the Github instructions need to updated to reflect this device type rather than Desktop app?

1 Like

Unfortunately Google has changed the console several times since I composed the instructions. Since mine is working I don’t often redo the setup to know that something has changed so I appreciate you letting me know. I will update the instructions in Github.

3 Likes

Thanks for this! Was completely DoA without this post. GitHub instructions definitely need to be updated as the sign up process simply halts if you don't select the correct device type.

I won’t be able to update this for another week, traveling for the holidays without my computer. If either of you have GitHub accounts and could submit a pull request with the update I can accept it. Otherwise I will get to this when I can get back in front of a computer.

2 Likes