Did you ever make the new repository? Where is the best place to get the latest scripts? Thanks.
Yes I started a new repository but for a huge lack of time I couldn‘t finish the documentation. Let me have a look this weekend …
Everythin looks fine now and you can grab the latest scripts from GitHub - FrankR59/CalSyncHAB: Synchronization Of Google Calendar Events With OpenHAB Items From Multiple Calendars
If you only need openhab rules you will find them within them ‘samples’ folder.
The latest change to ExecCal rule has been done a few weeks ago. You may now use the ‘location’ field of your google calendar events as a condition for updating your items. The given condition will be checked before updating your item. No action will take place if the condition is false. I am using my presense detection switch (named: ‘aPersonIsPresent’) to stop my shades from moving every morning if nobody is at home. A condition has to contain the name of an openhab-item, a relational operator and a value to be compared with. All these have to be sperated by a space. Example: ‘aPersonIsPresent == ON’. Actually relational operators can only be ‘==’ (equals) and ‘!=’ (unequal). If you need more complex conditions you should write your own rules which set switch items to ON or OFF if your condition is true or false. These switch items can later be used for the condition here. Condition must not be used.
Thanks for that. I have it working. I did notice that my Ubuntu 18.04 whined about using python2, so I switched the shell script to use python3. And then it didn’t like the oauth2client saying it is deprecated (see the README.md) when I installed it. So then I tried using the google-auth. Also, I had earlier set up a service account for this, so I used it instead instead of the web login. I am uncertain if I did this properly, but I do get updates from my calendar, so at least some of it is working. Occasionally I do see some odd things in the Description for my items such as: “To see detailed information for automatically created events like this one, use the official Google Calendar app.” I’m not sure what that’s about.
Anyway, the top of my modified python script is this. Everything that follows is the same. Maybe this will be useful to someone else.
import datetime
import Settings as S
import warnings
import requests
import time
from operator import itemgetter
from googleapiclient.discovery import build
from google.oauth2 import service_account
def Main():
credentials = service_account.Credentials.from_service_account_file(S.CalendarClientSecretFile)
CalendarService = build('calendar', 'v3', credentials=credentials)
CurrentTime = datetime.datetime.utcnow().isoformat() + 'Z'
EventList = []
...
A for-loop within the python script was buggy and tried to access one openhab item more than specified by MaxEvents. This led to error messages in openhab. No severe problem but I fixed it. You can download it from my git.
Sorry, can’t help with this. What about Summary, Location, Starttime, Endtime? Do they work?
Yes, they work well. I don’t need that for now, so I’m going to ignore it. I made a simpler ExecCal rule and it does what I need. For reasons beyond my control
entries on my calendar don’t always follow exact rules so I needed to do some simple string compares to look for matches. Thanks again.
a more flexible ( grep etc ) item spotting script would be useful, ive been messing with some scripts ive found that decode the ics format, but getting the dates back into openhab ove found to be difficult
@Chod I’m not sure in which direction you’re pointing. Can you give an example?
Since the summertime, all my events are showing the wrong date. 19.12.1909 00:00 .. any idea?
Not here. What is the primary time zone of your google calendar? Are you using the latest version of the script?
The Primary Timezone is my local, GMT +2 Europe/Berlin.
Yes, im using the latest version
TimeZone in your CalSyncHAB.ini file should therfore also be:
TimeZone: +02:00
Is it?
I suppose the events in your google calendar show a correct date and time while your gCal items show the wrong date. Right?
Maybe there’s a problem with timezone properties of your openhab machine.
Ok, totally forget to check the CalSyncHAB.ini … Thanks for your help ![]()
I have the script working as as detailed but I’m having issues with timezones. I’m using the family calendar which is fixed to (GMT+00:00) Coordinated Universal Time and cannot be changed. I’m at +10:00 so everything is out by 10 hours.
The timezone setting in the *.ini file does not seem to have any affect on this. Any ideas on what I could do to resolve this?
It looks like I need a way to change the item value, to somehow add 10 hours as the actual response from the API is the wrong time to what it shows on the google calendar.
2019-05-21 22:21:44.148 [ome.event.ItemCommandEvent] - Item 'calendarevent16_summary' received command Brunch at Tenille's
2019-05-21 22:21:44.157 [vent.ItemStateChangedEvent] - calendarevent16_summary changed from to Brunch at Tenille's
2019-05-21 22:21:44.170 [ome.event.ItemCommandEvent] - Item 'calendarevent16_location' received command
2019-05-21 22:21:44.198 [ome.event.ItemCommandEvent] - Item 'calendarevent16_description' received command
2019-05-21 22:21:44.218 [ome.event.ItemCommandEvent] - Item 'calendarevent16_starttime' received command 2019-06-07T23:30:00.000+0000
2019-05-21 22:21:44.238 [vent.ItemStateChangedEvent] - calendarevent16_starttime changed from 1970-01-01T00:00:00.000+1000 to 2019-06-07T23:30:00.000+0000
2019-05-21 22:21:44.244 [ome.event.ItemCommandEvent] - Item 'calendarevent16_endtime' received command 2019-06-08T01:30:00.000+0000
2019-05-21 22:21:44.253 [vent.ItemStateChangedEvent] - calendarevent16_endtime changed from 1970-01-01T00:00:00.000+1000 to 2019-06-08T01:30:00.000+0000
Event when viewing in Google calendar is actually set for 9:30am

