Next Events from Caldav Calendar

Hello,
I have intrate my icloud calendar with:

calendar:
  - platform: caldav
    url: https://caldav.icloud.com
    username: !secret icloud_kalender_username
    password: !secret icloud_kalender_password
    custom_calendars:
      - name: Bogensport
        calendar: Bogenschiessen
        search: ".*"
      - name: Urlaub
        calendar: Arbeit
        search: "Urlaub*"
      - name: Arbeit
        calendar: Arbeit
        search: ".*"

It works, that I can see alle events in the calendar view.

I can only find the stage of the calendar.

But now I would like to output the next 5 events from this calendaron a lovelace page.

How can I do this?

But I don´t find anything here in the forum.

Thank you for the Addon tipp.

But now I have a problem to config the addon for my icloud calendar.

I put the following into the config of the addon:

- calName: Familie
  calType: caldav
  username: my icloud username
  password: the specific password
  caldavUrl: https://xxx-caldav.icloud.com/calendars/kalendername/

I put at xxx before -caldav the number of the server and by kalendername the right kalendername
But I don´t find the sensors

This doesn’t look like the correct url for your calendar. :slight_smile:

The documentation says this:

Apple icloud caldav

To obtain the caldavUrl for your icloud calendar, follow the explanation in the highest voted answer on this forum. Your url should look like https://*******.icloud.com/{dsid}/calendars/{calendarName}/ (Don’t forget to include the trailing forward slash). If you have trouble finding the right url, take a look at the solution in this closed issue.

Also make sure to generate an app-specific password like explained there and use this as the password you set in the add-on config.

Also, have you noticed this:

If you run the add-on for the first time you need to give it some time, depending on the CRON-schedule you configured. I advise not to overload the google or caldav api’s. I chose to only query them every 30 minutes. You can see in the addon logs when a query has run and when the data is posted to the sensor(s).

The queried data is saved to a file in persistent storage and this is used upon restarts of the add-on, so after a restart you shouldn’t need to wait normally.

I think that’s old. The new one:

Here’s a 2018 Update. If you want to use your iCloud calendar in Gnome Calendar you still need to install Evolution. After you added the calendar, you can remove Evolution.

  • Go to icloud.com and temporarilyshare a calendar to get the server URL and note it down somewhere (e.g. https://p12-caldav.icloud.com). Now deactivate the calendar sharing. If you don’t do this, everyone can view this shared calendar!

That why I use this form. But If you are right, how can I find the dsid? Because I try to find it out with Firefox like it written in the documentation. But the dsid don’t show.

This is my log:

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
added 62 packages, and audited 63 packages in 19s
23 packages are looking for funding
run npm fund for details
found 0 vulnerabilities
axios error: Request failed with status code 400[object Object]
Calendar(s) queried at: Fri Jun 03 2022 23:00:01 GMT+0200 (Central European Summer Time)
postEventsAllCalendars error: TypeError: Cannot read properties of undefined (reading ‘length’)
CRON-Task: Events posted to sensor(s) at: Fri Jun 03 2022 23:00:01 GMT+0200 (Central European Summer Time)
axios error: Request failed with status code 400[object Object]
Calendar(s) queried at: Fri Jun 03 2022 23:30:00 GMT+0200 (Central European Summer Time)
postEventsAllCalendars error: TypeError: Cannot read properties of undefined (reading ‘length’)
CRON-Task: Events posted to sensor(s) at: Fri Jun 03 2022 23:30:00 GMT+0200 (Central European Summer Time)

Ok now I have try with the other url:

https://pxx-caldav.icloud.com/xxxxxxxxxxxxxxxxxx/calendars/archery/

But with this url I got also an Error in the addon Logs:
found 0 vulnerabilities
axios error: Request failed with status code 403[object Object]
Calendar(s) queried at: Sat Jun 04 2022 10:00:00 GMT+0200 (Central European Summer Time)
postEventsAllCalendars error: TypeError: Cannot read properties of undefined (reading ‘length’)
CRON-Task: Events posted to sensor(s) at: Sat Jun 04 2022 10:00:00 GMT+0200 (Central European Summer Time)

What I make wrong?

I don’t think you’re doing something wrong, maybe you’re hit with this issue as well:

Try checking in there, maybe you can help with something to solve this. :slight_smile: But it seems to be related, as the error message is nearly identical.

I had read that and didn’t assume it was the same.

So I opened a new issue in github.

Have maybe anyone a other idea, how I can output the next for example 5 events in my calender?

It’s the same as yours, it is about

TypeError: Cannot read properties of undefined (reading ‘length’)

But unfortunately I don’t know about other components, that would give you more than the next event from a calendar.

The caldav component in HA is not the best, to say it nicely. It implements the complete “caldav” library, but uses only a small fraction of what that library could do. For example, the library can add or modify events, yet in HA you can only get the next event. Period. :wink:

I sincerely hope, someone is picking up on this, and rewrites or extends the HA component. But for now, we are stuck with this… :expressionless:

Thanks for the information.

But you write it is possible to give out the next event.

But how can I give out the next event for example:

  • Date
  • time if not all day event
  • text of the event

If this possible it is the first step for me and it is ok

I’m one step further now.

I have add in the configuration.yaml at the calendar days: 7. So in the calendar entitie the next date appears 7 days in advance.

But now I need your support again.

I make the output with the following code:

## Nächster Bogensport Termin:
{{ states.calendar.bogenschiessen_bogensport.attributes.message }}

{{ as_timestamp(state_attr("calendar.bogenschiessen_bogensport", "start_time")) | timestamp_custom('%a, %d.%m.%Y') | replace("Mon", "Montag") | replace("Tue", "Dienstag") | replace ("Wed", "Mittwoch") | replace ("Thu", "Donnerstag") | replace ("Fri", "Freitag") | replace ("Sat", "Samstag") | replace ("Sun", "Sonntag") }}

Beginn: {{ as_timestamp(state_attr("calendar.bogenschiessen_bogensport", "start_time")) | timestamp_custom('%H:%M Uhr') }}
Ende: {{ as_timestamp(state_attr("calendar.bogenschiessen_bogensport", "end_time")) | timestamp_custom('%H:%M Uhr') }}


{{ states.calendar.bogenschiessen_bogensport.attributes.location }}

But now I have the Problem, if are no event in the next 7 days the code crashed because there a no attributes.

How can I put out “no Event” if are no event in the next 7 days?