Birthday reminder automation based on Google calendar events

Hi there,

I’m trying to set up a custom birthday reminder automation based on my already configured an working Google birthday calendar and basically it is working but…

So here’s my automation:

alias: Birthday Reminder
description: ''
trigger:
  - platform: time
    at: '10:00'
condition:
  - condition: state
    entity_id: calendar.geburtstage
    state: 'on'
action:
  - device_id: [mysmartphone]
    domain: mobile_app
    type: notify
    title: Birthday reminder
    message: **xxx hat heute Geburtstag!**
mode: single

And here’s the state of that particular calendar right now:

message: **[name of a friend] hat Geburtstag**
all_day: true
start_time: '2021-05-07 00:00:00'
end_time: '2021-05-08 00:00:00'
location: ''
description: [name of a friend] hat Geburtstag!
offset_reached: false
friendly_name: Geburtstage

So what I’m trying to accomplish is that the notification on my smartphone includes the message of said entity as the message text. So if John Doe has it’s birthday on the 7th of may I want to get a message to my smartpone at 10 a.m. with the message text “It’s John’s birthday today!” and of course if Jane Doe has her birthday 5 days later I want another message with her name.

I’d be happy if anybody could help or maybe just push me in the right direction, as I’m pretty knew to HA and templates and variables and stuff.

if the format of the calendar message is exactly the same for each entry as in the above example I think you can use this template to just extract the name and add it to your notification message:

action:
  - device_id: [mysmartphone]
    domain: mobile_app
    type: notify
    title: Birthday reminder
    message: >
      **{{ state_attr('calendar.your_calendar_entity', 'message')[2:-17] }} hat heute Geburtstag!**
1 Like

Thank you very much! :ok_hand:t3:

I had to play around with the code a bit as the part [2:-17] problably prevents something and basically I just don’t know what it does but if I leave that out the state_attr ist being fetched properly out of the message and it’s working now.

Probably me description in the starting post was not good enough as I ths particular Google calendar already provides the full sentence “John hat heute Geburtstag” and I assume [2:-17] hast something to do with which part of the message should be picked.

My new code is now:

alias: Geburtstagscheck
description: ''
trigger:
  - platform: time
    at: '10:00'
condition:
  - condition: state
    entity_id: calendar.geburtstage
    state: 'on'
action:
  - device_id: `[mysmartphone]
    domain: mobile_app
    type: notify
    title: Geburtstagserinnerung
    message: >-
      {{ state_attr('calendar.geburtstage', 'message') }} heute!
mode: single

It takes the string that results from the “state_attr(…” and then trims the first 2 characters and the last 17 characters. So you end up left with everything in between.

But I’m glad you got it working.

1 Like

Okay, now I understand the logic and I had to change the values to [0:-15] und now only the name (or first and last name) are fetched from the Google calendar message just as I wanted it to be.

Thank you very much again.

Everything’s working now and the grammar of the sentence “xxx hat heute Geburtstag!” is correct.

Now I’m diving into the possibibilites of intents to upgrade the notifications benefit with actionable buttons to directly jump into messaging apps, Duo or my phone’s contacts.

1 Like

Hi.

Thank you for this thread as it is a very good start point.

I use a condition template to get also notified 7 days before.

{% set time_to_bd =
  ((as_timestamp(states.calendar.anniversaires.attributes.start_time)
    - as_timestamp(now()))/60/60/24) | round(0) %}
{% if time_to_bd == 0 or time_to_bd == 7 -%}
True
{%- else -%}
False
{%- endif %}

The title of my notification looks like

Birthday in {{ ((as_timestamp(states.calendar.anniversaires.attributes.start_time)
        - as_timestamp(now()))/60/60/24) | round(0) }} days 🎂

Hope it helps.

1 Like