Local Calendar with automation

Have you considered using the Google Calendar Integration ? I do and it does all (and more) that you seem to need.

You do not need a calendar for each holiday.

Explain what you are trying to do and someone here can likely help you.

If I have a holiday calendar and have (2) events (Halloween) and Christmas. I want the Halloween event automation to run for one day with a start & end time. I want the Christmas automation to run for a couple of weeks with a start and end time. When I create the automation for Halloween only the Holiday calendar is specified. What stops the Christmas automation from running if it does not know which date triggered the automation? I will have to do some testing. I don’t know how to explain it better.

The following automation sets a light’s color, at sunset, for specified dates (single day or a range of days). It does this without using a Calendar.

As with everything in HA, there are many ways to accomplish your goal, so it is difficult to offer help that pertains to your specific setup if you don’t provide the details…

Are these all-day/multi-day events, or discrete daily events for the light schedule?

Posting your current automation would help us understand how you are using the calendar.

All I have is some test code. It does go on at the calendar date and time.
I disabled the outside strings for testing. Only the inside test string is enabled.

alias: Test2 WLED Calendar
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "0:0:0"
    entity_id: calendar.test
  - platform: time
    at: "09:00:00"
    id: Turn_off
condition: []
action:
  - service: select.select_option
    data:
      option: Fireworks
    target:
      entity_id: select.wled_garage_preset
    enabled: false
  - service: select.select_option
    data:
      option: Fireworks
    target:
      entity_id: select.wled_center_preset
    enabled: false
  - service: select.select_option
    data:
      option: Fireworks
    target:
      entity_id: select.wled_bedroom_preset
    enabled: false
  - service: select.select_option
    data:
      option: Fireworks
    target:
      entity_id: select.wled_test_preset
  - delay:
      hours: 1
      minutes: 0
      seconds: 0
      milliseconds: 0
  - service: select.select_option
    data:
      option: "Off"
    target:
      entity_id: select.wled_test_preset
    alias: Turn off Test WLED
mode: single

You can check the condition for halloween or christmas if you add that in the summary text of the calendar event. You can then use the “trigger.calendar_event.summary” or “trigger.calendar_event.description” to act upon. You can set a sensor to christmas or halloween when appropriate.

This is how I calculate set my alarmclock and day-type based on the type of day as given in the calendar. Maybe it gives you an idea how to use the trigger.calendar_event entitites.

alias: CALENDAR Set input_select.day_type
description: set alarmsomneo on trigger (midnight)
trigger:
  - platform: calendar
    event: start
    offset: "0:0:0"
    entity_id: calendar.schedule
condition: []
action:
  - service: notify.persistent_notification
    data:
      message: >-
        Event {{ trigger.calendar_event }} Summary {{
        trigger.calendar_event.summary }} @ {{ trigger.calendar_event.start }}
    enabled: false
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ 'WORK' in trigger.calendar_event.summary }}"
        sequence:
          - service: input_select.select_option
            data:
              option: work
            target:
              entity_id: input_select.day_type
          - service: number.set_value
            data:
              value: "07"
            target:
              entity_id: number.somneo_alarm0_hours
            enabled: false
          - service: number.set_value
            data:
              value: "15"
            target:
              entity_id: number.somneo_alarm0_minutes
            enabled: false
          - service: time.set_value
            data:
              time: "07:15:00"
            target:
              entity_id: time.somneo_alarm0_time
          - service: switch.turn_on
            data: {}
            target:
              entity_id: switch.somneo_alarm0
      - conditions:
          - condition: template
            value_template: "{{ 'FREE' in trigger.calendar_event.summary }}"
        sequence:
          - service: input_select.select_option
            data:
              option: free
            target:
              entity_id: input_select.day_type
          - service: number.set_value
            data:
              value: "08"
            target:
              entity_id: number.somneo_alarm0_hours
            enabled: false
          - service: number.set_value
            data:
              value: "30"
            target:
              entity_id: number.somneo_alarm0_minutes
            enabled: false
          - service: time.set_value
            data:
              time: "08:30:00"
            target:
              entity_id: time.somneo_alarm0_time
          - service: switch.turn_on
            data: {}
            target:
              entity_id: switch.somneo_alarm0
      - conditions:
          - condition: template
            value_template: "{{ 'HOLIDAY' in trigger.calendar_event.summary }}"
        sequence:
          - service: input_select.select_option
            data:
              option: holiday
            target:
              entity_id: input_select.day_type
          - service: switch.turn_off
            data: {}
            target:
              entity_id: switch.somneo_alarm0
      - conditions:
          - condition: template
            value_template: "{{ 'MANUAL' in trigger.calendar_event.summary }}"
        sequence:
          - service: input_select.select_option
            data:
              option: manual
            target:
              entity_id: input_select.day_type
mode: queued

For Christmas are you planning to also have an event each day, or just one 2-week long event? If the latter, you will also need to tell us when the lights should be turned on.

