I’m trying to create an automation but hitting some brick walls. My aim is to have the automation run when a google calendar event contains ‘Red bin day’ for example, as the title.
I would then like to ‘post’ a message via MQTT that contains the calendar event title to my AWTRIX flashed clock.
You should probably change your condition to be based on the trigger variable instead of the calendar entity. The state of the calendar entity is not reliable if you ever have overlapping events in the calendar.
Having tried that the trigger happens but then the and if on the trigger calendar summary doesn’t appear to work.
I saw another one of your comments on another post saying to try the persistent notification to see if it’s passing correctly and it does. But in the automation it either fails at the and if or the then do element. I’m not sure which or if there’s a way of testing each element.
I pressed the 3 dots to test the and if but it says condition did not pass. Not sure if that’s because it’s based on a trigger that hasn’t;t technically been run thus no calendar event? Or something else?
UPDATE:
I tried looking at traces, not knowing too much about them but they showed the error “ Error: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘calendar_event’”
i changed the then do text just to “123” and that passed through to my Awtrix clock fine. So it looks like it’s something to do with passing the {{ trigger.calendar_event.summary }} into the MQTT text?
END UPDATE
I used Digeridrew’s suggested code which all works other than passing the calendar event to my awtrix clock. As per my updated commment above. Showing the error.
Turns out I just needed “ “ around {{ trigger.calendar_event.summary }}
To take this a step further I’m thinking about 2 things that hopefully one of your knowledgeable folk will be able to help with.
Instead of == can i do contains?
I have a blueprint that displays the weather, moon phase etc as an ‘app’ on the AWTRIX flashed clock which appears within the cycle of apps on the clock around 9:30pm for around 60 minutes.
I would like this message to do similar. As opposed to just currently display for 150 seconds. I’d like it to rotate in / out of the display for 1-2 hours. As it’s not always guaranteed I’ll be near my clock. Hope that makes sense
Thank you for this. I do code (web stuff so html/ xsl / css/ less etc) for my job but never yaml so didn’t think a simple contains would be the answer! What language code is this similar too?
The blueprint, I hadn’t realised has it’s own automation yaml code with it, it’s quite extensive so not sure the best way to share /even if you have time to explore (‘just let me know obviously absolutely fine but would rather not be hanging on haha). It is this blueprint.
As complex as that looks, the actual automation part of it is relatively straight-forward. All it should take to add your action is to use the “Take control” option from the 3-dot/expansion menu at the top right when editing the automation. This will convert the blueprint-linked automation into a stand-alone automation and you can add your MQTT publish action.
But, since you will not be relying on the Calendar trigger, you will need to decide how you want to store the payload data for the Weather, Moon automation to retrieve it. If the json string of payload will always be less than 255 characters you can store it in an Input text helper… just add an input_text.set_value action to your existing automation:
Here’s hoping you might get a ping. I’ve had it running for a while now and it’s great
Update time … I’m thinking it’s be even better if it could collect all my calendar events for the day and display them. No matter the time it starts or the name etc. any idea if that’s possible. I couldn’t fathom it out over the past few days.
Can you expand on the idea, it’s not clear to me exactly how you’re visualizing it should work.
For example, should it still trigger 30 minutes before the start of the calendar events, but cycle through the days remaining events instead of just showing the upcoming one? That’s seems do-able. I don’t have an Awtrix, so I’m not 100% versed in how it handles the flow of what it displays, but I’m sure we could figure it out… it just might take some experimenting.
so i think in terms of Awtrix so long as i can gather the data i can display near enough what ever I want. Below is a copy of my current yaml for the automation. The triggers being;
every 20 minutes
15 mins before a calendar event albeit full day events are taking over
HA restarts
essentially at the start of everyday i would like HA to ‘collect’ the days calendar event summary’s into a single variable which then Awtrix via the automation (every 20 minutes) would display them.
I’m still having problem automating mine. Would you be able to help? Below is my code with the calendar entity. Today is a Day Shift and below automation is for Night Shift
Looking the trace, it looks like the trigger and condition are skipped so the automation is passed, which is incorrect.
So I ran manually to check if the automation works or not, since when I test only the condition in the automation page, it never gives me pass/fail result.
However is the syntax correct? Reason I ask is because it didn’t trigger my “Day Shift” automation that has similar syntax with this one, and the condition is “Day Shift” instead of “Night Shift”.
Previously I used a separate calendar entity for Day and Night shift that just turns “on” and “off”. I want to simplify my calendar and to use the calendar title to run the automation, however it hasn’t worked well for me.
Yes, the syntax is fine. The condition can’t accurately be tested within the Automation editor because it relies on the trigger variable, which isn’t populated until the actual trigger fires.
One thing to keep in mind is that == is literal… so your titles like Night Shift (Day 1/2) would cause the condition to fail. If you will be using a variety of titles, you need to use either a more specific regex find function or the search() function like:
{{ trigger.calendar_event.summary is search('Night Shift') }}
Thanks mate. I’ll see if the automation will trigger tomorrow and report. Previously I used my email address as the calendar entity, not Christina calendar entity.
And thanks for the regex function. Will update them accordingly.
Hi again mate, upon testing, the code works fine for a one day event. If the event is longer than 1 day, the boolean is turned off by the offset. for this case it turns off after 16 hours.
Do I just have to change the Event to Event end and put 3 hh Before from the visual editor?