I’ve found this thread very useful in my attempts to trigger a node-RED flow from calendars. I was using the ical sensor method but this trigger template might hold more promise now that calendars are more tightly integrated with the core.
Here is my current (experimental) template code, which defines a sensor whose state is the ‘name’ of the next calendar event, and which has attributes defining the calendar entry. The ‘start’ attribute indicates whether it’s triggered by the start - offset of the event (true) or the end of the event (false).
The id and idx attributes seem to come through as 0 for start and 1 for end. Probably some redundancy here.
I use node-RED for all but the most trivial automations and this state change is easily picked up with a state_changed node. The payload is the ‘name’ of the calendar entry and the data object contains the listed attributes.
Thanks for this great example. I tried to follow the instructions, but it is not working, the newly created template sensor is not receiving any input. What am I missing?
@riko Something to watch out for is a foible of either Google calendars or the integration (I’m not sure which exactly) whereby a calendar event needs to be assigned a new identity in order to trigger.
If you move an event to a new date and/or time it seems that it is not given a new ID. Unfortunate really, as this is what I did in testing and you may be doing as well. Instead, I found that I needed to duplicate an event and give a fresh date/time or create a new event from scratch. Either case results in a new event ID which will then trigger. Of course, you can’t re-use that event and you need to duplicate again for the next test.
I think that might suggest that the state of the sensor is not changing rather than the trigger not detecting a change in state. So your automation is probably OK and my advice would be to go over each step of the calendar API setup again in case it’s an authentication issue with your Google account. Maybe the callback URI is wrong.
This solution from @CentralCommand looks sweet. I imported and am using it without a hitch. I like that I can work things out in Node-RED and javascript. Although I guess it means handling a lot of timing issues, vs using the template code from @hunterdrayman. More experiments will tell. But thanks both for sharing, it will save me lots of time.