Capture Text from string

I currently have an automation that triggers when a gmail Event begins. What i need to do is based off the values in Data point #1 and Data Point #2 make a decision and turn on some lights and other appliances. The goal is to turn only those lights on in the rooms which are going to be occupied and disable the motion sensors in those same rooms which would normally turn the lights back off if no person is detected.

The trigger is:

platform: calendar
event: begin
offset: “0:0:00”
entity_id: calendar.xxxxxx_gmail_com

The Event names will be pretty dynamic but do have some rules around them such as:
Data Point 1 - Data Point 2 - freeform Text - freeform Text

Some close to real examples are:
Aud A - Room1 - Name - Event Message Name
Aud A - Room2 - Name - Event Message Name
Aud B - Room1 - Name - Event Message Name
Aud B - Room2 - Name - Event Message Name

To give a real world look here is what we could experience.
Aud A - Living Room - Name - Event Message Name
Aud A - Sala de estar - Name - Event Message Name
Aud A - Auditorium - Name - Event Message Name
Aud A - Auditorio - Name - Event Message Name

In the first example, Aud A - Room1 - Name - Event Message Name, it should turn on the lights on the Auditorium A in Room 1 while leaving the other 3 areas alone. This same logic holds true for the other areas as well.

When I first setup the automatons I was just looking to see if the words existed in the Event name.

What I used to do that was simple like this as a condition in the automation.
{{ "Aud A - " in trigger.calendar_event.summary }}
AND
{{ "Room1 - " in trigger.calendar_event.summary }}

What I learned is that in the free form text areas at the end, those words can exist which caused my logic to over trigger. It should be noted that the variable part I’m calling Room 1 can be of varied lengths depending on if they entered the Event Name in Spanish.

So i need to be a little more precise here and that is where I’m getting stuck.

  1. I need to extract the first the first part of the Event name in a condition (Aud A -)
  2. Then i need to extract the second part of the Event name in a second condition (Room1)
  3. Then ignore the entire rest of the Event name.

Having those extractable as mentioned would also allow me to store them temporarily in a string helper.

As I mentioned I’ve tried the contains template
{{ "Aud A - " in trigger.calendar_event.summary }}

I’ve tried to capture the first # characters similar to this
{{ trigger.calendar_event.summary[:9] }}

Can someone please help me figure this one out? I know the logic has to be simple but it is escaping me.

Please see the very first post that tells how to make a useful post to get help.

How to help us help you - or How to ask a good question - Configuration - Home Assistant Community (home-assistant.io)

From your posted examples I’m assuming that a calendar event holds only one data string like Aud A - Sala de estar - Name - Event Message Name, not multiple. If that is the case, you can use the split method on your string to turn it into a list, then use list index numbers to assign the values of the desired list items to variables for use in you conditions.

trigger:
  - platform: calendar
    event: begin
    offset: “0:0:00”
    entity_id: calendar.xxxxxx_gmail_com
    variables:
      aud: "{{ (trigger.calendar_event.summary).split(' - ')[0] }}"
      room: "{{ (trigger.calendar_event.summary).split(' - ')[1] }}"
condition: []
action:
.... 

With the above your condition templates would be along the lines of:

{{ aud == 'Aud A' }}

{{ room == 'Sala de estar' }}

You can use Developer Tools / Template to experiment. For example:

{% set x = ["Aud A - Living Room - Name - Event Message Name",
            "Aud A - Sala de estar - Name - Event Message Name",
            "Aud A - Auditorium - Name - Event Message Name",
            "Aud A - Auditorio - Name - Event Message Name"] %}
{% for i in x -%}
  Auditorium: {{ i.split(" - ")[0] }} / Room: {{ i.split(" - ")[1] }}
{% endfor %}

Thank you @Didgeridrew & @Troon , exactly what i was trying for.