Automation with a specific word in subject / regex-search failed

Hello everyone,

I would like to create an automation that only starts with a calendar entry that has a certain word in the subject of the event.

For example, the automation should only start if the event contains the word “test12”.

i.e. “Birthday of test12” => OK/True
i.e. “Birthday of test13” => NOK/false

Currently the condition is ALWAYS false.
Anyone an idea?

alias: my automation
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "0:0:0"
    entity_id: calendar.cal1
condition:
  - condition: template
    value_template: >-
      {% set events = state_attr('calendar.cal1', 'all_events') %} {% set
      found = false %} {% if events %}
        {% for event in events %}
          {% if event.message | regex_search('test12', ignorecase=True) %}
            {% set found = true %}
          {% endif %}
        {% endfor %}
      {% endif %} {{ found }}
action:
  - 
mode: single
  • trigger.calendar_event.summary represents the calendar event’s title.
  • trigger.calendar_event.description represents the calendar event’s description (if any).

For more information, refer to Trigger Variables - Calendar.


The following example uses a Template Condition to check if the string test12 exists in the calendar event’s title.

alias: my automation
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "0:0:0"
    entity_id: calendar.cal1
condition:
  - condition: template
    value_template: "{{ 'test12' in trigger.calendar_event.summary }}"
action:
  - 
mode: single
1 Like

So many thanks. Works like charm.

1 Like

Just for education, your method wouldn’t work because the found variable inside the for loop isn’t the same as the one on the outside.

You would have needed to use a namespace to get that to work:

https://jinja.palletsprojects.com/en/latest/templates/#assignments