Hoping to get a little help on writing an automation that involves the google calendar integration (Calendar entity)

Hello all,

Can someone here give me a little guidance on how to write the following automation or an example so that I can see how it is done. I believe it requires a value template trigger? I don’t really understand all of this just yet so I’m really not sure what is the right way to do this.

What I would like to do is get home assistant to send a push notification when an even on the calendar is titled “Heartworm Medicine”. I’m hoping the below screenshot can help someone show me how to do this. I have determined the attribute “message” is the title of the event on the calendar.

Something like this maybe!

automation:
  alias: Heartworn Tablet Notification
  trigger:
    - platform: calendar
      event: start
      entity_id: calendar.holidays_in_united_states
  condition:
    - condition: template
      value_template: "{{ 'Heartworm Medicine' in trigger.calendar_event.summary }}"
  action:
    …..
  mode: queued

You may need to experiment with the template as it could be calendar_event or possibly even calendar_event.summary not 100% sure on that to be honest.

I appreciate that. That is what I was reading also that it could be either of those. Thank you for your response @rossk. If you don’t mind, in order to help me learn/ understand, I would like to ask a follow up question that I’m a little confused about. And keep in mind, I know nothing, haha.

I kind of thought we would use something that included state attribute. message = “Heartworm Medicine”, am I way off base with a thought like this? I feel like I have seen the idea of using the attributes name like that before in automations. Are calendars just treated differently? I guess, I felt like the using “event” was out of left field by looking at the states and attributes area of the states tab.

Now that I’m looking at it, I thought we would use a state of “on” and an attribute of message= “Heartworm Medicine” in the automation somehow. I don’t know how to do it this way and maybe it’s a terrible idea but I figured you could expand on what I am thinking if it is even valid. (I have no clue what I am doing yet in Home Assistant and I can already tell you know way more than I do).

Thank you for any conversation @rossk!!

I will be honest and the reason I was unsure as the whole event / summary above is that I dont use the generic calendar, I use the google calendar integration so from looking at my setup and looking at the generic ha calendars there appears to be some differences.

Also to complicate matters slightly further, I had google calendars setup originally in yaml before it was transferred over to the GUI. Therefore I created from one google calendar multiple sensors that basically toggled off / on when ever a particular word or phrase was present within the google event.

Like this:

 entities:
  - device_id: recycle_bin
    ignore_availability: true
    name: Recycle Bin
    track: true
    search: 'recycle'
  - device_id: general_bin
    ignore_availability: true
    name: General Bin
    track: true
    search: 'general'
  - device_id: garden_bin
    ignore_availability: true
    name: Garden Bin
    track: true
    search: 'garden'

So my trigger for automation would look something like this:

  trigger:
  - platform: state
    entity_id: binary_sensor.recycle_bin_tomorrow
    from: 'off'
    to: 'on'

If I look at my calendar attributes I have the following as an example:

message: recycle bin
all_day: true
start_time: '2022-07-01 00:00:00'
end_time: '2022-07-02 00:00:00'
location: ''
description: 'description of the entry if I added one' 
offset_reached: false
friendly_name: Recycle Bin

So I could for example use the following in an automation action: (TTS, Notify Etc)

"House notice. The {{ state_attr('calendar.recycle_bin', 'message') }} 
is due to be collected early tomorrow. Please put it out before going to bed"

If I was you I would read the calendar documentation again and have a look at your calendars and the attributes listed. However i note they advise against using attributes.

Sorry I cant be much more help on the generic calendar side of things.

I do as well (I think my post title says that). That is what those calendars are or how I got them into HA was through the integration. I will read the rest of your post shortly. Thank you so much for helping me get this figured out.

Yeah, I am only interested in getting this to work with the google calendar integration.

I follow you here. I would like to do this also but the below is what is in my “google_calendars.yaml” and it doesn’t seem to work. (I added this to the .yaml file after it was already showing in the integrations page after a home assistant update, maybe this is why it isn’t working for me, if you have any ideas on this, I would be much appreciative)— when I search heartworm in my states developer tab, nothing related to a calendar pops up sadly.

- cal_id: [email protected]
  entities:
  - device_id: xxx_gmail_com
    ignore_availability: true
    name: [email protected]
    track: true
  - device_id: heartworm
    name: heartworm
    track: true
    search:: #heartworm

Did I possibly screw myself by updating home assistant to the OS version that required the GUI configuration and now the part that really makes this worth something may not be doable for me? It looks like anytime I try to add an entity to within the google_calendars.yaml, and then restart HA, the integration recreates the original calendar entry at the bottom of the same file (almost as if it can’t handle the idea we both know about after the update- this is a bummer). And I assume this means, you won’t be able to add anymore either if yours is now showing in the integrations GUI now? (The integration support… available for users before…)

So in your example. Your integration is already showing in the the integrations page? And you are not using the “google_calendars.yaml” anymore? Or you are still using the google_calendars.yaml while it is also showing in the integrations page? Have you added any additional “devices” after the integration has started showing up in your GUI?

The entities you are showing in your code post. Where do I put those? (In google_calendars.yaml) under the calendar like I have?

