Today's Events Widget

Mike_Bagdanoff https://community.openhab.org/users/mike_bagdanoff
February 14

Then it depends on what the value of todaysDate is, you can create a new
widget, name it whatever you want, then paste in this code:

{{(itemValue(‘Calendar_Google_Home_Event1_StartTime’) | date:‘yyyyMMdd’)}}

{{(itemValue(‘todaysDate’) | date:‘yyyyMMdd’)}}

then go to the preview tab and post a screenshot of the result. If both
lines are the same then I’m just going to go with a spacetime rift open
inside your computer that makes logic stop working.


Visit Topic
https://community.openhab.org/t/todays-events-widget/22631/20 or reply
to this email to respond.

In Reply To
Joshua_Cherwinski https://community.openhab.org/users/joshua_cherwinski
February 14
15:25:01.816 [INFO ] [smarthome.event.ItemCommandEvent ] - Item
‘Calendar_Google_Home_Event1_Summary’ received command 15:25:01.863 [INFO ]
[smarthome.event.ItemCommandEvent ] - Item
‘Calendar_Google_Home_Event1_Summary’ received command Test 15:25:01.879
[INFO ] [marthome.event.ItemStateChan…


Visit Topic
https://community.openhab.org/t/todays-events-widget/22631/20 or reply
to this email to respond.

To unsubscribe from these emails, click here
https://community.openhab.org/email/unsubscribe/0076825c50e6e4aa8824a05ec9c8a95007f8215907fad3b952a47d3cb88943aa
.

I think you may have had a copypasta issue here. I’m not sure that you meant to write all this.

Hello!

I’m not sure why do you add a timezone to the code. The Timezone parameter in CalSyncHAB.ini should take care of that, and send it via Google Calendar API, so, every event/task you get should be in sync with your timezone. And, regarding all today’s events instead of a future ones, did you mean you want event to show even if it’s past the end time (i.e. you want to receive event that was scheduled between 11 AM and 2 PM even if it’s 5 PM at the moment)? That should be achievable by changing CurrentTime only, no need to add the timezone here, if you set it up in .ini file. Actually, in that case, your CurrentTime should be current date midnight all day long.

Best regards,
Davor

I’m pretty sure the ‘-08:00’ isn’t used for any calculation, it is a label describing the timezone for the Time value but I might be wrong as I’ve just started looking at this stuff.

My understanding is:
The CurrentTime String “017-02-15T18:00:00.000000-08:00” means 6:00pm in the Pacific US timezone, it doesn’t mean 6:00pm UTC - 8 hours. Since my google calendar already knows its timezone, an event that starts at 11am has a StartTime of ‘2017-02-15T11:00:00-08:00’.

The script needs the CurrentTime variable to be in local time but my original change was bad as it assumed the -08:00 was being applied to the time before comparison, so I thought it was 11:59pm yesterday but it was really 7:59am today and it required the script to have a value for the timedelta. So after looking through the python docs, I have now changed the the line to use now() instead of utcnow():

CurrentTime = (datetime.datetime.now()).replace(hour=0, minute=0, second=0, microsecond=0).isoformat() + S.CalendarTimeZone

This gives me all events as of midnight today.

here is some output from some tests I ran:

Run #1: (Script as is misses 11am and 3pm event today)
pi@the-machine:/etc/openhab2/scripts/CalSyncHAB-master $ python CalSyncHAB.py
CurrentTime = datetime.datetime.utcnow().isoformat() + S.CalendarTimeZone
CurrentTime : 2017-02-15T18:14:48.785735-08:00
Event1 : Bella Drivers Ed - 2017-02-16T15:00:00-08:00
Event2 : Bella’s Birthday - 2017-02-19T00:00:00-08:00
Event3 : No School - 2017-02-20T00:00:00-08:00
Event4 : Mike Off Work - 2017-02-20T00:00:00-08:00
Event5 : Bella Drive #2 - 2017-02-20T13:00:00-08:00

Run #2: (Get local time first, gives all future events (correctly leaves off 6am event but nicely keeps my all day event))
pi@the-machine:/etc/openhab2/scripts/CalSyncHAB-master $ python CalSyncHAB.py
CurrentTime = (datetime.datetime.now()).isoformat() + S.CalendarTimeZone
CurrentTime : 2017-02-15T10:17:10.148079-08:00
Event1 : Garbage & Recycle Day - 2017-02-15T00:00:00-08:00
Event2 : test2 - 2017-02-15T11:00:00-08:00
Event3 : Bella Drivers Ed - 2017-02-15T15:00:00-08:00
Event4 : Bella Drivers Ed - 2017-02-16T15:00:00-08:00
Event5 : Bella’s Birthday - 2017-02-19T00:00:00-08:00

Run #3: (After Midnight, changed Time fields to 0 so I get all events today)
pi@the-machine:/etc/openhab2/scripts/CalSyncHAB-master $ python CalSyncHAB.py
CurrentTime = (datetime.datetime.now()).replace(hour=0, minute=0, second=0, microsecond=0).isoformat() + S.CalendarTimeZone
CurrentTime : 2017-02-15T00:00:00-08:00
Event1 : Garbage & Recycle Day - 2017-02-15T00:00:00-08:00
Event2 : test1 - 2017-02-15T06:00:00-08:00
Event3 : test2 - 2017-02-15T11:00:00-08:00
Event4 : Bella Drivers Ed - 2017-02-15T15:00:00-08:00
Event5 : Bella Drivers Ed - 2017-02-16T15:00:00-08:00

Hello!

I’m pretty sure that -08:00 is used for calculation, because I live in +1 timezone, and if I replace +01:00 with Z (UTC time) all my events and tasks are displayed with one hour offset. All day events are working with a script as-is. The only thing I’m not using is displaying today’s past events (events that are already over).

Best regards,
Davor

Ok, now I get it. Google uses the UTC offset to do the date math, if the offset is different than the offset set in the google calendar settings, it will convert when doing its timeMin check. The problem in the original script code is that there is a mismatch between the offset. It either needs to be:

CurrentTime = (datetime.datetime.utcnow()).isoformat() + "-00:00"

or

CurrentTime = (datetime.datetime.now()).isoformat() + S.CalendarTimeZone

the first one says 2pm UTC, the second says 2pm localtime. The problem in the original script code is that the CurrentTime value is filling the datetime structure with 2pm UTC and then appending the tag for localtime to it so google reads it (for my timezone) as 10pm localtime when comparing to my events that are also in localtime.

I think your success is a negative vs positive offset issue. Since my offset is negative, I lose dates in the future for up to 8 hours, which is quite noticible. Yours is a very small positive offset so when you run the script it may include events that are in the past, but only by an hour. If you create an event that starts at 11am and ends at 11:30am and then run the script at noon, that event should still be in your list.

Basically, at noon your time, your utcnow() call would return 11am and adding your +01:00 to the string would tell google that you want all events that end after 11am your localtime.

Hello!

You are right. I’ve just tried it and there is an event displayed that’s already finished. I’ll fix the script as soon as I find some free time. Thank you for a thorough analysis of the problem.

Best regards,
Davor

Welcome! Also, i’ve changed my script to just use

CurrentTime = (datetime.datetime.utcnow()).isoformat() + "-00:00"

which leaves the timezone stuff to google and you can leave out the CalendarTimeZone configuration, which makes it easier for people to use.

Hello!

I’ve pushed change that fixes bug with a timezone to the github. I’ve used

CurrentTime = (datetime.datetime.utcnow()).isoformat() + 'Z'

because that’s preferred notation for the UTC time. I’ve left Timezone parameter in the CalSyncHAB.ini, because it’s used for formatting of the startTime and endTime values. I’ve tested it with a few events, and now it seems to work without errors. If you find anything else, feel free to post it here, or as the github issue. Thank you for your help.

Best regards,
Davor

Hi, i have some problems with getting the widget to work. I get similar problems as Joshua_Cherwinski. If i run the script
manually i get these errors from the openhab.log while i run “tail -f /var/log/openhab2/openhab.log” The widget says no events today but the calendar is populated.

    2018-01-04 16:22:15.208 [INFO ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 
   'items/Calendar                                                                                                                       
    _Google_Home_Event1_StartTime' for the unknown item 'Calendar_Google_Home_Event1_StartTime'.
    2018-01-04 16:22:15.216 [WARN ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 
    'items/Calendar                                                                                                                       
    _Google_Home_Event1_EndTime' with an invalid status value 'UNDEF'.
    2018-01-04 16:22:15.246 [WARN ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 
    'items/Calendar                                                                                                                       
    _Google_Home_Event2_StartTime' with an invalid status value 'UNDEF'.
    2018-01-04 16:22:15.253 [WARN ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 
    'items/Calendar                                                                                                                        
    _Google_Home_Event2_EndTime' with an invalid status value 'UNDEF'.
    2018-01-04 16:22:15.281 [WARN ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 
    'items/Calendar                                                                                                                       
    _Google_Home_Event3_StartTime' with an invalid status value 'UNDEF'.
    2018-01-04 16:22:15.288 [WARN ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 
    'items/Calendar                                                                                                                       
    _Google_Home_Event3_EndTime' with an invalid status value 'UNDEF'.
    2018-01-04 16:22:15.310 [WARN ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 
    'items/Calendar                                                                                                                       
    _Google_Home_Event4_StartTime' with an invalid status value 'UNDEF'.
    2018-01-04 16:22:15.316 [WARN ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 
    'items/Calendar                                                                                                                       
    _Google_Home_Event4_EndTime' with an invalid status value 'UNDEF'.
    2018-01-04 16:22:15.340 [WARN ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 
    'items/Calendar                                                                                                                       
    _Google_Home_Event5_StartTime' with an invalid status value 'UNDEF'.
    2018-01-04 16:22:15.346 [WARN ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 
    'items/Calendar                                                                                                                       
    _Google_Home_Event5_EndTime' with an invalid status value 'UNDEF'.
    2018-01-04 16:22:17.385 [INFO ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 
   'items/Calendar

events.log seams to find the events in my Calender.

   _Google_Home_Event1_StartTime' for the unknown item 'Calendar_Google_Home_Event1_StartTime'.
   2018-01-04 22:02:00.625 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event1_Summary'     received command
2018-01-04 22:02:00.628 [vent.ItemStateChangedEvent] - Calendar_Google_Home_Event1_Summary changed from asd to
2018-01-04 22:02:00.633 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event1_Location' received command
2018-01-04 22:02:00.641 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event1_Description' received command
2018-01-04 22:02:00.666 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event2_Summary' received command
2018-01-04 22:02:00.669 [vent.ItemStateChangedEvent] - Calendar_Google_Home_Event2_Summary changed from test1 to
2018-01-04 22:02:00.673 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event2_Location' received command
2018-01-04 22:02:00.680 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event2_Description' received command
2018-01-04 22:02:00.696 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event3_Summary' received command
2018-01-04 22:02:00.698 [vent.ItemStateChangedEvent] - Calendar_Google_Home_Event3_Summary changed from test1.1 to
2018-01-04 22:02:00.702 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event3_Location' received command
2018-01-04 22:02:00.708 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event3_Description' received command
2018-01-04 22:02:02.735 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event1_Summary' received command Today
2018-01-04 22:02:02.737 [vent.ItemStateChangedEvent] - Calendar_Google_Home_Event1_Summary changed from  to Today
2018-01-04 22:02:02.743 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event1_Location' received command Today.loc
2018-01-04 22:02:02.745 [vent.ItemStateChangedEvent] - Calendar_Google_Home_Event1_Location changed from  to Today.loc
2018-01-04 22:02:02.751 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event1_Description' received command
2018-01-04 22:02:02.764 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event1_EndTime' received command 2018-01-05T00:30:00.000+0100
2018-01-04 22:02:02.770 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event2_Summary' received command Tommorow
2018-01-04 22:02:02.771 [vent.ItemStateChangedEvent] - Calendar_Google_Home_Event2_Summary changed from  to Tommorow
2018-01-04 22:02:02.776 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event2_Location' received command Tommorow.loc
2018-01-04 22:02:02.777 [vent.ItemStateChangedEvent] - Calendar_Google_Home_Event2_Location changed from  to Tommorow.loc
2018-01-04 22:02:02.782 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event2_Description' received command
2018-01-04 22:02:02.788 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event2_StartTime' received command 2018-01-05T17:00:00.000+0100
2018-01-04 22:02:02.794 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event2_EndTime' received command 2018-01-05T18:00:00.000+0100
2018-01-04 22:02:02.800 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event3_Summary' received command Tommorow2
2018-01-04 22:02:02.804 [vent.ItemStateChangedEvent] - Calendar_Google_Home_Event3_Summary changed from  to Tommorow2
2018-01-04 22:02:02.807 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event3_Location' received command Tommorow2.loc
2018-01-04 22:02:02.811 [vent.ItemStateChangedEvent] - Calendar_Google_Home_Event3_Location changed from  to Tommorow2.loc
2018-01-04 22:02:02.813 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event3_Description' received command
2018-01-04 22:02:02.818 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event3_StartTime' received command 2018-01-05T23:00:00.000+0100
2018-01-04 22:02:02.824 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event3_EndTime' received command 2018-01-06T00:00:00.000+0100
2018-01-04 22:02:23.083 [vent.ItemStateChangedEvent] - network_pingdevice_c1ae640f_lastseen changed from 2018-01-04T22:01:15.969+0100 to 2018-01-04T22:02:18.127+0100
2018-01-04 22:03:23.180 [vent.ItemStateChangedEvent] - network_pingdevice_c1ae640f_lastseen changed from 2018-01-04T22:02:18.127+0100 to 2018-01-04T22:03:23.175+0100
2018-01-04 22:03:23.182 [me.event.ThingUpdatedEvent] - Thing 'network:pingdevice:c1ae640f' has been updated.

My Items file under “/etc/openhab2/items/Calendar_Google_Home.items” looks like this

Switch Calendar_Refresh (gCal) {autoupdate="false"}
DateTime todaysDate

String Calendar_Google_Home_Event1_Summary
String Calendar_Google_Home_Event1_Location
String Calendar_Google_Home_Event1_Description
DateTime Calendar_Google_Home_Event1_Startime
DateTime Calendar_Google_Home_Event1_EndTime

String Calendar_Google_Home_Event2_Summary
String Calendar_Google_Home_Event2_Location
String Calendar_Google_Home_Event2_Description
DateTime Calendar_Google_Home_Event2_StartTime
DateTime Calendar_Google_Home_Event2_EndTime

String Calendar_Google_Home_Event3_Summary
String Calendar_Google_Home_Event3_Location
String Calendar_Google_Home_Event3_Description
DateTime Calendar_Google_Home_Event3_StartTime
DateTime Calendar_Google_Home_Event3_EndTime

String Calendar_Google_Home_Event4_Summary
String Calendar_Google_Home_Event4_Location
String Calendar_Google_Home_Event4_Description
DateTime Calendar_Google_Home_Event4_StartTime
DateTime Calendar_Google_Home_Event4_EndTime

String Calendar_Google_Home_Event5_Summary
String Calendar_Google_Home_Event5_Location
String Calendar_Google_Home_Event5_Description
DateTime Calendar_Google_Home_Event5_StartTime
DateTime Calendar_Google_Home_Event5_EndTime

If i log in to the (https://console.developers.google.com i can se an new entry with response code 200 evry time i run the script so it seams like the python script talks with google calender.

my CalSyncHAB.ini looks like this:
[General]
ApplicationName: OpenHAB

[Calendar]
Scope: https://www.googleapis.com/auth/calendar.readonly
CalendarId: primary
MaxEvents: 5
TimeZone: +01:00
ClientSecretFile: /etc/openhab2/scripts/CalSyncHAB/clientsecret.json

[OpenHAB]
HostName: 192.168.88.192
Port: 8080
ItemPrefix: Calendar_Google_Home_

Can someone please help me figure out what i am doing wrong?

Best Regards.

Ping @Mike_Bagdanoff @davorf

The two dates are 3 days apart for me even though the Event1 is in todaysDate; how do I fix this?

Got the script working great :slight_smile:
But I get a strange time issue.
On my computers it displaying the time correctly and also on my Samsung S8. But on my galaxy s2 tab it shows the time 1 hour earlier. All the system has the same regional settings.

Anyone that has a clue what this could be?

Strange problem - If I run the sh script from the command terminal on OH it will update my calendars successfully… but if I trigger through openhab or via rules it logs that it executed the script, but I never receive any updates to the API?

Hi all, I have used this for two month now and suddenly it stops working. When I check the logs suddenly it says:

2018-03-25 07:45:03.078 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event2_Summary' received command
2018-03-25 07:45:03.082 [vent.ItemStateChangedEvent] - Calendar_Google_Home_Event2_Summary changed from Martin: Sahlgrenska to
2018-03-25 07:45:03.102 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event2_Location' received command
2018-03-25 07:45:03.128 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event2_Description' received command
2018-03-25 07:45:03.131 [vent.ItemStateChangedEvent] - Calendar_Google_Home_Event2_Description changed from
 to
2018-03-25 07:45:03.223 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event3_Summary' received command
2018-03-25 07:45:03.227 [vent.ItemStateChangedEvent] - Calendar_Google_Home_Event3_Summary changed from Rasmus bvc to
2018-03-25 07:45:03.249 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event3_Location' received command
2018-03-25 07:45:03.265 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event3_Description' received command
2018-03-25 07:45:03.270 [vent.ItemStateChangedEvent] - Calendar_Google_Home_Event3_Description changed from När: 27 mars 2018 11:00:00 AM
--
 to
2018-03-25 07:45:03.322 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event4_Summary' received command
2018-03-25 07:45:03.324 [vent.ItemStateChangedEvent] - Calendar_Google_Home_Event4_Summary changed from BoU to
2018-03-25 07:45:03.338 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event4_Location' received command
2018-03-25 07:45:03.355 [ome.event.ItemCommandEvent] - Item 'Calendar_Google_Home_Event4_Description' received command
2018-03-25 07:45:03.359 [vent.ItemStateChangedEvent] - Calendar_Google_Home_Event4_Description changed from When: 12 Apr 2018 5:00:00 PM

If I do a REST call to see the status of Calendar_Google_Home_Event3_Description i get that it now contains the StartTime

{"link":"http://IPADRESS:8080/rest/items/Calendar_Google_Home_Event3_Description","state":"När: 27 mars 2018 11:00:00 AM\n--\n","stateDescription":{"pattern":"%s","readOnly":false,"options":[]},"type":"String","name":"Calendar_Google_Home_Event3_Description","label":"Event1 Desc.","category":"calendar","tags":[],"groupNames":["gCalEvent"]}

and the starttime contains NULL

{"link":"http://IPADDRESS:8080/rest/items/Calendar_Google_Home_Event3_StartTime","state":"NULL","stateDescription":{"pattern":"%1$td.%1$tm.%1$tY %1$tH:%1$tM","readOnly":false,"options":[]},"type":"DateTime","name":"Calendar_Google_Home_Event3_StartTime","label":"Event1 Start","category":"calendar","tags":[],"groupNames":["gCalEvent"]}

If i print the RetrievedEvents in the python file it recieves the data according to the

 u'updated': u'2018-02-12T09:31:42.369Z', u'summary': 
 u'Rasmus bvc', 
 u'guestsCanInviteOthers': False,
 u'start': {u'dateTime': u'2018-03-27T11:00:00+02:00'}, 
 u'etag': u'"3036855804738000"', u'privateCopy': True,

So what could have happend?