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.
- I need to extract the first the first part of the Event name in a condition (Aud A -)
- Then i need to extract the second part of the Event name in a second condition (Room1)
- 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.