Lastly, how do you get the below to trigger. I feel like I’m missing something that you are trying to show me.

binary_sensor.recycle_bin_tomorrow

The last thing I believe I have for this topic and I’ll stop beating it like a dead horse, is can you show me how to write an automation that runs when the below occurs.

{{ state_attr(‘calendar.recycle_bin’, ‘message’)} = “Heartworm” and the state of the [email protected] calendar goes from “off” to “on” (this second part may be redundant because to my understanding it goes to on anytime your inside the time period of an active calendar event)

I believe the below is what you orgininally gave me but it was for a generic calendar and not our google calendar. I think the value template would need to be different but I just don’t understand this stuff good enough yet.

automation:
  alias: Heartworn Tablet Notification
  trigger:
    - platform: calendar
      event: start
      entity_id: calendar.holidays_in_united_states
  condition:
    - condition: template
      value_template: "{{ 'Heartworm Medicine' in trigger.calendar_event.summary }}"
  action:
    …..
  mode: queued

For the value_template, would this work?:

    value_template: >
      {%- set event=states.calendar.xxx@gmail_com.attributes.message %}
      {%- if event == "Heartworm Medicine" %}
        true
      {%- endif -%}

EDIT (CODE PASTE ABOVE) From below resource at time 16:18

Sorry my bad, I have been chatting with about 3 different people recently about calendars and may have crossed some wire here!

If you are running 2022.6 then I believe the google_calendars.yaml is now null and void. The .yaml I listed in one of the above comments was what my original .yaml looked like before it was automatically pulled in to the GUI when I updated to 2022.6. After update I deleted the old .yaml out as it has no affect and is ignored by HA I believe.

Following automatic transfer to GUI I still luckily had all the original sensors / entities to use and nothing was lost (someone else I have been talking to lost theirs when updating also)

I think if you had .yaml before and it was automatically imported it may have not imported correctly. I believe if you restore to 2022.5 and put your .yaml back (making sure its correct - happy yo check if you choose this route) then you may get the sensors imported correctly when updating to 2022.6 like I did.

Yes

Correct - once updating to 2022.6 the old .yaml is ignored and I deleted it.

Not possible unless I roll back and replace the .yaml as mentioned above. I can and have added new google calendars since, however these dont show up as sensors like they did in the .yaml way.

You wont be able to unless you have the old .yaml entries imported like I did, otherwise you stuck using the new method.

The above examples in the previous post are snippets of me using the pulled in calendar sensors I previously created in .yaml and were (luckily for me imported).

I do however have a new calendar that I have added since and use this for generic announcements / automations. For example:

alias: Google Calendar Notification
description: ''
trigger:
  - platform: calendar
    event: start
    entity_id: calendar.home_assistant
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: person.rossk
            state: home
        sequence:
          - service: tts.google_cloud_say
            data:
              entity_id: media_player.google_everywhere
              message: >-
                Hi guys. I have the following google calendar event to inform
                you about. The title of the event is, {{  state_attr('calendar.home_assistant', 'message') }}. 
                And the description is {{ state_attr('calendar.home_assistant',
                'description') }}
          - if:
              - condition: state
                entity_id: sensor.pc_user_state
                state: InUse
            then:
              - service: notify.rossk_office_pc_notify
                data:
                  message: '{{ state_attr(''calendar.home_assistant'',  ''description'') }}.'
      - conditions:
          - condition: state
            entity_id: person.rossk
            state: away
        sequence:
          - service: notify.alarm_notify_group
            data:
              title: 'Google Calendar Event:'
              message: >-
                The title of the event is, {{ state_attr('calendar.home_assistant', 'message') }}
                And the description is {{ state_attr('calendar.home_assistant',
                'description') }}
    default: []
mode: single

OK I have just had a little play with the generic google calendar and to answer your question I think the following is what you may be looking for:

trigger:
  - platform: calendar
    event: start
    offset: '0:0:0'
    entity_id: calendar.holidays_in_united_states
condition:
  - condition: template
    value_template: '{{ "Heartworm Medicine" in trigger.calendar_event.summary }}'
action:
  - service: .....

This is based on having the Heartworm Medicine in the title of the actual google calendar entry.

I have tested this my end and confirmed the condition works correctly.

No problem. I completely get it.

I think you are correct. It makes me think that key word situation is dead now also. (creating new ones at least)

You lucky duck.

I bet you are correct. I don’t want to go backwards so I shall work with what exists now.

Thank you for being so concise/ detailed. Sorry I had to ask 10 times.

Now I understand. I will probably work off of titles of events knowing the limitations that I am working around.

I understand.

This is awesome and very helpful for helping me understand how to use all of this.

Thank you so much for helping me with all of this! I am pretty new to HA and I have learned the water can be deep but you and others are helping me learn everyday. I am still very new to the concept of a “value_template” and still don’t fully understand all you can do with them. Thank you for showing me how to do all of this.

Yeah, I wish I could work off of the old method (pre 2022.6), as you are, but I will just look forward and I think I can make it work good enough using the titles like you have shown me. @rossk I really do appreciate your help with this!!

1 Like