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
- binary_sensor
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: "{{ iif(is_state(cal_switch, 'on'), 'light.turn_on', 'light.turn_off') }}"
target: !input target_light
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.
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!
Yes, it works. I’ve just now updated it with a small modification though, and see more below.
The second post above shows an old way to create separate events based on search criteria in google calendar, but that is not needed anymore. Since then, we’ve added support for calendar triggers that work better.
What I currently use is first add a template entity in templates.yaml to create an entity for the particular calendar event I am trying to match:
So this gives me an entity called binary_sensor.calendar_backyard_light that turns on only when the specific event has started. It also helps that those sensors can preserve state and are useful for tracking/debugging.