Calendar automations (what if no title, or no other detail)

Hi!

I want to make an automation which triggers some “define variables” when a calendar event is starting…
Lets say that I will add a new event to the calendar, but I don’t write the title, no description, no location, nothing, only the time when the event starts…
The automation will trigger to define 6 variables with the values of these details: summary, start, end, location, description, all_day…
If one of the detail is empty because it was not written into the event, add the value “.” to that variable…

Well, how can I do that? This is what I tried till now, as conditions, but no luck:

{{ trigger.calendar_event.summary | trim == "" }}
{{ trigger.calendar_event.summary is none }}
{{ trigger.calendar_event.summary is not defined }}

All I know that “all_day” will return True or False, depending how the event was configured, but all other details…

Anyway, none of these are working… Any other idea?

Thanks.

The overall concept of what you are trying to do is unclear…

Summary (called “title” by some calendar providers) is a required field, at least as far as HA is concerned. If you are creating the calendar event without a summary in some other calendar software, it’s likely going to cause issues.

Neaa… I don’t think that HA cares if you add a title or not, to the calendar event… and after some tests, seems that does not care about any other detail you add or not.

Look, an event for today, configured like this:
Title: Testing
Date start: 00:40
Date end: 01:40
With no other details, using the next automation:

alias: Notify - Calendar Events
description: ""
triggers:
  - trigger: calendar
    entity_id: calendar.work
    event: start
    offset: "0:0:0"
conditions: []
actions:
  - variables:
      summary: "{{ trigger.calendar_event.summary }}"
  - variables:
      start: "{{ trigger.calendar_event.start }}"
  - variables:
      end: "{{ trigger.calendar_event.end }}"
  - variables:
      all_day: "{{ trigger.calendar_event.all_day }}"
  - variables:
      location: "{{ trigger.calendar_event.location }}"
  - variables:
      description: "{{ trigger.calendar_event.description }}"
  - action: persistent_notification.create
    metadata: {}
    data:
      title: Calendar Event (test ok)
      message: >-
        {{ summary }}/{{ start }}/{{ end }}/{{ all_day }}/{{ location }}/{{
        description }}

will result this:
"Testing/2024-11-10T00:40:00+02:00/2024-11-10T01:40:00+02:00/False//"

Another event, without a title, will have the result like this:
"/2024-11-10T00:40:00+02:00/2024-11-10T01:40:00+02:00/False//"

As you can see, where there is no data, home assistant will have no data as well, excepting “all_day” which always will have a result, as (True/False)…

So, regarding these details, how can I do this:

alias: Notify - Calendar Events
description: ""
triggers:
  - trigger: calendar
    entity_id: calendar.work
    event: start
    offset: "0:0:0"
conditions: []
actions:
  - if:
      - condition: template
        value_template: "{{ trigger.calendar_event.summary | trim == '' }}"
    then:
      - variables:
          summary: "{{ '.' }}"
    else:
      - variables:
          summary: "{{ trigger.calendar_event.summary }}"

This is what I want to achieve… if there is no detail, give the value “.” to that variable, if not, give the value of the trigger…

Edit: By the way, this… “all_day” type event… has anyone manage how to trigger the calendar event from HA? If I make an event calendar with “all_day” enabled (which means that there is no hour set for start/end), HA does not know when to trigger the calendar event, in order to run the automation… As far as I know, the standard hour for android devices, when you set “all_day” for an event, is 9:00 … But testing it with HA, the automation does not trigger…

Oh, but wait a second… I am not achieving this because I stuck my mind into using the triggers into conditions, instead of this, I could use a trigger for that calendar (in order to find out the changes of any attribute), then I could use trigger.entity_id attributes, in conditions…

Hmmm… In this way, triggers like " trigger.calendar_event.summary" are useless, I don’t see the point of using them… Right?

To what purpose? Explain the goal, not the procedure…

Absolutely wrong. If you don’t see their usefulness, then you likely don’t understand calendar triggers or calendar entity behavior.

1 Like

If an event will start from my google calendar, I want home assistant to extract all the datas and send them to my android device, where Tasker with the help of AutoNotification, will capture these informations, add them to an array, then throw them into a tasker scene, showing the event as a full screen notification.
When a detail is not defined (like the location, title, description), tasker should not show that info. This is where I got stuck:

