The Vera Community forums have moved!

Advanced => Plugins & Plugin Development => Programming => Google Calendar Switch => Topic started by: rjfcowdery on December 21, 2017, 10:18:55 am

Title: iCal Events Spanning Multiple Days
Post by: rjfcowdery on December 21, 2017, 10:18:55 am
Looking to see if events lasting multiple days are supported via iCal.    We have a vacation property which is scheduled via AirBnB and I am using GCal to prep the condo before arrival,  shut off services upon departure and  ensure the housekeeper has been there before the next person arrives.  I get the calendar from AirBnB into my Google calendar but it is all in iCal format.  People stay 2-7 days generally so I need the  GCal to recognize an event that started up to a week earlier.  Note that I am triggering on ALL events coming from the AirBnB calendar except those with "PENDING" as these are usually last minute unconfirmed bookings that disappear (or stop being pending) within 4-6hrs.

My problem is that it triggers correctly upon the event starting - but the event ends at midnight of the 1st day.  Looking at the log file it seems that the parser only looks for events starting at 00:00 of the current day.  I have included the log file, settings and a snapshot of the Google Calendar from the time period.   

Since I am getting the events from AirBnB automatically I am not able to change the formatting of the events to multiple single day events etc.    Any ideas or work-arounds would be appreciated!!!

Rob
Title: Re: iCal Events Spanning Multiple Days
Post by: Stuart on December 22, 2017, 09:27:29 pm
Take a look at the advanced documentation gc_retrip.  That may be what you want.

The problem with ical is that it can be implemented in manny ways -- it's one of those standards with too many options ...  :-(

From the logs (and the screen shots) it looks like these multi-day events are being treated as one long event.
Title: Re: iCal Events Spanning Multiple Days
Post by: rjfcowdery on December 23, 2017, 10:14:30 am
Thanks - Will try it with gc_retrip set back to true.  Will know in a few days if that changes the issue.  The events are all multi-day, all-day events coming from the Airbnb site so can't change the event records to single day ones. 
Title: Re: iCal Events Spanning Multiple Days
Post by: Stuart on December 23, 2017, 02:49:19 pm
Also -- not sure if this is what you are expecting but when you specify an event like this: "your event name [780,660]"
You are saying that you want it to trigger 780 minutes after the time you have in the calendar and finish 660 minutes after the time you have it ending in the calendar.  Positive is forward in time, negative is backward.

Unfortunately - I am on vacation and cannot look closely at this for a couple of weeks.  I'd recommend that you put the start and end delta to zero - convince yourself that it's working (or not) and then use the delta's.
Title: Re: iCal Events Spanning Multiple Days
Post by: rjfcowdery on December 23, 2017, 11:13:03 pm
Regarding the start/end delay....  The events comming from AirBnB are all-day events starting at midnight 00:00 before the check-in day then ending at midnight 00:00 of the night before checking out.  The delays cause the check-in actions to happen at 13:00 and checkout actions at 11:00 . The check-in (start) delay works fine but checkout (end) delay doesn't work as the event seems to mistakenly end at midnight of the first day.  I can use delayed actions in my scenes if necessary in place of the GCal delays. 

Have a good vacation. No hurry -  I am still experimenting with ways to automate the rentals.
Best Wishes for the Xmas Season

Rob
Title: Re: iCal Events Spanning Multiple Days
Post by: rjfcowdery on January 27, 2018, 01:32:28 pm
I eliminated the delays on the GCal trips but the trip for the ending of the event still happens  at midnight of the 1st day of the multi-day event.  Any other tests or diagnostics logs I can do to help figure this out?
Title: Re: iCal Events Spanning Multiple Days
Post by: Stuart on January 29, 2018, 03:42:51 pm
I can take a look and figure it out.  Lets see what your current logs look like.  I'm guessing it has to do with the way the events are being translated from ical to google cal.
Title: Re: iCal Events Spanning Multiple Days
Post by: rjfcowdery on February 07, 2018, 02:04:57 pm
Here is latest log with matching screen shots of the GCal settings (back to 0 delays) and the Google Calendar that it is scanning.  Hope this helps.   

Thanks
Rob
Title: Re: iCal Events Spanning Multiple Days
Post by: Stuart on February 08, 2018, 12:25:55 am
Hi --
A couple of things

