Seeking Elegant Solution for Reminders Around 5:00 PM on the Previous Day

Hello everyone, I would like it if calendar events for the next day are scheduled, you receive a WhatsApp reminder. The special thing is that the WhatsApp message should arrive at 5:00 PM each time. With a specific time before, it wouldn’t be a problem to solve. I’ve created a makeshift solution using a helper switch. Is there a more elegant solution that would be easy to implement? Does anyone know of one? Thank you for your help.

If you only want to know “if calendar events for the next day are scheduled”, seems pretty easy.
But you want the calendar details, I guess, right?

What do you actually have now?

Currently, I have an automation that activates another automation if there is an entry in the calendar 28 hours before
, and it automatically deactivates at midnight. It works well because the entries are between 7 am and 7 pm. But there must be a more elegant solution, right? Yes, I also have the YAML code for the event name,

{{ trigger.calendar_event.summary }}

which is sufficient for me.

I actually meant: Show your full code.
It is quite pointless to try to describe computer code with words when you can just copy/paste it, isn’t it? :slight_smile:

:slight_smile: you have a solution?

description: ""
mode: single
trigger:
  - platform: time
    at: "17:00:00"
condition: []
action:
  - service: notify.mobile_app_iphone_von_anousone
    data:
      title: test
       message: >-
                  Anthony morgen hast du {{ trigger.calendar_event.summary }}
                  startet am {{ trigger.calendar_event.start }}

Does anyone else know of a simple solution?

hmm…

if we’re being honest here, that automation has no prayer of doing anything. it’s not fetching from any calendar, it’s not talking w/ whatsapp. i’m guessing you tossed a few lines of code together when @koying pressed you to…

as a hint on how to be sly, next time throw your question in to chatgpt when asked for code and you don’t have any :). it’ll almost certainly be wrong still, but it won’t look as obvious that you were asking for someone to write it all from scratch for you…

i don’t know whether you’ve got actual content in the ha calendar, or google calendar or where you’re pulling your calendar from. you talked about whatsapp, but do you have a whatsapp integration set up? are you able to actually send to whatsapp already?

someone might come along and be super generous and write the whole thing from scratch… but the community generally does best helping folks who reasonably try to help themselves… so i’d encourage you to give it a real try first, post a real effort… and get some help then…

but who knows, maybe someone will gift you a full solution…

1 Like

Hello, yes, I shortened the YAML code because it was too complicated, and I posted it incorrectly, my mistake :slight_smile: Now here’s the complete code, and yes, it works. I have another automation that either activates or deactivates this automation, depending on whether there’s an entry in the calendar. Here’s the code: can I trust your help now? @armedad

alias: 06_08_Erinnerung_Kalenderereignis_vortag_Anthony
description: ""
trigger:
  - platform: time
    at: "17:00:00"
    id: Zeit_Anthony
  - platform: event
    event_data:
      action: KALENDER_ANTHONY
    id: kalendereintrag erledigt
    event_type: mobile_app_notification_action
  - platform: time
    at: "23:55:00"
    id: 0uhr
condition: []
action:
  - if:
      - condition: trigger
        id:
          - Zeit_Anthony
    then:
      - repeat:
          sequence:
            - service: notify.mobile_app_iphone_von_anousone
              data:
                data:
                  actions:
                    - action: KALENDER_ANTHONY
                      title: Wenn Kalender Überprüft bestätigen
                title: Kalender
                message: Kalender morgen überprüfen
            - service: notify.mobile_app_sm_g998b
              data:
                data:
                  actions:
                    - action: KALENDER_ANTHONY
                      title: Wenn Kalender Überprüft bestätigen
                title: Kalender
                message: >-
                  Anthony morgen hast du {{ trigger.calendar_event.summary }}
                  startet am {{ trigger.calendar_event.start }}
              enabled: false
            - if:
                - condition: zone
                  entity_id: person.anthony
                  zone: zone.home
              then:
                - service: notify.alexa_media_anthony_echo_dot
                  data:
                    message: >-
                      Anthony bitte Kalender eintrag für morgen überprüfen und
                      dann via whatsapp bestätigen
                    title: Kalender
                    data:
                      type: tts
            - delay:
                hours: 1
                minutes: 0
                seconds: 0
                milliseconds: 0
          until:
            - condition: state
              entity_id: input_boolean.kalenderereignis_morgen
              state: "on"
  - if:
      - condition: trigger
        id:
          - kalendereintrag erledigt
    then:
      - service: input_boolean.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: input_boolean.kalenderereignis_morgen
  - if:
      - condition: trigger
        id:
          - 0uhr
    then:
      - service: input_boolean.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: input_boolean.kalenderereignis_morgen
mode: parallel
max: 3

Here’s the automation that checks 28 hours ahead if there’s a calendar entry tomorrow.

