Starting a Google Calendar SmartApp


(Ryan B) #1

I’ve been working on a SmartApp to connect to Google Calendar and close a Contact Sensor whenever there is an event for a particular calendar. This is the basis of what I use now to wake me up with a Sonos, which I am moving to SmartThings. What I have probably works, though I’m sure I’ve made some rookie mistakes. One large example is that, I haven’t found a good way to do inline OAuth from the smartthings to Google Calendar. I can’t get a completely static URI, so what I’ve got for now includes out-of-band auth.

With all of this, I’m pretty new to the smartthings community, however. Would anyone here find it useful? I’ve seen it mentioned in other threads here, but haven’t seen any implementations yet. Should I I just share the source for anyone willing to use it? Right now, what I have is on github.

Rule machine - as per the app developer, this app is no longer available for new installs, distribution, or support
(Edward Pope) #2

There is a way to do this through IFTTT, However I would not mind taking a step out of the process and having a direct app doing the work in the ST environment. I currently use it to turn on and off my side light based on a sliding schedule. Probably better ways to do that, but what the heck it worked

(Ryan B) #3

Yes, I looked at the IFTTT approach, but like everything else I’ve tried to do with integrating IFTTT doing some state change in my home, it never has the accuracy I want. They claim “15 minute” accuracy for Google Calendar integration. That could be 15 extra minutes of sleep!

(sidjohn1) #4

WOW that looks pretty good, you put a lot of thought behind this… I may of missed it in the code, but how can a user change what event is the trigger? Can you have different events trigger different virtual switches(child devices)?

(Ryan B) #5

I don’t have any filter yet. but I just split this kind of thing out into it’s own calendars. It wouldn’t be hard to add, though.

(sidjohn1) #6

Here’s how i would use it, I already have a google calendar for travel and it pulls my travel data from tripit. When i schedule travel for work it automagicly gets added to tripit. Tripit updates my google calendar and flows to all of my devices. Its the only way i can keep my crazy travel schedule straight. If i could trigger a virtual switch on/off at the end of a event from a keyword in the event like “Arrive Austin” i could trigger my Nest from away to home early and start cooling/heating my condo as soon as i “land”. No apps, no buttons just my home responding to things i already have to do in a very intelligent way… I think i might cry.
If you build it, ill totally support you with a paypal donation.

(Lost and Confused) #7

@qedi sorry to revive such an old topic. I just discovered this and have tried to paste your github code to automate my wake up routine based on Google Calendar events. I was able to publish the “Calendar Event Sensor”, but can’t seem to get the “Google Calendar Trigger” App to save or publish. Any insight would be helpful.

I’m hoping to use “Rule Machine” to work out when to switch to Wake Up mode.

UPDATE: I was able to add “Google Calendar Trigger” and publish. Don’t know what the problem was with the IDE, but persistence payed off. Problem now is that the SmartApp says that “You are no authorized to perform the requested operation” when I try to add it.

(Lost and Confused) #8

6fd3a45b-1cf7-4ada-8007-9421f36c35d3 9:12:39 PM: error java.lang.NullPointerException: Cannot get property ‘authorities’ on null object @ line 61
6fd3a45b-1cf7-4ada-8007-9421f36c35d3 9:12:39 PM: debug about to create access token
6fd3a45b-1cf7-4ada-8007-9421f36c35d3 9:12:39 PM: debug authPage()

(Mike Nestor) #9

Make sure you enable OAuth on the app. That error will go away then.

You must also create an app in Google Developer Console.
And add the Calendar API to it. Setup the credentials and copy the clientId and clientSecret into the Settings portion of the Smartthings app.

I’m working on refining this. If it works out I’ll post a followup.

(Lost and Confused) #10

@mnestor THANK YOU. I would have never been able to figure it out without your post. I have a working trigger. Now I just need to figure out what to do with it.

(Mike Nestor) #11

Question for you @benzyne and anyone else that wants to chime in.

The use case I have is I want to trigger actions based on entries on 1 or more calendars. The event names will help determine the action.

So for example I have a calendar ST Schedule. If I have an all day event “Vacation” I want to change my morning routing on that day. Which can happen at midnight. Similar if I the event is has “Late Start” in the name. So the current way I’m implementing this is that I will end up with 2 Calendar Event Sensors (CES Vacation and CES Late Start) to do my actions based on.

What use cases would you like implemented?

Btw, I have it working now without requiring you to cut and paste :smiley:

(Lost and Confused) #12

Hello @mnestor, I currently use Tasker, AutoAlarm (plugin for Tasker), SharpTools to automate my Wake Up routine. AutoAlarm is triggered each morning to see when my next alarm is set for on my phone (and concurrently on my wife’s phone the same system is running). If I have an alarm set, then Tasker takes the alarm time and triggers (through SharpTool) a virtual switch to start my Gentle Wake Up dimming in the bedroom, and the thermostat, so that everything is nice and cozy by the time the alarm on my phone sounds. I work M-F, but my wife is a shift worker, so this helps get the house nice and warm for her for the days she’s on shift (sometimes on weekends too). When neither of us have calendar entries, then Wake Up doesn’t trigger for that day, and we can sleep until whenever. This is good enough for now.

What I’d like to do is to use the Google Calendar SmartApp, and link it to “Travel Time Guru” to check if there is unusual traffic to work. add that to the regular time it takes to get ready, and advance the alarm clock time by that amount. The alarm clock app that I use is “Sleep as Android” which has the ability for Tasker to write in new alarm settings, so the ultimate would be for Smartthings to search Google Calendar for entries and automagically writing, then updating the alarm clock.

(Mike Nestor) #13

@benzyne so it sounds like this works as is for you then. I went the way of trying to avoid doing too much on my phone and let ST handle as much as possible.

(Lost and Confused) #14

@mnestor, I’d like to off load the work to Smartthings as well, so I’ll investigate this now that I have the trigger working.

(Lost and Confused) #15

@mnestor, the sensor trigger is VERY intermittent. Is there anything I should look at to troubleshoot?

(Mike Nestor) #16

Sadly that is a limitation of ST API… Polling clarification

I’m trying to work around it before I go with a different solution. Haven’t gotten anything reliable yet.

(Lost and Confused) #17

Thanks @mnestor I was “hoping” that I was doing something wrong, but it looks like its a “feature” of the ST platform.

(Chris Cardé) #18

I was looking for something exactly like this. My golden use case is triggering “Guest Present” mode when Airbnb guests arrive, and automatically canceling it when they leave. This mode “dumbs down” the house to avoid annoying guests, and then makes sure they haven’t left anything on when they go.

One suggestion: consider using iCal feeds in addition to (or even instead of) a full Google calendar.

Another suggestion: allow the user to set rules matching strings in the events to various devices.

I’m really looking forward to seeing where you land with this!

(I got a hair cut from Alexa) #19

This works, I use it!