One long one, then change for New years for a couple of days.

That makes it a little more convoluted… If you’re going to do it that way, you will need to include an additional trigger to handle turning them on at the appropriate time.

alias: Test2 WLED Calendar
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "0:0:0"
    entity_id: calendar.holiday
    id: 'on'
    variables:
      h: "{{ trigger.calendar_event.summary }}"
  - platform: time
    at: "18:00:00"
    id: 'on'
    variables:
      h: "{{ state_attr('calendar.holiday', 'message') }}"
  - platform: time
    at: "09:00:00"
    id: 'off'
condition:
  - or:
    - condition: state
      entity_id: calendar.holiday
      state: 'on'
    - condition: trigger
      id: 'off'
action:
  - variables:
      holiday: "{{ "Off" if trigger.id == 'off' else h}}"  
      preset:
        "Halloween": Fireworks
        "Christmas": Fireworks
        "Off": "Off"
  - service: select.select_option
    data:
      option: "{{ preset.get(holiday) }}"
    target:
      entity_id: 
        - select.wled_garage_preset
        - select.wled_test_preset
        - select.wled_bedroom_preset
        - select.wled_center_preset
mode: single

Personally, I would use individual events. It makes it a lot simpler, and it only takes a couple seconds to have the event repeat daily for x days, when you are setting it up in the calendar.

Automation for Discrete Events

alias: WLED Holiday Lights Calendar
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "0:0:0"
    entity_id: calendar.holiday
    id: 'on'
  - platform: calendar
    event: end
    offset: "0:0:0"
    entity_id: calendar.holiday
    id: 'off'
condition: []
action:
  - variables:
      preset:
        "Halloween": Fireworks
        "Christmas": XMas
  - service: select.select_option
    data:
      option: "{{ "Off" if trigger.id == 'off' else preset.get(trigger.calendar_event.summary) }}"
    target:
      entity_id: 
        - select.wled_garage_preset
        - select.wled_test_preset
        - select.wled_bedroom_preset
        - select.wled_center_preset
mode: single

That makes sense, I will go with the repeat method. I am still in the R&D phase, so I did not think it through. This all looks very good.

Is there anyway to use the calendar start and end Date & time to control the automation?
Example: At start, set the preset fireworks
at end, set the preset to off.

Yes, that’s the usual way to employ a Calendar Trigger.

See my previous post…

image

Just made some tweaks and this works great. Just what I am looking for.
Thank you very much.

I know many programing languages, but yaml is not one of them. Starting to do some YT tutorials. Just seeing available variables and events does not tell you how to use them.

YAML is a markup language.

Home Assistant has adapted it for its own purposes. It creates a scripting “language” by combining YAML with Jinja2, a templating language, and some python.

That’s why it can be daunting to learn Home Assistant’s scripting language because it’s unique to Home Assistant and is comprised of four different sources: YAML, Jinja2, python, and Home Assistant’s own scripting documentation.

I still fail to understand why you would not just use the Google Calendar Integration. A bit of a hassle to do the authentication but once done you can easily use your calendar in HA.

Do you recall which Reply button you clicked in order to post your reply?

  1. The one in the bottom right corner of my message (or GaryK4’s message)?

  2. The one at the bottom of the topic?

Because it appears like you clicked the Reply button in my message which directs your reply to me.
Screenshot_20231009-101512~2

However, your reply appears to have been meant for GaryK4 (since it’s unrelated to anything I wrote about YAML) in which case it would be best to click the Reply button in GaryK4’s message.

If you clicked on the Reply button at the very bottom of the topic, then there may be something wrong with the forum software (or my understanding of how it works) because I am not subscribed to this topic. Therefore I should only be notified of replies made directly to my posts and no one else’s posts in this topic.

Getting closer. I tried to convert from a preset to a playlist. The playlist allows playing multiple presets, so it gives me more options. I have it running repeat indefinitely.
I created (2) playlists Xmas and Off. When running the Off playlist, it stops Xmas.
This works in a Card, but not in the below yaml that I modified from preset to playlist.
When manually trying to run the automation, I get an error.
Error: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘calendar_event’

Not sure what I did wrong?

alias: WLED Playlist
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "0:0:0"
    entity_id: calendar.wled_schedule
    id: "on"
  - platform: calendar
    event: end
    offset: "0:0:0"
    entity_id: calendar.wled_schedule
    id: "off"
condition: []
action:
  - variables:
      playlist:
        Christmas: Xmas
  - service: select.select_option
    data:
      option: >-
        {{ 'Off' if trigger.id == 'off' else
        playlist.get(trigger.calendar_event.summary) }}
    target:
      entity_id:
        - select.wled_test_playlist
mode: single

The trigger variable only exists for actual triggers, it is not populated when you use the “Run” button or automation.trigger service.

Automation with the local calendar is working great!
Thanks to all responders. Could not have done it without you.

1 Like