grover / homebridge-calendar

A calendar plugin for homebridge (https://github.com/nfarina/homebridge), which allows flexible scheduling of triggers using any iCal calendar.
MIT License
73 stars 13 forks source link

Support for full-day events? #29

Open maisun opened 3 years ago

maisun commented 3 years ago

Hi, I'm trying to setup some automation based on holiday calendar which contains only full day events (to mark the public holidays). When I start HomeBridge I got the error message. I suspect it is because the plugin doesn't support full day event? [2/21/2021, 8:47:10 PM] TypeError: Cannot read property 'toJSDate' of null
at getTimes (/homebridge/node_modules/homebridge-calendar/node_modules/ical-expander/index.js:40:53)
at /homebridge/node_modules/homebridge-calendar/node_modules/ical-expander/index.js:110:38
at Array.forEach ()
at IcalExpander.between (/homebridge/node_modules/homebridge-calendar/node_modules/ical-expander/index.js:63:57)
at CalendarPoller._refreshCalendar (/homebridge/node_modules/homebridge-calendar/src/CalendarPoller.js:78:30)
at IncomingMessage. (/homebridge/node_modules/homebridge-calendar/src/CalendarPoller.js:54:14)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)

dkahia commented 3 years ago

I think you need to confirm your calendar is accessible without authentication. It needs to be made public.

maisun commented 3 years ago

I think you need to confirm your calendar is accessible without authentication. It needs to be made public.

Hi, thanks for your reply! I think it is public as I can subscribe in my calendar without provide username/pwd. The link to the calendar is: webcal://ugenr.dk/ics/helligdage/dk.ics I have no idea how to check if the ics is in valid format though..

dkahia commented 3 years ago

I added your url and it seems to connect fine. There are no holidays to test against until April.

{ "name": "Danish Holidays", "url": "webcal://ugenr.dk/ics/helligdage/dk.ics", "pollingInterval": 15, "sensors": [] }

maisun commented 3 years ago

"sensors": []

Hi, thanks a lot for looking into it! I have the same configuration, but strangely I got the error below which causes HomeBridge to reboot: [2/27/2021, 9:26:32 PM] TypeError: Cannot read property 'toJSDate' of null at getTimes (/homebridge/node_modules/homebridge-calendar/node_modules/ical-expander/index.js:40:53) at /homebridge/node_modules/homebridge-calendar/node_modules/ical-expander/index.js:110:38 at Array.forEach () at IcalExpander.between (/homebridge/node_modules/homebridge-calendar/node_modules/ical-expander/index.js:63:57) at CalendarPoller._refreshCalendar (/homebridge/node_modules/homebridge-calendar/src/CalendarPoller.js:78:30) at IncomingMessage. (/homebridge/node_modules/homebridge-calendar/src/CalendarPoller.js:54:14) at IncomingMessage.emit (events.js:327:22) at endReadableNT (_stream_readable.js:1327:12) at processTicksAndRejections (internal/process/task_queues.js:80:21)

My configuration: { "platform": "Calendar", "calendars": [ { "name": "Holidays", "url": "webcal://ugenr.dk/ics/helligdage/dk.ics", "pollingInterval": 15, "sensors": [] } ] }

I'm running HB 1.3.1 and plugin version 0.4.0

dkahia commented 3 years ago

OS | Ubuntu Focal Fossa (20.04.2 LTS) Node.js v14.16.0 Npm v6.14.11

HB 1.3.1

maisun commented 3 years ago

OS | Ubuntu Focal Fossa (20.04.2 LTS) Node.js v14.16.0 Npm v6.14.11

HB 1.3.1

Hi, Ok so looks like nothing to do with HB 1.3.X. I have Node.js in a lower version: v14.15.1, and running as docker container with Homebridge-UI. Will try to upgrade Node and see if it solves. Thanks a lot for testing!

maisun commented 3 years ago

OS | Ubuntu Focal Fossa (20.04.2 LTS) Node.js v14.16.0 Npm v6.14.11

HB 1.3.1

Hi, Just want to report if I created a separate sub-bridge for Calendar plugin it now works fine, strange if I leave it in the main bridge it doesn't seem to parse the calendar correctly, maybe due to conflict with some HomeBridge dependencies. Anyways, I found that you can skip the invalid dates by: const icalExpander = new IcalExpander({ ics: data, maxIterations: 1000, skipInvalidDates: true }); Which I'd recommend to ensure in case of bad calendar format it doesn't crash homebridge. Anyways, will see how it works out in April :-) Thanks a lot for your help!

Edit: I tried to print out the events after parsing and it looks like following: { "component": [ "vevent", [ [ "uid", {}, "text", "dk-nytårsaften-2026@ugenr.dk" ], [ "summary", {}, "text", "Nytårsaften" ], [ "dtstamp", {}, "date-time", "2012-03-06T23:00:00Z" ], [ "dtstart", {}, "date", "2026-12-31" ], [ "duration", {}, "duration", "P1D" ], [ "url", {}, "uri", "https://ugenr.dk/nyt%C3%A5rsaften" ], [ "status", {}, "text", "CONFIRMED" ], [ "transp", {}, "text", "TRANSPARENT" ] ], [] ]

Does it look right? Basically I'd like to have a contact sensor that is open on 2026-12-31 at 0 o'clock local time, and off on 2026-12-31 at 23.59.59 local time. I notice "dtstamp" uses GMT time and not sure why "2012-03-06".