Searching for string in results from calendar.get_events

I want to trigger different events on if a list of events for the day contain certain strings. I have managed to use the calendar.get_events and filter to get a list of events for the day. So far I have not been able to come up with a conditional statement that will give me a true when checking for a string. When looking at the trace from the automation, I get to this and can’t ever get it to give me a result as true.

The automation has this code:

trigger:
  - platform: time
    at: "06:45:00"
condition: []
action:
  - service: calendar.get_events
    data:
      duration:
        hours: 72
        minutes: 0
        seconds: 0
    response_variable: cal_events
    target:
      entity_id:
        - calendar.fms_events_calendar
  - if:
      - condition: template
        value_template: |-
          false
          {% for key, value in cal_events.items() %}
            {% for event in value.events %}
              {% if 'FMS' in states(event.summary) %}
                true
              {% endif %}
           {% endfor %}
          {% endfor %} 
    then:


{% set fms = namespace(event=false) %}
{%- for key, value in cal_events.items() if fms.event is false %}
  {%- for event in value.events if fms.event is false and 'FMS' in event.summary%}
    {%- set fms.event = true %}
  {%- endfor -%}
{%- endfor %}
{{- fms.event }}

Though, if you will need the filtered events for some purpose later in the automation, it would likely be better to extract them into a variable to avoid having to render the same thing multiple times.

Thank You, It looks like it is working. I can now get it to return true or false, depending upon my inputs.

Hi, please take the time to mark the answer as solution, you do that by selecting the three dots under the post:

image

Then select the check box:

image

By doing so this can be useful to other users as well and prevents that someone else steps in and still tries to help you.