alias: Notify - Calendar Events
description: ""
triggers:
  - trigger: state
    entity_id:
      - calendar.work
conditions:
  - condition: state
    entity_id: calendar.work
    state: "on"
actions:
  - if:
      - condition: template
        value_template: "{{ state_attr('trigger.entity_id','message') != '' }}"
    then:
      - variables:
          summary: "{{ state_attr('trigger.entity_id','message') }}"
    else:
      - variables:
          summary: " "
  - if:
      - condition: template
        value_template: "{{ state_attr('trigger.entity_id','all_day') == false }}"
    then:
      - variables:
          start: >-
            {{ as_timestamp(state_attr('calendar.work','start_time')) |
            timestamp_custom('%H:%M:%S, %d.%m.%Y') }}
    else:
      - variables:
          start: " "
  - if:
      - condition: template
        value_template: "{{ state_attr('trigger.entity_id','all_day') == false }}"
    then:
      - variables:
          end: >-
            {{ as_timestamp(state_attr('calendar.work','end_time')) |
            timestamp_custom('%H:%M:%S, %d.%m.%Y') }}
    else:
      - variables:
          end: " "
  - if:
      - condition: template
        value_template: "{{ state_attr('trigger.entity_id','all_day') == true }}"
    then:
      - variables:
          all_day: All Day
    else:
      - variables:
          all_day: " "
  - if:
      - condition: template
        value_template: "{{ state_attr('trigger.entity_id','location') != '' }}"
    then:
      - variables:
          location: "{{ state_attr('trigger.entity_id','location') }}"
    else:
      - variables:
          location: " "
  - if:
      - condition: template
        value_template: "{{ state_attr('trigger.entity_id','description') != '' }}"
    then:
      - variables:
          description: "{{ state_attr('trigger.entity_id','description') }}"
    else:
      - variables:
          description: " "
  - action: notify.mobile_app_entrance_tablet
    metadata: {}
    data:
      title: Calendar Event
      message: >-
        {{ summary }}/{{ start }}/{{ end }}/{{ all_day }}/{{ location }}/{{
        description }}
mode: single

The automation it is sending everything needed and if a detail will not be available, it will send " " (space), because tasker does not know about a variable with no value, it will fire an error, so, the character space, will help in this situation.
All good with this, it is working, but I have an event type “all_day”, the automation will not trigger anymore for other events (in that day), only after this “all_day” type event will finish, then, the automation will trigger again for the next events… So, it is not a good solution till now, I am still trying to make it work…

I know that summary attribute it is NOT optional, but doesn’t care so much. If you don’t trust me, test it. I created an event with no title, when the event will fire and home assistant request the needed infos, it will not care, not even an warning will appear, it will not give a value to that attribute, thats it…

Now, after more tests, I am aware that I was wrong thinking that those attributes arre useless… I thought that I can do everything with the entity attributes, but nope… as you can see my upper automation, that will not work for the case with all_day…

Use the default templating filter.

You’re going to have issues with scope… Script Syntax - Home Assistant

Also, be aware that basing anything off the value of the calendar entity instead of the trigger will be unreliable if the calendar has events that overlap (this includes all-day events).

1 Like

Yes, exactly this I have managed today :frowning: Seems that I need a way to use the trigger attributes… in order to avoid overlaping the events… Thanks

Edit: wait a sec… sooo… variables does not keep/change the value between the blocks inside the same automation?? It thought that it will keep the value till at the end of the blocks… Or I don’t understand something?

Correct. They are local, not global.

1 Like

Wow… this is bad :frowning: I always thought that these type of variables are local per automation, not per sequence… I mean, it is bad and good, I don’t know what to say, i’m a bit dissapointed by finding out now, but I am glad that I didn’t use this too much… It will be extremely good if HA could have 2 types of variables… local as working in complete automation script and one big ultra global which stands between automations as well…
Nice, what can I say… again, dissapointed that I found out so late :slight_smile: Thanks you both for pointing this to me.

It’s time to use the variable add from hacs…

Thanks again

By the way, about this calendar, if I will have these type of overlay events, like two events type of all_day and another 5 events during the day, which all overlaps, how can I get the trigger to work? I mean, for the non-all_day, it will work, it will trigger the automation, but what about all_day type events? I tested with one all_day event, and the automation didn’t triggered, using the calendar trigger…
I am doing something wrong or I need to approach other solution for all_day events?

Thanks