Calendar (local) trigger

Hello, I am testing with the local calendar feature. I created an event with a duration of “all day”. I also associated an automation that monitors the occurrence of this event. As a result, at 12:00:00 AM today, I observed 2 behaviors. The first at 12:00:00 AM and the second at 12:00:13 AM

A first “trigger” woke up at 12:00:00 AM:

entity_id: calendar.vacances
event: start
trigger: calendar

and I got errors in the following code:


actions:

  • data:
    title: :warning: [Extérieur] Exécution réalisée Off_cd_matin_exterieur
    message: |
    Nouvel événement du calendrier :
    Titre : {{ trigger.to_state.attributes.message }}
    Description : {{ trigger.to_state.attributes.description }}
    Début : {{ trigger.to_state.attributes.start_time }}
    Fin : {{ trigger.to_state.attributes.end_time }}
    {% if ‘Vacances’ in trigger.to_state.attributes.description %}
    Le mot ‘Vacances’ est présent dans la description.
    {% else %}
    Le mot ‘Vacances’ n’est pas présent dans la description.
    {% endif %}
    data:
    persistent: true
    sticky: true
    vibrationPattern: 100, 1000, 100, 1000
    ttl: 0
    priority: high
    color: “#2DF56D
    clickAction: lovelace-accuweather/exterieur-
    action: notify.mobile_app_sm_s928w

The “trigger…” variables were not recognized.

At 12:00:13 AM, the “trigger”:

trigger: state
entity_id:

  • calendar.vacances
    from: “off”
    to: “on”
    enabled: true

and I got an execution as expected for the notify.

What I’m trying to understand is why the automation was requested at 12:00:00 AM and again at 12:00:13 AM for the same calendar entry.

Thanks for your comments and suggestions

Please format your code, otherwise it’s not possible to detect potential YAML indentation errors.

1 Like
data:
  title: ⚠️ [Extérieur] Exécution réalisée Off_cd_matin_exterieur
  message: |
    Nouvel événement du calendrier :
    Titre : {{ trigger.to_state.attributes.message }}
    Description : {{ trigger.to_state.attributes.description }}
    Début : {{ trigger.to_state.attributes.start_time }}
    Fin : {{ trigger.to_state.attributes.end_time }}
    {% if 'Vacances' in trigger.to_state.attributes.description %}
    Le mot 'Vacances' est présent dans la description.
    {% else %}
    Le mot 'Vacances' n'est pas présent dans la description.
    {% endif %}
  data:
    persistent: true
    sticky: true
    vibrationPattern: 100, 1000, 100, 1000
    ttl: 0
    priority: high
    color: "#2DF56D"
    clickAction: lovelace-accuweather/exterieur-
action: notify.mobile_app_sm_s928w

and

alias: “TEST: Calendrier Vacances#2”
description: “”
triggers:

  • entity_id: calendar.vacances
    event: start
    trigger: calendar
  • trigger: state
    entity_id:
    • calendar.vacances
      from: “off”
      to: “on”
      enabled: true
      type or paste code here
alias: "TEST: Calendrier Vacances#2"
description: ""
triggers:
  - trigger: calendar
    entity_id: calendar.vacances
    event: start
  - trigger: state
    entity_id: calendar.vacances
    from: "off"
    to: "on"
    enabled: true
conditions: []
actions:
  - action: notify.mobile_app_sm_s928w
    data:
      ... etc ...

Your automation monitors calendar.vacances using a Calendar Trigger and a State Trigger. Why?

I recommend you remove the State Trigger.

The templates in your action refer to various properties of the trigger variable, like message in trigger.to_state.attributes.message, that do not exist when the State Trigger is triggered (or even the Calendar Trigger). That explains why you got an error message when the State Trigger was triggered.

Thanks, I’ll remove the “state trigger”. Now, the contents of the calendar entry are in which variables?

The available properties of the trigger variable for Calendar triggers can be found in the Automation Trigger Variables page of the docs.

data:
  title: ⚠️ [Extérieur] Exécution réalisée Off_cd_matin_exterieur
  message: |
    Nouvel événement du calendrier :
    Titre : {{ trigger.calendar_event.summary }}
    Description : {{ trigger.calendar_event.description }}
    Début : {{ trigger.calendar_event.start }}
    Fin : {{ trigger.calendar_event.end }}
    {% if 'Vacances' in trigger.calendar_event.description %}
    Le mot 'Vacances' est présent dans la description.
    {% else %}
    Le mot 'Vacances' n'est pas présent dans la description.
    {% endif %}
  data:
    persistent: true
    sticky: true
    vibrationPattern: 100, 1000, 100, 1000
    ttl: 0
    priority: high
    color: "#2DF56D"
    clickAction: lovelace-accuweather/exterieur-
action: notify.mobile_app_sm_s928w
1 Like

I made the adjustments. However now, since I simplified the triggers, HA no longer executes the automation, weird.

alias: "Test Calendar #3"
description: ""
triggers:
  - trigger: calendar
    entity_id: calendar.vacances
    event: start
    offset: "0:0:0"
conditions: []
actions:
  - data:
      title: ⚠️ [Extérieur] Exécution réalisée 
      message: |
        Nouvel événement du calendrier :
        Titre : {{ trigger.calendar_event.summary }}
        Description : {{ trigger.calendar_event.description }}
        Début : {{ trigger.calendar_event.start }}
        Fin : {{ trigger.calendar_event.end }}
        {% if 'Vacances' in trigger.calendar_event.description %}
        Le mot 'Vacances' est présent dans la description.
        {% else %}
        Le mot 'Vacances' n'est pas présent dans la description.
        {% endif %}
      data:
        persistent: true
        sticky: true
        vibrationPattern: 100, 1000, 100, 1000
        ttl: 0
        priority: high
        color: "#2DF56D"
        clickAction: lovelace-accuweather/exterieur-
    action: notify.mobile_app_sm_s928w
mode: single

When is the next scheduled event in calendar.vacances?

If the next event is an “all day” event, your automation’s Calendar Trigger will trigger at 00:00 on the scheduled day.

I scheduled one for 13:00:00 but with no results.

I have another scheduled for 13:45:00.

From the documentation:

Note that calendars are read once every 15 minutes. When testing, make sure you do not plan events less than 15 minutes away from the current time, or your trigger might not fire.

1 Like

I have calendar entries for 14:15:00, 14:30:00

I’m monitoring

Calendar Vacances is a local calendar

This works great, I didn’t take into account the sync delay.
Thanks for your advice

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 has been resolved. This helps users find answers to similar questions.

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