I get some problems to get one of the two templates working. I’m pretty sure I have to replace the “work” or in your case “treinbestuurder_be” with my calendar. But I don’t know how exactly. Replacing it with the calendar ID gives me an error, using the entityid of a calendar sensor makes the template sensor to always say “unavailable” even when there is no event planned.
Thanks for your help!
If you need more information I am able to share it.
Many, many thanks to the above posters for this.
I’m relatively new to HA and writing my own automations and was stuck with parsing calendar data for just his kind of issue. I just wanted a quick reminder - on the day - that a football match was scheduled.
My original thought was to check the date of start_time against the date portion of {{now()}}, but my limited knowledge of syntax/command structure just floored me so I left it. Came back today with a different search-term which led me here.
Here’s what I ended up with: ( calendar is a google calendar )
The idea of the ‘<12’ is that triggering this as any time before 8pm on a matchday would result in the condition being true and therefore send the message. I run the automation @10:30am and therefore should pick up any kickoff up to 10pm the same day.
- id: '1635593344340'
alias: Football Reminder
description: Telegram reminder on the day of a match with time of match
trigger:
- platform: time
at: '10:30'
condition:
- condition: state
entity_id: binary_sensor.footy_today
state: 'on'
action:
- service: notify.[MY-TELEGRAM_BOT]_tg_bot
data:
message: Footy today {{as_timestamp(strptime(state_attr("calendar.manchester_united",
"start_time"),"" ))| timestamp_custom('%H:%M') }}
mode: single
Know this is an old one, am setting this up so I can set trigger x mins before school, x mins before school ends, then will do the same for work, have the following sensors set up which seem to work, only issue I seem to be getting is if I change start/finish time of an event on my google calendar, it updates on calendar integration within HA but the mins left on sensors dont seem to change until I restart server, is this normal? Any way to make it automatically update with new times without needing to do a restart? thanks
- platform: template
sensors:
timeuntilschool:
friendly_name: Time until school
value_template: >-
{% if states.calendar.school.attributes.start_time %}
{{((as_timestamp(states.calendar.school.attributes.start_time) - as_timestamp(now())) / 60) | default(99) | int }}
{%- else -%}
0
{%- endif %}
- platform: time_date
display_options:
- 'time'
- platform: template
sensors:
timeuntilschoolends:
friendly_name: Time until school ends
value_template: >-
{% if states.calendar.school.attributes.end_time %}
{{((as_timestamp(states.calendar.school.attributes.end_time) - as_timestamp(now())) / 60) | default(99) | int }}
{%- else -%}
0
{%- endif %}
For all using this, we can now do this cleanly inside the calendar integration by just using offset
automation:
trigger:
- platform: calendar
# Possible values: start, end
event: start
# The calendar entity_id
entity_id: calendar.personal
# Optional time offset to fire a set time before or after event start/end
offset: -00:15:00