Automation triggered by certain calendar event name?

Thanks. For the low-techie that I am, Yaml is frustrating. I’ll watch the video :slight_smile:

1 Like

Hey everyone,

I finally had the time to connect my iOS calendar to Home Assistant. I have a number of options and triggers for camera notification. One should be that I will get notified when there is someone at the entrance, when I am working from home. When stumbling across this post, I use the code as suggested in the solution, however the condition returns as false, even though the calendar name shows the entry.

This is the code

alias: Home Office
choose:
  - conditions:
      - condition: template
        value_template: "{{ trigger.calendar_event.summary | slugify == 'Home Office' }}"
    sequence:
      - service: notify.mobile_app_oles_iphone
        data:
          data: {}
      - service: tts.cloud_say
        data:
          cache: false
          entity_id: media_player.sonos_one_sl
          message: Jemand ist im Eingang gesehen worden.
          options:
            voice: KatjaNeural

The event Home Office is shown in the calendar.

Bildschirmfoto 2024-05-29 um 11.01.22

I think I might need to specify the entity_id of the calendar, but I am unsure how to do this in a condition?

The filter slugify will never return the string “Home Office”.

Hm, okay. How can I then check if the calendar shows Home Office as an event today?

If the summary of the event will always be exactly “Home Office” you can just remove the slugify filter:

value_template: "{{ trigger.calendar_event.summary == 'Home Office' }}"

That’s what I have tried before, but the condition when being tested is still returning false.

I’ve also tried with eventS instead of event, no changes.

Bildschirmfoto 2024-05-29 um 13.00.46

Post the entire configuration for the automation.

Quite a bulky one. It’s only about the alias: “Home Office”. The rest works fine.

alias: Benachrichtigung_Kameras
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.eingang_person_occupancy
    to: "on"
    id: Eingang
  - platform: state
    entity_id:
      - binary_sensor.garten_person_occupancy
    to: "on"
    id: Garten_Person
    enabled: true
  - platform: state
    entity_id:
      - binary_sensor.garten_cat_occupancy
    to: "on"
    id: Garten_Katze
    enabled: true
