I’m trying to set a template condition on a calendar triggered automation.
I want to perform actions only when my calendar event contains a specific word.
This is working :
condition:
- condition: template
value_template: "{{ 'WordToFind' in trigger.calendar_event.summary }}"
But this is id only matching the exact WordToFind. I’d like to match a regex which will permit more flexibility.
To be complete, in my WordToFind I’m using caracters like ‘é’ and ‘è’ but I don’t think this is the problem.
This is not working. My automation did not start anymore, and I’ve no trace.
trigger.calendar_event.summary is not available when I test this template with dev tool, so I tried with a random state value and I got it working.
I tried to put all in one row from the automation YAML editor : value_template: "{{ trigger.calendar_event.summary is search('[Ww]ord[Tt]o[Ff]ind',ignorecase=False) }}"
But this is not persistant, when I save, I’m back with the multiline “>-”
Thank you for your help. Very appreciate.
So I tried :
value_template: "{{ trigger.calendar_event.summary is search('wordtofind',ignorecase=True) }}"`
which became :
value_template: >-
{{ trigger.calendar_event.summary is search('wordtofind',ignorecase=True)
}}
as soon as I saved when I edit as YAML.
Same problem.
For now don’t mind for ‘é’ and ‘è’ but with the first example I gave it was working. So I’m pretty sure that HA is correctly configured to uses those. But, first things first…
Your template is correct in both instances. It’s 100% the word you’re trying to match.
The only other possibility is that you’re not using the correct trigger. Or you’re trying to test your condition in the UI (which you can’t do because it doesn’t have a trigger).
I’m not trying to test the condition in the UI as trigger.calendar_event.summary doesn’t exist if not launched by the calendar trigger.
So for testing purpose, I’m creating an event into the calendar I’m using.
I have open an issue related to this subject. There is something going wrong with template conditions I think. And not just in UI evaluation as it is already known (I actually do not retrieve that issue).
But this is not what would explain why I didn’t got it working if my template is correct…
Could you give it a try ?
NB: It’s not the word I search the cause. If it was, I’ll have a trace of execution of my automation sayin that the condition where false, which infortunately I’ve not…I have no trace of execution (cf. related issue).
No there isn’t. I have literally hundreds of template conditions. I use search in many places. There are issues with a few functions currently, but that’s about it.
I think I’m becoming a little bit crazy with this thing right now.
I removed any special caracter as ‘é’ or ‘è’ from my calendar event summary
I’m now using the home assistant calendar integration (just in case)
I have deleted any previous existaing automation based on calendar event.
I started over with the value_template in one single line version. And I got it working.
This morning I replaced the value_template with the multiline version which is more appropriate regarding my purpose.
This is not working anymore. Automation do not get launched anymore.
I’ve rolled back my template_value… And this is still not working.
I didn’t get what is going on.
But I still see the blue notification on my trigger when I’m editing my automation saying “launched”. And I didn’t get any trace of this execution.
what does the trace say? Are you building this in the UI? If no, then add id: to it so you can see the trace. Lets try to stop playing these games, you’re focusing on the template but the template is fine.
If you really are convinced it’s your template, move each piece into variables so you can view each trigger in the automation trace variable section.
Personally, I think you’ve spent so much time focusing in the wrong area that it’s something simple like the formatting in your automation or the calendar entity_id.