Hi, how can I make an automation that would fire off when a certain calendar event comes up?
Goal: have my “Cleaning” script (that disables automatic vacuuming, auto lights in bathroom/WC…) when we have a cleaning lady over. That is marked as “Cleaning” in a calendar that is already integrated in HA.
I have read documentation about calendar triggers but that doesn’t seem to do what I need (I cannot specify an event name). I am not even sure what the Calendar Trigger actually does - trigger whenever there’s ANY event?
Any tips? Thanks!
1 Like
Kind of… it will trigger at the start or end (whichever you select) of every event in that calendar. You then use conditions to limit/route/modify the action sequence.
automation:
- trigger:
- platform: calendar
event: start
entity_id: calendar.x
condition:
- "{{ trigger.calendar_event.summary == 'Cleaning' }}"
action:
- service: script.cleaning
data: {}
Doesn’t trigger though… this is the automation:
alias: Calendar Uklid triggers Cleaning Mode
description: ""
trigger:
- platform: calendar
event: start
offset: "0:0:0"
entity_id: calendar.rodina
condition:
- "{{ trigger.calendar_event.summary == 'úklid' }}"
action:
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.cleaning_mode
mode: single
Seems to not work with unicode (or accents) in event names. It works when the event name and the condition is “cleaning”, but not with my native Czech “úklid”… A bug to report maybe?
I have a different but related question. I have my Google calendar integrated in HA and I have numerous Automations that use, as Trigger or as Conditions, whole day events in specific sub-calendars that I created in the Google Calendar.
However I am not able to use time based Events (like ‘pick up grand kid’ at 3 pm) . These events show in the Calendar Card in one of my Overview tabs, but no Entity exist for such time based Events.
Don’t hijack someone else’s topic. Start your own.
I respect your concern but I think that it is actually useful to ask my question here. We can of course respectfully disagree.
2 Likes
It wouldn’t hurt to report it.
As a work-around you could try something like:
{{ trigger.calendar_event.summary | slugify == 'uklid' }}
1 Like
- Don’t divert a topic by changing it midstream.
https://community.home-assistant.io/guidelines
This is simple netiquette.
that didn’t trigger either… thanks anyway
I can’t reproduce your issue on my instance. I’m getting normal triggers with calendar events with a variety of accents and diacritics.
Run a test with the following so you can see exactly what the template is returning:
alias: Test Calendar with accents
description: ""
trigger:
- platform: calendar
event: start
offset: "0:0:0"
entity_id: calendar.rodina
condition: []
action:
- service: persistent_notification.create
data:
message: "{{ trigger.calendar_event.summary }}"
mode: single
When testing calendar event triggers make sure you follow the proper protocol so that the calendar is loaded before the trigger should fire. Calendars are normally only reloaded every 15 minutes, but they are also reloaded when an automation with a calendar trigger is reloaded. So you can either schedule your test event for more than 15 minutes in the future or reload your automation after the test event is created.
It’s probably the Google Calendar integration that updates seemingly whenever it damn chooses to. There are events I have deleted from it 20 minutes ago and it’s still not synced with HA.
Then again, even if I create the event inside HA and manually reloaded your test automation, it didn’t trigger anyway. Calendar entity is correct.
Manually triggering the automation reveals this in Traces:
Stopped because an error was encountered at 20. června 2023 v 22:13:40 (runtime: 0.02 seconds)
Error rendering data template: UndefinedError: 'dict object' has no attribute 'calendar_event'
Yeah, you cannot test automations that rely on calendar event triggers or other trigger variables using the “Run Automation” button or automation.trigger
service because those methods don’t create/populate the trigger
variable.
Okay the testing automation trigger fine, the event names are being passed correctly
What I ultimately want is a condition that would trigger with any variant such as “uklid”, “úklid” or “úklid #CLEANING LADY NAME#” so it’s actually helpful without requiring us to be super diligent with the event name.
Thanks for your help!
In that case you should combine the slugify
filter from my previous post with a search()
function… slugify
should strip the accents and and upper case letters making it so you only need a single search term to cover the variations.
alias: Calendar Uklid triggers Cleaning Mode
description: ""
trigger:
- platform: calendar
event: start
offset: "0:0:0"
entity_id: calendar.rodina
condition:
- condition: template
value_template: '{{ trigger.calendar_event.summary | slugify is search("uklid") }}'
action:
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.cleaning_mode
mode: single
2 Likes
Perfect! Works and I can use this as a blueprint of sorts for other automations. Thank you
Is it possible to get this in Visual Editor ?
1 Like
Yes, it’s just very annoying and inefficient to take and share 5 screen shots compared to using copy/paste once.
If you need one, there is a slightly dated but still informative video primer on translating between YAML and UI editor available on the ResinChem Tech Youtube channel.