franc6 / ics_calendar

Provides an ICS (icalendar) platform for the Home Assistant calendar
Apache License 2.0
143 stars 22 forks source link

all-day events - trigger in HA #74

Open MPatzek opened 1 year ago

MPatzek commented 1 year ago

Hey,

I have a problem setting up a trigger for all-day events in the automations. In detail, it is about a trash calender, where the all-day event indicates the day of removal. I tried with a trigger with an offset of 7 hours to trigger it the day before at 5pm.

alias: Kalendertest
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "-7:0:0"
    entity_id: calendar.abfallcalender
condition: []
action:
  - service: telegram_bot.send_message
    data:
      message: Müll wird abgeholt {{ trigger.calendar_event.summary }}
mode: single

Here is the definition:

calendar:
  - platform: ics_calendar
    calendars:
      - name: "Abfallcalender"
        url: "https://calendar.google.com/calendar/ical/xxxxx
        days: 14
        download_interval: 5
        include_all_day: True

The events are shown in the calender tile, but the triggering is not working. What do I miss here?

best regards

franc6 commented 1 year ago

I'm not sure why that wouldn't work, although I suspect it's not related to this calendar platform. I'd recommend changing the automation's mode from 'single' to 'queued', based on recommendations at https://www.home-assistant.io/integrations/calendar#automation

Another note, if this is a trash calendar, I suspect it's unlikely to change often, in which case, you might want to set download_interval to at least 1440 (once a day), instead of 5 (once every 5 minutes). That'll reduce your system load, as it won't have to download the calendar data so often. The download_interval should always be a multiple of 15, anyway, just because of how calendars work in HA.

MPatzek commented 1 year ago

Thanks for the suggestion! It actually works with "normal" entries, e.g., with a given time of the day. That's why I am confused it does not work with all-day events. I'll see if it works with the queued mode and report back.

Report back: This did not solve the issue for me. Really weird, since the all-day events are also associated with a exact starting time (00:00). I changed my calender entries not to a given time slot as a work around.

franc6 commented 1 year ago

I'm going to leave this open for now, but I don't think this is a bug in this software. I'll play with it for caldav, and see what I can come up with. Please note that all-day events don't actually have a start time; they only have a start date. Usually that's interpreted as 00:00:00, but I wonder if the trigger doesn't interpret the time?

SirGarnet commented 1 year ago

Hi @franc6 ,

I have the exact same problem in the current version of HA & ICS Calendar. I add my config and automation, these are working on a local calendar but not with ICS. You can use the appended calendar it is a free suppplied waste calendar for my region.

Maybe this helps to find a solution.

EDIT: Just saw that the whole day events in the downloaded calendar are shown as timed events with a dot and not with a bar like the whole day entrys in a local calendar. See attached image, blue is local calender purple is the ics downloaded calendar.

2023-03-31 00_29_44-Kalender – Home Assistant

configuration.yaml:

# Waste Calendar
calendar:
  - platform: ics_calendar
    calendars:
      - name: "Waste Calendar"
        url: "https://landkreis-stendal.abfall-app.net/download?system=ical&period=1&district=1358&categories=&view=year"
        download_interval: 43800

automation:

alias: TEST - MÜLL
description: Sendet eine Benachrichtigung um die Mülltonnen rechtzeitig raus zu stellen.
trigger:
  - platform: calendar
    event: start
    offset: "-10:0:0"
    entity_id: calendar.waste_calendar
condition: []
action:
  - service: persistent_notification.create
    data:
      message: "{{ trigger.calendar_event.summary }}"
  - service: notify.administrator
    data:
      data:
        inline_keyboard:
          - 30 Minuten:/30m, 1 Stunde:/1h
          - Wird gemacht:/removekeyboard
      message: "{{ trigger.calendar_event.summary }}"
mode: queued
michaelwingender commented 1 year ago

Looks like I have found a similar issue with a ICS holiday calendar: http://i.cal.to/ical/61/nrw/feiertage/7309dfd4.2383d769-22a4152c.ics For a local calendar with all day events, automations are triggerd. For this calendar it looks like the events do not trigger my automations.