alias: 06_08_Kalenderereignis_auto_start_beenden_Anthony
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "-28:0:0"
    entity_id: calendar.anthony
    id: kalender
  - platform: time
    at: "23:59:00"
    id: 0Uhr
    enabled: true
condition: []
action:
  - if:
      - condition: trigger
        id:
          - kalender
    then:
      - service: automation.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: automation.06_08_erinnerung_kalenderereignis_vortag
  - if:
      - condition: trigger
        id:
          - 0Uhr
    then:
      - service: automation.turn_off
        target:
          entity_id:
            - automation.06_08_erinnerung_kalenderereignis_vortag
        data:
          stop_actions: true
mode: parallel
max: 3

ok, that is way more helpful. please always share the actual code if you are having problems with code. it is otherwise quite hard to guess.

I don’t see how the first code can work because you are triggering on Zeit. And then you are trying to reference
trigger.calendar_event.summary

Which does not exist on a time triggered event.

You will first need to use calendar.get_events to get the calendar event data.

I am on mobile right now so hard for me to do the code but I think that is the first fundamental issue. Others here may be able to gen the code… But hopefully thats good to get you going if not…

At 17:00, use calendar.get_events to get tomorrow’s events (in a response_variable) and then report the contents of the response_variable via your choice of notification service.

alias: example 
trigger:
  - platform: time
    at: '17:00:00'
condition: []
action:
  - service: calendar.get_events
    data:
      duration:
        hours: 24
      start_date_time: "{{ today_at() + timedelta(days=1) }}"
    target:
      entity_id:
        - calendar.anthony
    response_variable: agenda
  - service: notify.your_phone
    data:
      title: Daily agenda for {{ now().date() + timedelta(days=1) }}
      message: >-
        Your scheduled events for tomorrow:
        {% for event in agenda['calendar.anthony']['events'] %}
        {{ event.start}}: {{ event.summary }}<br>
        {% endfor %}
1 Like

Thank you, this would work, but if I don’t have an entry, I still receive a notification. I only want to receive a WhatsApp message if there’s an entry the next day. Is there a solution for that?

Yes, add a condition that checks if the quantity of events is greater than zero. Here’s one way to do it:

alias: example 
trigger:
  - platform: time
    at: '17:00:00'
condition: []
action:
  - service: calendar.get_events
    data:
      duration:
        hours: 24
      start_date_time: "{{ today_at() + timedelta(days=1) }}"
    target:
      entity_id:
        - calendar.anthony
    response_variable: agenda
  - condition: "{{ agenda['calendar.anthony']['events'] | count > 0 }}"
  - service: notify.your_phone
    data:
      title: Daily agenda for {{ now().date() + timedelta(days=1) }}
      message: >-
        Your scheduled events for tomorrow:
        {% for event in agenda['calendar.anthony']['events'] %}
        {{ event.start}}: {{ event.summary }}<br>
        {% endfor %}

Reference

Scripts - Test a condition

2 Likes

Thank you very much! That is the solution!

1 Like

Hello everyone, another question, I would like to continue to be asked at 5:00 p.m. whether there is a calendar entry for tomorrow, but only a notification comes if there is an @ sign in the calendar text, does anyone know why this code does not work?
I add this code:

  - condition: template
    value_template: "{{ trigger.calendar_event.summary is search('@') }}
alias: example
trigger:
  - platform: time
    at: "17:00:00"
condition: []
action:
  - service: calendar.get_events
    data:
      duration:
        hours: 24
      start_date_time: "{{ today_at() + timedelta(days=1) }}"
    target:
      entity_id:
        - calendar.anthony
    response_variable: agenda
  - condition: template
    value_template: "{{ trigger.calendar_event.summary is search('@') }}"
  - service: notify.your_phone
    data:
      title: Daily agenda for {{ now().date() + timedelta(days=1) }}
      message: >-
        Your scheduled events for tomorrow: {% for event in
        agenda['calendar.anthony']['events'] %} {{ event.start}}: {{
        event.summary }}<br> {% endfor %}

  - condition: template
    value_template: >
      {{ agenda['calendar.anthony']['events']
        | selectattr('summary', 'contains', '@') 
        | list | count > 0 }}

  - condition: template
    value_template: >
      {{ agenda['calendar.anthony']['events']
        | selectattr('summary', 'contains', '@') 
        | list | count > 0 }}

Thank you very much, but unfortunately, this YAML code does not work.

1 Like

Oh, I have unfortunately made a formatting error. Thank you very much for your help!

1 Like

Hello everyone, is there another way to check multiple calendars? I tried it like this, but it didn’t work.

service: calendar.get_events
data:
  duration:
    hours: 24
  start_date_time: "{{ today_at() + timedelta(days=1) }}"
target:
  entity_id:
    - calendar.anthony
    - calendar.andrew
response_variable: agenda
enabled: true
{{ agenda['calendar.anthony', 'calendar.andrew' ]['events']
  | selectattr('summary', 'contains', '@') 
  | list | count > 0 }}