Frist of all: The timezone setting only works when the script detects an error while checking the date and time format which is delivered by google api. In case we only get a date without time the script appends T00:00:00 plus the timezone setting. As it would never add T23:30:00 I am sure that date and time are deliverd by the api.
Does that mean you traveled eastwards? If so you have to change the timezone of your events (not your calendar). Google automatically reads the timezone of your location while you edit your events and sets it to +10:00. I am pretty sure that the api converts this by adding the timezone to the time of your events and adding your calendar’s timezone instead of giving time and timezone. The script itself can’t do anything to change this.
Thanks for the reply. No, not travelled, just highligting that I live in Brisbane, Australia. There is something a bit odd going on but it is all working as expected, mostly.
My primary calendar (set to GMT+10:00) shows the correct time in google and in BasicUI. My family calendar (automatically created in google if you setup a family (set to GMT+00:00 and cannot be changed)) shows the correct time in google but it’s 10 hours behind in BasicUI (openhab is set to GMT+10:00 also), this only affects events with a time, not all day events which correctly show midnight to midnight.
What is odd but ultimately good is from HABpanel all times show correctly and since my goal was to show the calendar in HABpanel I no longer have an issue. I’ll just have to get used seeing the incorrect times in BasicUI and Frontail.
I’m not sure where to go from here, would like to understand this behaviour better and at some point fix it but for now it works.
I am pretty sure that the following explains the behavior.
Google knows that you are located at +10:00. Therefore the events in your family calendar are stored like 09:30:00+10:00 or like 23:30:00+00:00. Both values are equivalent. In any case google api returns the last value. HABpanel might now be able to reconvert this to 09:30:00 from the difference between your computer‘s timezone (+10:00) and the timezone given in the events (+00:00) while BasicUI might not be able to do the same conversion.
For some reason I updated my Google Calendar with my timezone (Sydney +11 - DST is on).
The script stopped working as Google was returning my calendar times with the +11 as part of the string. Have done a minor update to the script.
datetime.datetime.strptime(EventStartTime, '%Y-%m-%dT%H:%M:%S' + S.CalendarTimeZone)
to
datetime.datetime.strptime(EventStartTime, '%Y-%m-%dT%H:%M:%S%z')
and
datetime.datetime.strptime(EventEndTime, '%Y-%m-%dT%H:%M:%S' + S.CalendarTimeZone)
to
datetime.datetime.strptime(EventEndTime, '%Y-%m-%dT%H:%M:%S%z')
This does negate the timezone in the INI file but given google is now providing directly it did not seem to matter.
I’m using the python script and since a few days, OAuth authorization with google takes ages (some 5minutes!), in between these codelines:
def Main():
Credentials = GetCredentials()
HTTPAuthorization = Credentials.authorize(httplib2.Http())
CalendarService = discovery.build('calendar', 'v3', http = HTTPAuthorization) // <== THIS is the part taking up to 5mins!
CurrentTime = datetime.datetime.utcnow().isoformat() + 'Z'
...
meaning if Main() starts, it will get the Credentials and Authorize and after that with discovery.build(...) it takes a looooong time; much longer than usually. Is there something I missed or can change? or is it just google at the moment?