Calendar based triggers

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic is resolved. This helps other users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.

Tip:
It’s the post that answers/solves the question/problem that is marked with the Solution tag. You marked your own post but it doesn’t contain information that explains why your automation failed to trigger.

Thanks again!

1 Like

Hi again - I’m sorry but the automation really isn’t working. Two things:

  1. Doesn’t automatically fire at midnight

  2. It’s always a “workday” regardless if that text is in the current calendar day.

Solutions are much appreciated!

What changed to make it go from
“This worked perfectly.”
to
“Doesn’t automatically fire at midnight”

I think I was too eager and when I was originally testing, it was a workday and the notification said it was a workday. Poor troubleshooting on my part, I should have waited.

I don’t think it’s reading today’s calendar_event.summary.

Basically, I’m trying to do the same thing here as this thread. I have a separate calendar that my wife uses for school (teacher.) There are 4 kinds of “days” she works. When those days are not present in the calendar, she isn’t working. All the morning automations should be turned off or other “vacation” automations should fire.

Her work days are “Red Day”, “Blue Day”, “CCR Day”, and “Purple Day”. These are all day events in the calendar.

How do I best do this automation? I see the link below has a relatable situation but am not sure how to proceed.

The automation I posted above only works if the calendar event’s summary contains the word “workday”. It won’t match “Red Day”, “Blue Day”, etc.

Did you modify the automation to match those words? Please post the exact automation you are using with whatever modifications you made.

Yes. Work day was just something I used to make it easy to understand.

Post the modifications you made to the example.

Not sure how to “query” the calendar and tell me what it thinks today is. Here is the automation and sample calendar screenshot.

alias: Work day
description: “”
trigger:

  • platform: calendar
    event: start
    offset: “-0:0:0”
    entity_id: calendar.rhs_sy22_23
    condition:
  • condition: or
    conditions:
    • condition: template
      value_template: “{{ ‘Red Day’ in trigger.calendar_event.summary }}”
    • condition: or
      conditions:
      • condition: template
        value_template: “{{ ‘Blue Day’ in trigger.calendar_event.summary }}”
    • condition: or
      conditions:
      • condition: template
        value_template: “{{ ‘Purple Day’ in trigger.calendar_event.summary }}”
    • condition: or
      conditions:
      • condition: template
        value_template: “{{ ‘CCR Day’ in trigger.calendar_event.summary }}”
  • condition: time
    before: “00:00:00”
    after: “05:00:00”
    weekday:
    • mon
    • tue
    • wed
    • thu
    • fri
      action:
  • service: notify.persistent_notification
    data:
    message: Today is a work day
    mode: parallel
alias: Work day
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "0:0:0"
    entity_id: calendar.rhs_sy22_23
condition:
  - condition: template
    value_template: >
      {% set days = ['Red Day', 'Blue Day', 'Purple Day', 'CCR Day'] %}
      {{ days | select('in', trigger.calendar_event.summary) | list | count > 0 }}
action:
  - service: notify.persistent_notification
    data:
      message: "It's a workday."
mode: single

Are the scheduled events All Day events? Or are they events with start and stop times?

If they are All Day events, the trigger occurs at midnight (start of the new day) so you can’t add a Time Condition restricting the time for ‘after 05:00’ because then you won’t get a notification.

Yes they are all day events. Okay, that makes sense. I will try that and get back to you.

No notification. I’m wondering if it’s because it’s an Apple Calendar and not a Google Calendar? Should that even matter? It’s an iCal format and HA sees it.

At this point I would eliminate the Template Condition and see if the Calendar Trigger works.

Yeah, nothing has triggered. I’m going to change the name to Schoolday and copy the code there.

alias: Schoolday
description: “”
trigger:

  • platform: calendar
    event: start
    offset: “0:0:0”
    entity_id: calendar.rhs_sy22_23
    condition:
  • condition: template
    value_template: >
    {% set days = [‘Red Day’, ‘Blue Day’, ‘Purple Day’, ‘CCR Day’] %}
    {{ days | select(‘in’, trigger.calendar_event.summary) | list | count > 0 }}
    action:
  • service: notify.persistent_notification
    data:
    message: “It’s a school day.”
    mode: single

You’re saying that after you removed the Template Condition from the automation (like I had suggested), it still failed to trigger?

yes! Nothing triggered.

I was wondering if “work” was a reserved word or something.

If the following automation fails to trigger then the problem isn’t the automation but in the Caldav integration (or the testing procedure).

alias: Work day
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "0:0:0"
    entity_id: calendar.rhs_sy22_23
condition: []
action:
  - service: notify.persistent_notification
    data:
      message: "Detected a scheduled event."
mode: single

Okay, I’ve added and will let you know tomorrow since this only triggers once.

Found this in the CalDAV documentation. Maybe why it’s not firing.

This example will generate default binary sensors for each calendar you have in your account. Those calendars will be on when there is an ongoing event and off if not. Events that last a whole day are ignored in those calendars. You have to setup custom calendars in order to take them into account or for advanced event filtering.”

Here is my new config.yml entry. This brings everything in now (as it was before) but I still don’t think it’s triggering.

#Apple calendar
calendar:

  • platform: caldav
    url: https://caldav.icloud.com
    username: !secret apple_user
    password: !secret apple_specific
    custom_calendars:
    • name: Family
      calendar: “Family”
      search: “”
    • name: RHS
      calendar: “RHS SY22-23”
      search: “.*”

Automations:
alias: Work day1
description: “”
trigger:

  • platform: calendar
    event: start
    offset: “0:0:0”
    entity_id: calendar.rhs_sy22_23_rhs
    condition: []
    action:
  • service: notify.persistent_notification
    data:
    message: Detected a scheduled event1.
    mode: single