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!**
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.
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.
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.