Google Calendar event for today

Hi everyone

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.

So, do I put these in my configuration.yaml file, or in automation.yaml (or somewhere else)?

Personally, I have a sensors.yaml file that they’re in and referenced from configuration.yaml with:

sensor: !include sensors.yaml

Ok, I did that. So how do I trigger it now?
Sorry for the (maybe dumb) question(s), but like I said --> newbie :slight_smile:

You’re best bet is reading up on Automations in HA here: https://www.home-assistant.io/docs/automation/

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 :slight_smile:

Hope this sets you in the right direction. Definitely a bit of a process / learning curve - but SO worth it!

So, this is what I have in my sensors.yaml file:

- 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

Your best bet is to test manually using developer tools - template section: https://URL-TO-YOUR-HA/developer-tools/template

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 :wink:

1 Like

If you are just trying to get a school/work day sensor you could use the workday sensor https://www.home-assistant.io/integrations/workday/

gives you a simple binary sensor. I use it to control my lights for the days I need to get up.

Won’t help for other events however.

1 Like

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)


As you can see, it says it’s off since 11:15, while I put in an event at 11:26, so it didn’t change. How could this be happening?

Caveats for my installation.

  1. I’m not using Node-RED
  2. I’m only looking at daily events, so haven’t gotten more granular about specific start/stop times - though theoretically should work very similarly.

Sorry I can’t assist further.

No problem of course :slight_smile:. It’s only just frustrating if one is not able to find why something is happening :wink: