Adding Google Calendar to Your Smart Home (Home Assistant)February 27, 2019
Today on the hookup I’m going to show you how to let your smart home adapt to your busy and ever changing schedule by integrating google calendar into your automations.
My wife is a planner, and an awesome one at that. Our shared google calendar is always accurate and up to date, and knowing that really takes a lot of stress out of my life. Unfortunately, based on the events on the calendar I often find myself needing to manually switch automations on or off in home assistant, which sounds like the opposite of automation to me.
In this video I’m going to show you two different ways to integrate your google calendar with your smart home: First through a simple webservice like IFTTT, and then as a component in home assistant.
The easiest way to allow your smart home interact with your google calendar is with the IFTTT webservice. If you’ve never heard of IFTTT, first of all, congratulations on living under a rock for the last 4 years, and second, IFTTT or I. F. T. T. T. is a web service that allows you to write simple If this than that integrations for many of your cloud based products. After simply signing in to your google account and granting access to IFTTT, your google calendar events can be used as If triggers or Then responses in IFTTT and you can pair them with all of the other services already supported by their platform. Some notable integrations include Samsung smart things hub, wink hub, and the Tuya smart app. The setup process is extremely straight forward, and that’s ultimately the reason why IFTTT is so popular. That being said, IFTTT is a web service, and honestly in my experience with it, it has been clunky, slow to respond, and not super reliable. If you’ve only got a few automations and those automations are non-critical, IFTTT will probably work out just fine for you, but if you’re getting serious about home automation there are better ways.
Specifically, home assistant integration with google calendar is not only powerful, but pretty simple and well documented.
To add your google calendar to home assistant you’ll first head over to the google developers console while logged into the google account you want to integrate.
You’ll be presented with a setup wizard that will step you through all the consent screens needed to obtain your OAuth credentials, but you don’t need to finish the whole wizard. When you get to the question asking about which API you’ll be using, you can just click cancel.
Then under API’s and Services select “credentials” and then click on the tab “OAuth consent screen”
On this screen you’ll enter a descriptive product name for this credential, homeAssistant works well, but you can call it anything you’d like. Click save.
Next click “create credentials” “OAuth Client ID”, set the application type to “other” and give a specific name to the credential you are creating, again homeAssistant works fine here. Then click create and it will generate a ClientID and Secret for you.
At this point you’ll want to go into your configuration.yaml file and create an entry called “google” with the values client_id and client_secret. Copy and paste your ClientID and ClientSecret into your configuration.yaml file (or better yet, use your secrets file for these values), but don’t restart home assistant yet.
Go back to the google developers console and search for “Calendar” and select “Google Calendar API”. On the next screen that pops up just click “Enable” and you’re all set.
When you restart home assistant you’ll see a new file show up in your config folder called google_calendars.yaml that will have separate listings for each calendar that you have created yourself or has been shared with you.
For me, I was only interested in adding a sensor two of my calendars, so I under the rest of my calendars I changed the value from “track: true” to “track: false”. I also added a value called “name” to make the calendar names a bit more user friendly, when you’re all finished hit save, then restart home assistant.
When home assistant comes back up you should see all of your tracked calendars under the “states” tab in home assistant, and all that’s left to do at that point is automate.
I do all of my automations in Node-RED, so lets take a quick look at what I’ve done with that. A quick side node before we begin. There is a node palette for node red to directly support google calendar, but the nodes are not being actively maintained, and I was not able to make direct google calendar integration work in node red, I suspect this is because it relies on the google plus API, which was recently marked as end of life. Thankfully, the home assistant integration works perfectly, and node-red plays nice with home assistant.
The two main automations that I’m modifying with google calendar are my sunrise alarm clock, and my daughter’s RGB alarm clock.
The sunrise is simple enough. I just added a home assistant current state node in the middle of the flow to check if the day is marked as “school” or “nonschool” in the calendar. The part of the message that contains that information is specifically msg.data.attributes.message, which I know sounds confusing, but it just comes from the json object that is generated by home assistant. If that particular value comes back as nonschool it blocks the flow and prevents the sunrise from starting so I can sleep in a bit on days off.
My daughter’s schedules are a bit different. On weekdays she has 10 minutes in between her “start waking up”, “start getting dressed” and “go downstairs” lights, so I’m utilizing a trigger node to send the next color after a set amount of time. The light scheduler node triggers every day for “non school days” before checking the calendar to confirm the schedule, this means that long breaks like spring break and winter break will automatically switch for every day. The school days light scheduler is only on weekdays, since we won’t have any surprise school days on the weekend, but it will also check the google calendar with a current state node in home assistant to make sure it won’t wake my daughter up on a non-school day.
Another useful change you could make to these flows would be to use the “contains” flag in the switch node which allows you to parse your events to look for a single word, rather than having to have the entire string correct. In other words, the event doesn’t have to be called exactly “non-school” it could be “non-school – winter break) and because it still contains the word non-school it could work in the automation.
As you can see, the integrations you can make in home assistant are significantly more powerful than what you can do with IFTTT, but they come with a bit more setup. Either way, I hope this video gave you some ideas for how to add google calendar into YOUR automations. If you’re using google calendar in a different way that’s working well for you, let me know down in the comments.
Thank you to all of my awesome patrons over at patreon for your continued support of my channel. If you’re interested in supporting my channel check out the links in the description. If you enjoyed this video, please consider subscribing, and as always, thanks for watching the hookup.