Evening Light schedule driven by Google Calendar

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

I use the Google Calendar integration to control lights around the outside of my home according to a schedule.

Then use the binary sensor created as input into the blueprint automation. The calendar entry defines the earliest time the light can turn on, but also won’t turn on until sunset. That is, the light will turn on after sunset and after the event has started. The light shuts off when the calendar event is over.

blueprint:
  name: Evening Light Calendar
  description: Use a calendar for managing a light schedule.  Lights are turned on according the calendar schedule, and only after dark.
  domain: automation
  input:
    calendar_sensor:
      name: Calendar Sensor
      selector:
        entity:
          domain: calendar
    target_light:
      name: Light
      selector:
        target:
          entity:
            domain: light

variables:
  cal_switch: !input calendar_sensor

trigger:
- platform: state
  entity_id: !input calendar_sensor
- platform: sun
  event: sunset

condition:
- after: sunset
  condition: sun

action:
  service: >
    {% if is_state(cal_switch, 'on') %}
      light.turn_on
    {% else %}
      light.turn_off
    {% endif %}
  target: !input target_light
1 Like

Here is an example google_calendars.yaml file pointed at a secondary calendar in my account. The event descriptions have a hash tag that I use to match the calendar entity.

- cal_id: [email protected]
  entities:
  - device_id: backyard_light
    name: Backyard Light
    search: "#Backyard"
    track: true

I’m using a similar search for my google calendar integration, but I’m struggling to get it to work right. To work off of your example, I have events in my calendar with titles #Backyard and others with something like BBQ in Backyard. With the search on #Backyard, I would expect to only have the events with that title, but instead it’s triggering on all events with Backyard in them, which means both sets of events. It’s like it’s ignoring the # in the search…have you had any experience with this?

Ah I have not looked at that. In my case I also use a dedicated additional calendar so maybe I just get lucky since all my hash tags are unique.

You may want to see what happens searching in the Google calendar UI and see if it matches and maybe we should try a different method.

Longer term: I am building a new way to do automations for calendar events in home assistant using Triggers instead of treating the calendar as a binary sensor, and that will pass the full event struct to the automation, giving you ability to do your own string matching rather than relying on the API searching.

Yea, so if I put in a search like #Backyard in the normal Google calendar ui search field, every event with Backyard in the title is returned…so seems like Google ignores the #. I also tested with @ and it also ignores that.

I’m really interested in the triggers instead of a binary sensor…can’t wait to see that when you get to it!