Using Google Calendar as condition in automations

Hey, I just configured the Google Calender integration. I want to set Calender Events as Condition in automations.
So: If there is a event with “Urlaub” in the title, I dont want the automation to run.

I’m pretty new to HASS and I can’t get it to work. My automation for just starting the vacuum at weekdays was fine. But now I need another condition and Iam not sure, what Iam doing wrong…

I found some threads and I tested a lot… Thats my full automation YAML now:

alias: Tägliche Staubsaug-Roboter Reinigung
description: ""
trigger:
  - platform: time
    at: "08:30:00"
  - platform: calendar
    event: start
    entity_id: calendar.XXX_googlemail_com
condition:
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
  - condition: template
    value_template: "{{ 'Urlaub' in trigger.calendar_event.summary }}"
action:
  - service: vacuum.start
    data: {}
    target:
      device_id: ba76ce925395198eb361127769a843fc
mode: single

If I test the condition in the visual editor, its not passing. And I have a event in my calendar, starting yesterday and ending at the start of january with the title “Urlaub: XXX”.

Do I need to do something special, if I use 2 platforms? So the value template “knows” which entity he has to check?! Or something like that?!

Thanks!

See my earlier post on similar question:

1 Like

Hey, thanks for the reply. You are using “state”, not “template”. Its good to know, that I really dont have to add the platform stuff for the calendar for the use case.
But I cant add the entity_id in the condition: template part…

edit
This looked a lot like my problem, too: Automation triggered by certain calendar event name? - #16 by Stooovie

But with just 1 condition. But nothing is working for me so far.

edit2
Btw “not in” isnt working, too… ^^ That was one error in the template.

Send me a message and I’ll try and help

1 Like

Andrew could help me. For ppl that are looking for a solution:

  • Create a Helper (Settings / Devices / Helpers => Creater Helper → Template → Binary Sensor) with a binary sensor template
{{ is_state('calendar.XXX_googlemail_com','on') and 'Urlaub' in state_attr('calendar.XXX_googlemail_com','message') }}

and then its really easy added as additional condition into the automation:

- condition: state
    entity_id: binary_sensor.vacation_bf
    state: "off"

And its very flexible, if you want to use it for other automations, too :slight_smile:

4 Likes

(Andrew also tried to teach a little bit too, so it wasn’t just a copy and paste solution - there was explanation behind it) :wink:

2 Likes

This works great for an automation I have with our kid’s school calendar. They publish all-day events that contain “Non-student day” on days the kids are off, so I built a binary sensor using Acanis87’s binary sensor to look for that condition for the sensor, then can use that sensor for the automation condition to determine if it should run or not. Amazing automation now where the kiddo won’t get woken up on a day that they don’t have school!

Hi there, this is useful thanks all for discussing this. I have now a different use case where “now” I need to check if an event is in the calendar in “now+1h”. With the binary sensor configured like you described I can check only “now”, is there a way to specify a different time do you think?

My use case: I want to turn on the heating on earlier some days, when it happens that I have an early morning meeting

After a day of digging, I think I made it:

{% set next_event = state_attr('calendar.mycalendar', 'start_time') %}
{% set next_event_day = next_event[:10] %}
{% set next_event_hour = next_event[11:13] %}
{% set today = (as_timestamp(now())) | timestamp_custom('%Y-%m-%d %H', True) %}
{% set today_date = today[:10] %}
{% set today_hour = today[11:13] %}
{% set seven = today_hour == '07' and next_event_day == today_date and next_event_hour == '08' %}
{% set eight = today_hour == '08' and next_event_day == today_date and next_event_hour == '09' %}
{% set nine = today_hour == '09' %}
{{ seven or eight or nine }}

this goes in the condition and I’ve got 3 triggers, one at 7, one at 8, one at 9. Then the template checks if the next event in the calendar is today and in the hour after.
Could probably be done more elegantly but it seems to do the job for me.

This is very helpful! I’ve been trying to schedule my WLED roof lights based on a Google Calendar - this approach looks promising. Is there a way to parse through multiple all-day events?

For context, I have a “Roof Lights” calendar where I’m scheduling all-day events for the days that I’d like my lights to turn on (Christmas, Valentine’s Day, etc.). My automation triggers at sunset each day and then will turn on the appropriate WLED preset based on the calendar entry. The tricky part is that I also like to schedule lights based on sports schedules (Auburn, 49ers, and Warriors), which can conflict with the holiday events. For example, there may be a “Valentine’s Day” event on the same day as a “Warriors” event.

One way could be to create another Automation for the sport schedules Calendar(s) that in Actions starts with Disable the original Automation and then after a set nr of hours enables that Automation again.
Also, in the original Automation you can set a Condition with Sport schedules Calendar(s) State as OFF.