condition: []
action:
  - alias: Eingang
    if:
      - condition: trigger
        id:
          - Eingang
    then:
      - service: camera.snapshot
        data:
          filename: /config/www/Eingang.jpg
        target:
          entity_id: camera.eingang
      - alias: Malin
        choose:
          - conditions:
              - condition: state
                entity_id: person.malin
                state: not_home
            sequence:
              - service: notify.mobile_app_malins_iphone
                data:
                  data:
                    attachment:
                      url: /local/Eingang.jpg
                  message: Person erkannt
                  title: 📹 Eingang
      - alias: Ole
        choose:
          - conditions:
              - condition: state
                entity_id: person.ole
                state: not_home
            sequence:
              - service: notify.mobile_app_oles_iphone
                data:
                  message: Person erkannt
                  title: 📹 Eingang
                  data:
                    attachment:
                      url: /local/Eingang.jpg
      - alias: Nacht Wochentag
        choose:
          - conditions:
              - condition: time
                after: "22:00:00"
                before: "06:00:00"
                weekday:
                  - mon
                  - tue
                  - wed
                  - thu
                  - sun
                  - fri
            sequence:
              - service: notify.familie
                data:
                  message: Person erkannt
                  title: 📹 Eingang
                  data:
                    attachment:
                      url: /local/Eingang.jpg
      - alias: Nacht Wochenende
        choose:
          - conditions:
              - condition: time
                after: "23:30:00"
                before: "08:00:00"
                weekday:
                  - sat
            sequence:
              - service: notify.familie
                data:
                  message: Person erkannt
                  title: 📹 Eingang
                  data:
                    attachment:
                      url: /local/Eingang.jpg
      - alias: Home Office
        choose:
          - conditions:
              - condition: template
                value_template: "\"{{ trigger.calendar_events.summary == 'Home Office' }}\""
            sequence:
              - service: notify.mobile_app_oles_iphone
                data:
                  data: {}
              - service: tts.cloud_say
                data:
                  cache: false
                  entity_id: media_player.sonos_one_sl
                  message: Jemand ist im Eingang gesehen worden.
                  options:
                    voice: KatjaNeural
  - alias: Garten_Person
    if:
      - condition: trigger
        id:
          - Garten_Person
    then:
      - service: camera.snapshot
        data:
          filename: /config/www/Garten_Person.jpg
        target:
          entity_id: camera.garten
      - alias: Malin
        choose:
          - conditions:
              - condition: state
                entity_id: person.malin
                state: not_home
            sequence:
              - service: notify.mobile_app_malins_iphone
                data:
                  data:
                    attachment:
                      url: /local/Garten_Person.jpg
                  message: Person erkannt
                  title: 📹 Garten
      - alias: Ole
        choose:
          - conditions:
              - condition: state
                entity_id: person.ole
                state: not_home
                enabled: true
            sequence:
              - service: notify.mobile_app_oles_iphone
                data:
                  message: Person erkannt
                  title: 📹 Garten
                  data:
                    attachment:
                      url: /local/Garten_Person.jpg
      - alias: Nacht Wochentag
        choose:
          - conditions:
              - condition: time
                after: "22:00:00"
                before: "06:00:00"
                weekday:
                  - mon
                  - tue
                  - wed
                  - thu
                  - sun
            sequence:
              - service: notify.familie
                data:
                  message: Person erkannt
                  title: 📹 Garten
                  data:
                    attachment:
                      url: /local/Garten_Person.jpg
      - alias: Nacht Wochenende
        choose:
          - conditions:
              - condition: time
                after: "23:30:00"
                before: "08:00:00"
                weekday:
                  - fri
                  - sat
            sequence:
              - service: notify.familie
                data:
                  message: Person erkannt
                  title: 📹 Garten
                  data:
                    attachment:
                      url: /local/Garten_Person.jpg
  - alias: Garten_Katze
    if:
      - condition: trigger
        id:
          - Garten_Katze
    then:
      - service: camera.snapshot
        data:
          filename: /config/www/Garten_Katze.jpg
        target:
          entity_id: camera.garten
      - alias: Malin
        choose:
          - conditions:
              - condition: state
                entity_id: person.malin
                state: not_home
            sequence:
              - service: notify.mobile_app_malins_iphone
                data:
                  data:
                    attachment:
                      url: /local/Garten_Katze.jpg
                  message: Katze erkannt
                  title: 📹 Garten
      - alias: Ole
        choose:
          - conditions:
              - condition: state
                entity_id: person.ole
                state: not_home
                enabled: true
            sequence:
              - service: notify.mobile_app_oles_iphone
                data:
                  message: Katze erkannt
                  title: 📹 Garte
                  data:
                    attachment:
                      url: /local/Garten_Katze.jpg
      - alias: Nacht Wochentag
        choose:
          - conditions:
              - condition: time
                after: "22:00:00"
                before: "06:00:00"
                weekday:
                  - mon
                  - tue
                  - wed
                  - thu
                  - sun
            sequence:
              - service: notify.familie
                data:
                  message: Katze erkannt
                  title: 📹 Garten
                  data:
                    attachment:
                      url: /local/Garten_Katze.jpg
      - alias: Nacht Wochenende
        choose:
          - conditions:
              - condition: time
                after: "23:30:00"
                before: "08:00:00"
                weekday:
                  - fri
                  - sat
            sequence:
              - service: notify.familie
                data:
                  message: Katze erkannt
                  title: 📹 Garten
                  data:
                    attachment:
                      url: /local/Garten_Katze.jpg
    enabled: true
mode: single

This is why the Community Guidelines says to post the complete automation…

None of your triggers are Calendar Event triggers, so your trigger variable will never contain the trigger.calendar_event.summary property. You need to use the calendar.get_events service call in your action block.

You might be able to just use a State condition that targets the calendar entity, but that is only reliable if the target calendar never has concurrent/overlapping events.

Okay, so from what I understand:

  • When the camera detects motion, it must call the calendar.get_events service to retrieve data.
  • This must be stored in an variable
  • The condition then checks if this variable is containing “Home Office”

Right?
If yes, how would I accomplish that? That goes far beyond what I did so far. :sweat_smile:

You have a lot of unnecessary repetition in there… I would use a few variables to make the automation more readable:

alias: Benachrichtigung_Kameras
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.eingang_person_occupancy
    to: "on"
    id: Eingang
  - platform: state
    entity_id:
      - binary_sensor.garten_person_occupancy
    to: "on"
    id: Garten_Person
  - platform: state
    entity_id:
      - binary_sensor.garten_cat_occupancy
    to: "on"
    id: Garten_Katze
