Best flow for calendar event triggered automations

I have a calendar called Kiosk on which I’d like to place multiple triggers (e.g. trigger 1, trigger, 2, trigger 3, etc.) at different times each day to run a different script (e.g. script 1, script 2, script 3, etc.) for each trigger.

Since Calendar-triggered automations do not seem to support Trigger ID’s for discrete events (i.e. the content in a single event’s summary), what is the best flow for configuring them?

Here is what I’ve tried so far:

alias: Kiosk Calendar Scripter
description: Activate scripts based on calendar events
trigger:
  - platform: calendar
    event: start
    entity_id: calendar.kiosk
action:
  - data_template:
      entity_id: >
        {% set event_summary = trigger.calendar_event.summary %}
        {% if 'trigger 1' in event_summary %}
          {{ 'script.script_1' }}
        {% elif 'trigger 2' in event_summary %}
          {{ 'script.script_2' }}
        {% elif 'trigger 3' in event_summary %}
          {{ 'script.script_3' }}
        {% endif %}
    action: script.turn_on
mode: parallel

I suggest you give your scripts the same name as the event.

script.sleep
script.wakeup
script.nutrislice
script.here_comes_the_bus_morning
script.here_comes_the_bus_afternoon

Then your template can be reduced to this:

  - action: script.turn_on
    target:
      entity_id: "script.{{ trigger.calendar_event.summary | slugify }}"

OK, sure I could optimize the template with that approach (although a quick test was not successful using the template I originally posted). So, thank you.

But I’m more asking if this (using templates) is really the most optimized way to trigger automations based on discrete calendar events? It seems they could add a field in calendar triggers for event summary and then I could use Trigger ID’s like any other automation.

Are you asking how it can be done with features that exist or with features that you would like to have added? Because the latter would be a Feature Request.

Personally, I would prefer to use a single Calendar Trigger and allow the action to determine which event occurred (using a choose or templated action as suggested above) as opposed to creating multiple Calendar Triggers, one for every possible scheduled calendar event.

Well, both since I’d like to get this working (with templates for now) and I wasn’t sure if I was missing something since the current Calendar triggers seem so basic.

For templates, do you see anything that would prevent the template I OP’d from working (even if it’s not the most efficient)?

I also tried using the Choose method which is what I would normally use with Trigger ID’s but set the conditional to the template instead of a Trigger ID. That didn’t work either. Testing these calendar triggered events is an exercise in patience, especially with the 15 minute buffer.

alias: Kiosk Calendar Scripter
description: Activate scripts based on calendar events
trigger:
  - platform: calendar
    event: start
    entity_id: calendar.kiosk
action:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ iif(trigger.calendar_event.summary=="Test",true,false) }}"
        sequence:
          - action: script.turn_on
            target:
              entity_id: script.kiosk_test
mode: parallel

For a single-line template, inner quotes must be different from outer quotes (your template uses double-quotes everywhere).

Change it to this (the word Test is delimited by single-quotes):

value_template: "{{ iif(trigger.calendar_event.summary=='Test',true,false) }}"

or simply this:

value_template: "{{ trigger.calendar_event.summary == 'Test' }}"

Alternately, you can define it as a multiline template and dispense with outer quotes altogether.

value_template: >
  {{ trigger.calendar_event.summary == 'Test' }}

Using a choose is fine but, as you can see, it’s far more verbose than what I had suggested (templated service call). I would use a choose if each choice had multiple actions. In your case, you simply want to “steer” the automation to execute the appropriate script (simply mapping the calendar event to a script). One calendar trigger plus one templated service call is an efficient “flow”.

Ah, yes. I was just using .yaml to share on here. I configured the template in the UI using double-quotes. That’s something the template text field should catch.

But, I made the change to single quotes and it still didn’t work.

What does its trace report?

Yeah, I was just looking at it. It actually did try to activate the script (which does work separately) but nothing happened on the kiosk. I’ll troubleshoot further and let you know if I have other issues. Thanks for your help.

In that case, check the script’s trace.

The script was fine. I ended up just scrapping the automation and starting from scratch. It seems to work now. Thanks again.

How does the new automation differ from the original one you had posted above?

It’s completely flowed out now for all the triggers and nested conditions I wanted so its hard to compare, but with regards to the scripts that originally did not fire and now do work, I have no idea. Probably some errant extra space or something lame like that.

The overall flow is the requisite and generic Event start and Event end triggers with Trigger IDs > Choose… >

Event start > Choose based on templated event summaries > Run respective script (Open respective App)
or
Event end & templated event summary is one of the apps to trigger an action on event end > Run respective script (relaunch FKB)

The last little bit was a test “subroutine” that I deleted after screenshotting this trace:

This automation flow matches my logical intent and (at least to me) would be easiest to jump back in a year from now to troubleshoot. I like having separate scripts that I can call here or elsewhere explicitly without having to template everywhere it’s invoked too. I still would like to see Calendar triggers with more options (e.g. event summaries and really any field currently or in the future available in a Calendar event) but this works for now…I think :joy::rofl:

But I also may have declared victory a little too soon. Now I have a different situation that seem to be an actual bug (in the UI at least). Here is an example of the events in the Kiosk calendar from today:

image

This morning at 6:40 and 7:20 both trigger events (Event start and Event end) triggered simultaneously. I just investigated and the trigger for Event end was set to Event start in the UI. I thought “I’m positive I set that correctly” but I went ahead and made the change from Event start to Event end. Right after I moved my mouse’s focus, the UI automatically switched it back to Event start! The only way I could get it to stick was by editing in YAML. So, I’ll see tomorrow morning if it works as intended.

Side question: are you importing the nutrislice menus into a calendar or are you subscribed to a calendar that nutrislice has?

This trigger just switches to the Nutrislice app using Fully Kiosk Browser at the event’s start and then restarts HA at the event’s end.