I notice that you have gc_keyword set to PENDING  yet there are no calendar entries with that WORD in the title.  So basically - nothing should be happening :-( . and as far as I can see in the logs -- it's dutifully not doing anything :-)

So it does not look like the logs are capturing the behavior you reported earlier?

I have set up a test calendar and am seeing an odd behavior (likely because google changed their ical format) so will dig a little deeper today.

Three things that you can try (1) use the standard google url for the calendar (versus the ical url) as this will generally be more reliable.
(2) use the url directly to the source calendar site (may not be able to do because of login requirements)
(3) past the google ical url into your browser -- it should download the ical file -- send that to me as well (and I can see what the formatting looks like)

One of the problems with iCal is that there are many ways the developer that created the ical file can represent events -- so you cannot guarantee that a given parser (like my code) will work with all variations that are possible.

Title: Re: iCal Events Spanning Multiple Days
Post by: Stuart on February 08, 2018, 11:02:56 pm
As I suspected --  there has been a change to the way google is creating iCal files for repeating events.  This could have been a long time ago since the iCal support was not intended to be used with google calendars.

There is no reason to use the ical url from google calendar (for GCAL).  Please use the Calendar ID that google provides and lets take it from there.  That does not mean that the google import from AirBnB is working correctly -- but we shall see .....
Title: Re: iCal Events Spanning Multiple Days
Post by: rjfcowdery on February 09, 2018, 11:12:25 am
I was triggering on all events except the PENDING ones as these were not confirmed bookings and would dissappear or become real booking within hours. Rarely saw them but did get a few falsely triggering before adding the PENDING.   I'll try the Google calendar method again - I did try this to start with but couldn't get it working., but too be truthful I really didn't spend a lot of time.

Thanks for the ideas.  I'll try them and let you know how it goes.
Title: Re: iCal Events Spanning Multiple Days
Post by: rjfcowdery on February 15, 2018, 11:47:17 am
Using the Google calendar link instead of the ical is working - sort of!  The triggers for start an end happen on the correct days now , but the start/ end delays seem to be ignored. So the start/ end of the events are happening at midnight instead of 2pm/11am. I can manage this with timers & delayed scene actions.  Is there anything I should try?. 
Title: Re: iCal Events Spanning Multiple Days
Post by: Stuart on February 15, 2018, 11:56:27 am
Using the Google calendar link instead of the ical is working - sort of!  The triggers for start an end happen on the correct days now , but the start/ end delays seem to be ignored. So the start/ end of the events are happening at midnight instead of 2pm/11am. I can manage this with timers & delayed scene actions.  Is there anything I should try?.

Please send a log.  I need to see exactly how you have it set up.

Also - re-reading your earlier posts, it's not clear exactly what you are trying to achieve.  Do you have two different type of events in the calendar (1) a checkin / start of occupancy and (2) a checkout / end of occupancy.  If so - it's likely that you need two instances of GCAL with different start / end deltas for the two different types of event.
Title: Re: iCal Events Spanning Multiple Days
Post by: rjfcowdery on February 15, 2018, 03:04:48 pm
I have attached the logs (probably mostly the same - I did a getlog just before downloading #2)

So here is what I am trying to do.  We get the calendar data from our AirBnB listing automatically into my google calendar. Each event is a single reservation that may span multiple days.  Events from AirBnB start at midnight of the  night before checkin (00:00 of the night before 4:00PM checkin)  and end at midnight of the night before checkout (00:00 of the night before 11:00AM checkout).  For example a person checking in Feb 1@4:00 and leaving Feb3@11:00 will show up as all day events starting 00:00:01 Feb 1  - ending 00:00:01 Feb 3 (note that the calendar doesn't include the 01 seconds part but it makes the timing clearer for this explanation!!)

A few hours before checkin I set the thermostat, turn on the water, and check that the cleaner has been in the unit.  A few hours after checkout I turn the thermostat down and water off (its a bit more complex that that but this is the jist).

I have tried restarting Vera/Luup to ensure the system isn't confused.   I haven't yet created a new GCal3 device for this - just reused the one I had setup earlier that was using the iCal method and changed the calendar ID/credentials and reset the start/end delays and extra days settings.   
Title: Re: iCal Events Spanning Multiple Days
Post by: Stuart on February 15, 2018, 04:06:29 pm
Both these log files show that there are errors reading from google calendar (http error 403).  It may be that the calendar sharing permissions are not set correctly.

The net effect is that GCAL is trying to work from a copy of the calendar that it obtained some time previously -- likely when it was using ical.  It's an offline mode that is designed to help when there are network issues.    You can tell if it's in offline mode when the event name is preceded by an asterisk.
Title: Re: iCal Events Spanning Multiple Days
Post by: rjfcowdery on February 15, 2018, 05:47:43 pm
The calendar permissions was the one area I wasn't able to follow your instructions.  Perhaps because the calendar source (AirBnB) is a read-only I don't get option to permit specific users or rights to my calendar.  I noticed the http error but it seemed to function after it did a few retries.  I see from your explanation why that would happen.   I'll need to get to a real computer to get screen shots showing the problem with Google Calendar permissions.  Thanks for the help!!
Title: Re: iCal Events Spanning Multiple Days
Post by: Stuart on February 15, 2018, 06:05:12 pm
Here's the thing.  Your source calendar is AirBnB BUT you are effectively re-implementing it in google calendar.  GCAL wants to read your google calendar (i.e. it's not really reading AirBnB directly).   Therefore the permission setting are all about the google calendar settings.

For the google calendar that represents your AirBnB calendar -- you need to have "Share with specific people" identify your service account AND allow it to at least "Make Changes to events"

I know all this sounds a bit convoluted -- but it's a by product of google keeping unauthorized eyes off your calendar :-)
Title: Re: iCal Events Spanning Multiple Days
Post by: rjfcowdery on February 15, 2018, 06:45:52 pm
This is the screen I get for setting permissions.  For my personal calendar(s) I am able to set permissions for specific people as your instructions describe, but for this one it is not an option.  Only difference is that I created the calendar "From URL"  instead of the "New Calendar".   It looks like I can create a personal calendar and import the AirBnB  into it as seperate editable events (which should then work as you described)- but it looks like I would need to do the import routinely to keep it up to date.  Will explore if the original airBnB ical source works any better.
Title: Re: iCal Events Spanning Multiple Days
Post by: rjfcowdery on February 16, 2018, 09:11:59 pm
Tried direct link to the AirBnB calendar vi iCal but results are the same as accessing the Google Calendar version via iCal.
Title: Re: iCal Events Spanning Multiple Days
Post by: rjfcowdery on February 18, 2018, 01:26:45 pm
Here are the ics files (listings... is the one direct from airbnb,  basics...  is the one from google)

Title: Re: iCal Events Spanning Multiple Days
Post by: rjfcowdery on April 02, 2018, 06:29:10 pm
Managed to make the GCal app work as I needed for iCal calendars with events spanning multiple days - but needed to make a minor change in your GCal3.lua.   My problem was that the calendar events may have started a few days ago - even though they were still active now.  The calendar data being requested seemed to request events starting just before midnight on the current day though to several days in the future (depending on ExtraDays).  I needed the calendar data request to look for events starting several days in the past.  Hence I added the "ExtraDays"  value into the starttime variable as shown in red below.   I will leave it to you to decide if this hack may cause other issues,  but it seems to make everything work for me and I haven't seen any side effects yet!!

in the GetStartMinMax function...

-- look back 5 minutes to make sure we catch midnight events with the calendar lookup  ......and ExtraDays before today to catch events starting earlier but still active
  starttime = starttime - (60*5)- (3600*24*GC.ExtraDays)
Title: Re: iCal Events Spanning Multiple Days
Post by: Stuart on May 01, 2018, 10:10:49 am
Managed to make the GCal app work as I needed for iCal calendars with events spanning multiple days - but needed to make a minor change in your GCal3.lua.   My problem was that the calendar events may have started a few days ago - even though they were still active now.  The calendar data being requested seemed to request events starting just before midnight on the current day though to several days in the future (depending on ExtraDays).  I needed the calendar data request to look for events starting several days in the past.  Hence I added the "ExtraDays"  value into the starttime variable as shown in red below.   I will leave it to you to decide if this hack may cause other issues,  but it seems to make everything work for me and I haven't seen any side effects yet!!

in the GetStartMinMax function...

-- look back 5 minutes to make sure we catch midnight events with the calendar lookup  ......and ExtraDays before today to catch events starting earlier but still active
  starttime = starttime - (60*5)- (3600*24*GC.ExtraDays)


Thanks -- just getting some time to look at this.
I've tried to be considerate of the limited resources on the vera by only loading into memory the needed information.  So am a little reticent to arbitrarily expand the "capture" dates.

It's (events spanning midnight) have not been a problem before with regular google calendars - hence looking back 5 min from midnight  (I was unable to make it fail recently).    I suspect there is something to do with the ical format / structure that is causing it to not see the current event in these conditions -- I'll take a look.  Maybe I end up just expanding for iCal -- don't know .....