Page 1 of 1

Calendar Event trigger logic

Posted: 27 Apr 2015 07:31
by Wibbly
Is there a way to make this deal with overlapping events? At the moment it triggers at the end of event even when another event is still in progress (in parallel).

It would be good to have an option to 'merge' events as far as the trigger is concerned, so overlapping events appear to the trigger as one big event. Or, alternatively, to have a condition for 'Event in progress' so I could prevent an 'end of event action' taking place if the trigger fires when there is another overlapping event still in progress (in the same or another calendar). Or have a new variable as part of the calendar event trigger which was the total number of event's "active" at the time of the trigger...

------
Example use case

- I'm out with friends from 1pm to 8pm and set an event for that.
- We go to the cinema from 2pm to 4pm, and I've received and accepted an event invite for that too.

I have a flow for setting my phone to Priority interruptions whilst I'm busy, and return to All interruptions after.

As it stands, the end of event trigger fires at the end of the film at 4pm and my phone goes to All interruptions whilst I'm still busy with my friends
------

I guess an alternative would be to use a global variable to count (increment/decrement) the current number of concurrent events based on individual event starts and event ends triggers. And then a flow to test when it's >0 or 0? Seems a bit kludgy though, and prone to error if events are added or removed during the event duration. :-(

Re: Calendar Event trigger logic

Posted: 27 Apr 2015 19:47
by Martin
You could use a condition Calendar Event to check if there are still matching events when one event ends. The condition also provides variables with the end time of the event so you could also check how long the event still lasts.
Action Query Content Provider can also be used to work directly with the calendar provider and read all currently active events into a list and process the list with a script. The action contains an example All current calendar events to read the titles of all events into a list. Query Content Provider requires knowledge about some internals of the calendar provider so it's not very comfirtable to work with. Here's a starting point: http://developer.android.com/guide/topi ... vider.html

Regards,
Martin

Re: Calendar Event trigger logic

Posted: 28 Apr 2015 10:35
by Wibbly
Thanks. Will look at those options.

Re: Calendar Event trigger logic

Posted: 29 Apr 2015 10:45
by Wibbly
Martin wrote:You could use a condition Calendar Event to check if there are still matching events when one event ends. The condition also provides variables with the end time of the event so you could also check how long the event still lasts.
I'm struggling to understand how the offsets work (Start and End, Before and After). Do I need to set these to anything other than 0 to ensure there's no race condition if one event ends at the same time as another starts when a flow with the Calendar Event condition is triggered with the Calendar Event trigger? What I'm trying to achieve is to make sure the condition returns TRUE in that case (i.e. there's still an event active). I also want to make sure the condition returns FALSE is there are two concurrent events that finish at the same time...

If I do need to set them to other than zero (to a few seconds?), how should they be set (Start and End, Before and After)?

Re: Calendar Event trigger logic

Posted: 30 Apr 2015 19:27
by Martin
If you want to test whether an event is active at the time the flow is executed, you can set the starting/ending offsets to 0s. When you execute the flow at the time when one event ends, the condition should not detect this triggering event anymore. To be absolutely sure, you could also use a trigger Celandar Event: XYZ (1m after end) to execute the flow one minute after the event has ended. Using an action Sleep: 10s within the flow should also work.
Concurrent events ending at the same time should not be a problem. When one event ends a few minutes earlier, the condition would still return true for the first event since event 2 is still ongoing. The condition will return false when the flow is executed for the second event since event 1 is already over since a few minutes.

Re: Calendar Event trigger logic

Posted: 01 May 2015 07:40
by Wibbly
Thanks (again) Martin