I think what i am trying to do is pretty simple however I’ve not been able to achieve what I am looking for and hopefully someone can help me figuring out what I am doing wrong.
what I want to achieve is to execute an action to simply turn on an input boolean based on if there is a specific all day entry in the calendar for tomorrow 6 hours before that all day event which should start at 12AM, so this mean I want this automation to run at 6PM the day before.
here is what I have, but what happen when I execute it is that the boolean switch to on even if there’s no such entry in the calendar for tomorrow.
I have replaced my automation with the code you send and replaced calendar.test with calendar.family and tested the automation but it seem to have the same result, i do not have the ‘Ped day’ event tomorrow and the boolean was turned on by the automation.
Allright, I did not know that manually triggering an automation would skip the conditions and execute the action. I will test it out by adding an event for tomorrow and see if it execute properly tonight and I will let you know the result.
You can test it today by setting the time to something earlier than 18:00:00. Or you can use Developer Tools > Services, select the automation.trigger service and your automation, and turn off the “Skip conditions” option.
Thank you for the reference. I have created an event for tomorrow (all_day) as well as Friday the 23rd and went to the developer tool to test the template variables
Not a criticism of your response, more a comment on the state of the calendar integration. Checking to see if the next event is the all-day event in question is not the correct logic. This will fail if I have something in the calendar for later tonight.
I would love to see the calendar integration augmented to allow for these types of automations. the typical pattern here is fire the automation if I have an all-day event today+/-offset called ‘xyz’.
The only visibility the template has is the calendar entity’s state and its attributes. The attributes contain information for the next scheduled event and nothing else.
In your case, the next scheduled event is today. Therefore a template can only see information about that event, not anything else scheduled in the future (like tomorrow’s all-day event or any other events you may have scheduled for tomorrow or in the future).
Once today’s events have passed, the calendar entity’s attributes will contain information about whatever it considers to be the next scheduled event which is likely to be tomorrow’s All Day event. Unfortunately, for your application, that’ll probably be too late (you want 6 hours advanced notice).
Another quirk (reported as an Issue in the GitHub Core repository) is that once you have an All Day event scheduled, any other events scheduled that day will never appear in the calendar entity’s attributes (the All Day event effectively suppresses the display of other events that day). The other events scheduled that day will still serve to trigger a Calendar Trigger but they won’t appear in the attributes.
All this to say that using the calendar entity’s attributes for making decisions has a very narrow window of usefulness and my suggestion doesn’t work for your application. In fact, the developer responsible for Local Calendar recommended not to use State Conditions based on the calendar entity’s attributes. His suggestion was to reference the trigger variable generated when the Calendar Trigger fires.
You’re absolutely correct. As mentioned in my previous post, the additional complication is that an All Day event becomes the only event displayed in the calendar entity’s attributes (i.e. any other scheduled events that day are never displayed). This makes using the entity’s attributes an unreliable means of checking information about the next scheduled event.
In another topic in the community forum, the author of Local Calendar recommended to reference the trigger variable as the best means of getting information about the event that just triggered the Calendar Trigger. I’m beginning to realize the wisdom of that advice owing to the way the calendar entity’s attributes aren’t guaranteed to accurately report information about the next scheduled event.
Ok, thank you for the suggestion. I will have a look. It is too bad that we cannot do something like that as of yet because this type of automations would definitely be really beneficial. one thing that i could have a look at is to use something external, perhaps ifttt.
Today I tested an automation very similar to the latest example I posted above (employing an offset Calendar Trigger and a Template Condition that checks trigger.calendar_event).
It was set to report an All Day event scheduled tomorrow. It was offset for 11 and 2 hours prior to the event. It was successful and notified me at 13:00 and 22:00.
Thank you, I have created a new automation with the above and will check at 6PM tonight if it flips the boolean.
I also checked ifttt yesterday but I didnt find much integration with the ios calendar (as opposed to gcal). There’s the app integration, but I would need a mac for that I think. I just scratched the surface, I didnt investigated deeply.
Finger crossed for the above code and thanks again for spending time on my problem.
Just want to update that it seem to have worked. Both of the conditions matched my all_day calendar entry. I also tested with no all_day event matching this condition and it skipped the test. it didnt even run which I think its expected.