I’m pretty new in Home Assistant, but I want to learn. I (think I) successfully implemented the Google Calendar in Home Assistant (have the calendar yaml file etc). Now I want to check if there is an event on my calendar for a given day/time and then have it do something (for example send me a notification). I’ve searched around a bit on the internet, but can’t find it exactly. Hope you guys (and girls) can help me out a bit?
you should be seeing entities in HA starts with calendar. if the implementation is correct.
so if there is an event at this moment, the entity would show on, and otherwise it would be off.
then you need to play little bit offset and other config parameters of the calendar.
here is another thread maybe can give you ideas Google Calendar Offset Question
I built a few custom sensors to ‘read’ my google calendar. First sensor checks the timestamps of an event to see if it’s ‘on’ or ‘off’
- platform: template
sensors:
date_now_gcisd:
entity_id: sensor.date
value_template: >
{% if states('calendar.calendar') == 'off' %}
off
{% elif now().timestamp() >= as_timestamp(strptime(states.calendar.calendar.attributes.start_time, '%Y-%m-%d %H:%M:%S')) and now().timestamp() <= as_timestamp(strptime(states.calendar.calendar.attributes.end_time, '%Y-%m-%d %H:%M:%S')) %}
on
{% else %}
off
{% endif %}
I also then have another sensor to check the name of the event and see if a keyword(s) matches
date_schoolday:
value_template: >
{% set ct = states('sensor.date_time') %}
{% set ct = as_timestamp(strptime(ct,'%Y-%m-%d, %H:%M')) %}
{% if 'Saturday' in ct | timestamp_custom("%A") %}
off
{% elif 'Sunday' in ct | timestamp_custom("%A") %}
off
{% elif is_state("sensor.date_now_gcisd","on") and 'holiday for all students' in states.calendar.calendar.attributes.message.lower()%}
off
{% elif is_state("sensor.date_now_gcisd","on") and 'spring break' in states.calendar.calendar.attributes.message.lower()%}
off
{% else %}
on
{% endif %}
So first sensor checks if there’s an active event (on/off), second sensor then checks event name/text for keywords.
These are trying to ascertain if it’s a school day for my kids or not. Hopefully you can adjust for your purposes.
Personally, this schoolday sensor for me is a ‘CONDITION’ in a morning automation.
TRIGGER:TIME - Everyday at 5:30am CONDITION:date_schoolday sensor is ON ACTION: Turn on my kitchen lights
So the sensor doesn’t TRIGGER / START the automation, but it can stop it from running. I don’t want my kitchen lights on at 5:30am if it’s not a school day
Hope this sets you in the right direction. Definitely a bit of a process / learning curve - but SO worth it!
- platform: template
sensors:
event_now:
value_template: >
{% set ct = states('sensor.date_time') %}
{% set ct = as_timestamp(strptime(ct,'%Y-%m-%d, %H:%M')) %}
{% if 'Saturday' in ct | timestamp_custom("%A") %}
off
{% elif 'Sunday' in ct | timestamp_custom("%A") %}
off
{% elif is_state("sensor.date_now_gcisd","on") and 'Test' in states.calendar.my_calendar_name.attributes.message.lower()%}
off
{% else %}
on
{% endif %}
and then I made an automation with the things you said @Markus99 (only I set the time at 9:00am), but it doesn’t work
edit: ok, if I trigger it manually, I get the notification, doesn’t happen autmatically though
From there you can see the result and update the template accordingly. Without seeing the actual event(s) in your calendar it’s difficult to give you exact code. Trying to give you a baseline / framework to edit to suit your needs.
HA is definitely a platform where getting your hands dirty and understanding the building blocks is crucial for success. Teach a man to fish vs. give him a fish
Still not getting this, tried around, now with Node-RED which seems much easier, but most of the times the state of the calendar doesn’t change from off to on, even if there’s an event in my calendar (I created a separate calendar just to test things out, so it’s totally empty unless I put an event in it)