Home Assistant: control automation with Google Calendar

How to improve the home automation, using calendar events instead doing it manually

ยท

3 min read

Automations in Home Assistant are very powerful allowing us to control anything in our home and, in this way, help reduce cost and consumption.

To simplify the management I decided to use events to trigger input_boolean flags, and then use the boolean value to trigger what was needed. In this case, if I want to add events I don't need to change a lot of automation because the boolean value is making an abstraction layer.

Holidays Flag

I'll try to drive you to my solution using an example. What about if you want to adapt your home automation on holiday? Following what I said just before, I added a holidays flag

This flag is then used in automation I want to change when I'm not at home for a "long period". For example the water heater:

It is started during the night but only if the holiday flag is off.

Control the flag

And now, how to know if I'm on holiday or not? A simple way to control it, as it is a flag, is switching it manually. But, in 2022, who is still doing manual things? ๐Ÿ˜‚
In Home Assistant there is a Google Calendar integration that allows you to download all the events from one, or more, calendars in a google account. Each of these events became a home assistant event... and then the rest is everything you already know ๐Ÿ˜Ž

When installing the integration you can add it a read or read/write access to the calendars. In some cases, you would like to create new events from home assistant (Did not use it on my side already).

Once connected you can see the list of calendars you are managing in your google account, each of them is giving an entity in home assistant

Oh, what's that homeautomation calendar? ๐Ÿคฉ I created it to separate my personal events, from the ones I would like to use to control the automation. But it is not necessary to do it in this way.

From now on, you can create contition or trigger in automation script based on what happens on the calendar entity.

- alias: Calendar Holidays Event
  id: calendar_holidays_event
  trigger:
    - platform: calendar
      event: start
      entity_id: calendar.homeautomation
    - platform: calendar
      event: end
      entity_id: calendar.homeautomation
  condition:
    - condition: template
      value_template: "{{ 'Holidays' in trigger.calendar_event.summary }}"
  action:
    - if:
        - "{{ trigger.event == 'start' }}"
      then:
        - service: input_boolean.turn_on
          entity_id: input_boolean.vacation
      else:
        - service: input_boolean.turn_off
          entity_id: input_boolean.vacation
  mode: queued

In this example, the automation is triggered by the start and end calendar events, but filtered only for events with a title starting with Holidays.

Create your calendar event, and then let the home automate ๐Ÿ˜Ž
Once synchronized with Home Assistant, the calendar.homeautomation entity will give you the information about the first detected event:

message: Holidays
all_day: true
start_time: '2023-02-11 00:00:00'
end_time: '2023-02-18 00:00:00'
location: ''
description: ''
offset_reached: false
friendly_name: Homeautomation

As I have a separate calendar to control the automation, the holidays putting in this one can be different from the real holidays days. In the example with the water heater, I would like to start back all the automation the day before I come back home.