switched sections as advised by @rpitera original post below
Hey there,
im just started diving into this whole home automation / home assistant stuff. Since I only have a switch and a shutter as hardware components for now, I’ve been looking into the other sensors like Google Calendar Event integration. Like many other people, I am not a fan of the offset feature that requires the data to be in the calendar title, especially since im subscribing to calendars that I cannot edit. I spent quite some time researching on this forum and on GitHub repositories for a workaround, but did not find a complete solution that worked for me.
So after putting together the bits and pieces I found, I feel like I have a very beginner friendly offset script. Since more than a few people seemed to be looking for this, I wanted to share this to spare some other beginners the research work.
SENSORS
sensor:
- platform: time_date
display_options:
- 'date_time'
- platform: template
sensors:
cal_alert_time:
entity_id: sensor.date__time
value_template: '{{ (as_timestamp(states.calendar.abfallkalender.attributes.start_time) - as_timestamp(now()) ) }}'
friendly_name: 'Alert Time'
I created a time_date sensor, which refreshes once every minute. This is needed to have a constant refresh on our cal_alert_time sensor
The cal_alert_time sensor calculates the time between the event start and right now in seconds and is refreshed every minute due to the sensor.date__time
AUTOMATION
- alias: Calendar Alert
initial_state: true
trigger:
- platform: numeric_state
entity_id: sensor.cal_alert_time
below: '21600'
above: '21500'
action:
- service: notify.SMTP_Notifier
data:
title: 'Reminder: {{states.calendar.YOURCALENDAR.attributes.start_time}} {{states.calendar.YOURCALENDAR.attributes.message}}'
message: ' '
A simple numeric_state trigger that is executed, when we hit the desired offset (value between below and above).In this case, we would be reminded 15 minutes (60 seconds * 15 = 900) before the event starts via email.
The ‘above’ statement is only there to make sure we dont get the mail again after a HA restart, not sure its necessary.
I hope this helps maybe one or two beginners like me somewhere down the road. Sorry for the formatting, the auto format in here somehow mixes things up.
Feel free to point out mistakes or possible improvements.