home-assistant / home-assistant.io

:blue_book: Home Assistant User documentation
https://www.home-assistant.io
Other
4.71k stars 7.15k forks source link

Sample template "agenda" #33711

Open stovedoctor opened 1 month ago

stovedoctor commented 1 month ago

Feedback

Can someone please explain a little? what is "for event in agenda" in the template ?


data:
  title: Daily agenda for {{ now().date() }}
  message: >-
    Your school calendar for today:
    {% for event in agenda["calendar.school_calendar"]["events"] %}
    {{ event.start}}: {{ event.summary }}<br>
    {% endfor %}
    Your work calendar for today:
    {% for event in agenda["calendar.work_calendar"]["events"] %}
    {{ event.start}}: {{ event.summary }}<br>
    {% endfor %}```

### URL

https://www.home-assistant.io/integrations/calendar/

### Version

2024.7.2

### Additional information

_No response_
home-assistant[bot] commented 1 month ago

Hey there @home-assistant/core, mind taking a look at this feedback as it has been labeled with an integration (calendar) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `calendar` can trigger bot actions by commenting: - `@home-assistant close` Closes the feedback. - `@home-assistant rename Awesome new title` Renames the feedback. - `@home-assistant reopen` Reopen the feedback. - `@home-assistant unassign calendar` Removes the current integration label and assignees on the feedback, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information) to the feedback. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information) on the feedback.
tjbenator commented 1 week ago

It's a two part example. One to fetch calender events, and another to send a notification of those events.

You would need this code snippet from further up on the page:

action: calendar.get_events
target:
  entity_id:
    - calendar.school
    - calendar.work
data:
  duration:
    hours: 24
response_variable: agenda

Which fetches 24 hours of calendar events and stores them in agenda

After that action you could then use the newly created agenda variable to send the notification:

action: notify.nina
data:
  title: Daily agenda for {{ now().date() }}
  message: >-
    Your school calendar for today:
    {% for event in agenda["calendar.school_calendar"]["events"] %}
    {{ event.start}}: {{ event.summary }}<br>
    {% endfor %}
    Your work calendar for today:
    {% for event in agenda["calendar.work_calendar"]["events"] %}
    {{ event.start}}: {{ event.summary }}<br>
    {% endfor %}
tjbenator commented 1 week ago

Created an example automation via the UI to demonstrate.

Trigger is every morning at 7am: 01-agenda_automation_when

It will use get_events to pull all calendar events for the next 24 hours and send a notification to my phone: 02-agenda_automation_then_do

Example of the notification: 03-agenda_notification

stovedoctor commented 3 days ago

Thank you