condition: []
action:
  - variables:
      filename: "/config/www/{{trigger.id}}.jpg"
      camera: "camera.{{ trigger.id|slugify }}"
      url: "/local/{{trigger.id}}.jpg"
      message: "{{ 'Katze erkannt' if trigger.id == 'Garten_Katze' else 'Person erkannt'}}"
      title: "{{ 'Eingang' if trigger.id == 'Eingang' else 'Garten'}}"
  - alias: Take a Snapshot
    service: camera.snapshot
    data:
      filename: "{{filename}}"
    target:
      entity_id: "{{camera}}"
  - alias: If Entrance, Check calendar for Home Office, then send TTS
    choose:
      - conditions:
          - condition: trigger
            id:
              - Eingang
        sequence:
          - service: calendar.get_events
            target:
              entity_id:
                - calendar.malin_ole
            data:
              start_date_time: "{{ now() }}"
              end_date_time: "{{ today_at('23:59') }}"
            response_variable: agenda
          - delay: 1
          - condition: template
            value_template: |
              {{ 'Home Office' in agenda['calendar.malin_ole'].events | map(attribute='summary') | list }}
          - service: notify.mobile_app_oles_iphone
            data:
              data: {}
            continue_on_error: true
          - service: tts.cloud_say
            data:
              cache: false
              entity_id: media_player.sonos_one_sl
              message: Jemand ist im Eingang gesehen worden.
              options:
                voice: KatjaNeural
    continue_on_error: true
  - alias: Notify everyone not at home
    repeat:
      for_each: |
        {{ ['person.malin', 'person.ole']| reject('is_state', 'home') | map('replace', 'person.', '') | list }}
      sequence:
        - service: notify.mobile_app_{{repeat.item}}s_iphone
          data:
            data:
              attachment:
                url: "{{url}}"
            message: "{{message}}"
            title: "📹  {{ title}}"
    continue_on_error: true
  - alias: Nacht
    choose:
      - conditions:
          - or:
              - condition: time
                after: "22:00:00"
                before: "06:00:00"
                weekday:
                  - mon
                  - tue
                  - wed
                  - thu
                  - sun
              - condition: time
                after: "23:30:00"
                before: "08:00:00"
                weekday:
                  - fri
                  - sat
        sequence:
          - service: notify.familie
            data:
              message: "{{message}}"
              title: "📹  {{ title}}"
              data:
                attachment:
                  url: "{{url}}"
mode: single

EDITS:

  • Corrected typo in calendar service call.
  • Moved emoji to service calls

Phew, that is by far more advanced than anything I did before, thanks for giving me something to learn :). I just blindly copy and pasted this, changing the calendar to the right entity to test it and give this a proper study the next days. But the traces show this


:man_facepalming: I forgot to erase the duration line… I’ve corrected it in the post above.

I am sorry for being a pain and I feel to hijack this post which was really not my intention!

With the duration deleted it gives me this for the variables block

Fehler: TypeError: decoding to str: need a bytes-like object, LoggingUndefined found

Try erasing the camera emoji from the title variable… sometimes emojis and templates don’t agree with each other. You should still be able to use it, you just have to have it in each of the notification service calls like:

title: "📹  {{ title}}"

Thanks, I will give it a try :slight_smile:

I have a slight variation on this topic, where I wanted the name/title/summary of my calendar event to be a meaningful message that changes, but I use the description to filter the automation. In my case, I broadcast the summary to all my Google Home devices in the house.

My solution was to put a constant string in the description, in my case notify and then I have a meaningful name in my calendar for what I am being notified about. I’m not sure if this is useful, but I had trouble modifying the condition for where summary contains notify, and this was an easy way to get around that because I don’t use the description for these events in my google calendar.

alias: Notify Calendar Event
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "0:0:0"
    entity_id: calendar.family
condition:
  - condition: template
    value_template: "{{ trigger.calendar_event.description == \"notify\" }}"
    enabled: true
action:
  - action: script.audio_notificaiton
    metadata: {}
    data:
      message: "\"{{trigger.calendar_event.summary}}\""
mode: single

This may be slightly off topic, or at least tangental to this, but this thread was the first thing I found on Google.