Next day check for google calendar

im trying to create a automation with my google calendrer that will check the next day, to see if my kids do not have a holiday active. I created a toggle helper that will turn on or off depending on the state of the calendrer. I tested the automation and it did not work. I wanted to get help to see what did I miss with my automation: Yaml:

alias: School Calendrer Toggle
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "20:0:0"
    entity_id: calendar.kids_school
    id: Kids start
    alias: Kids Start
  - platform: calendar
    event: end
    offset: "0:0:0"
    entity_id: calendar.kids_school
    id: Kids End
    alias: Kids End
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Kids start
        sequence:
          - service: input_boolean.turn_on
            data: {}
            target:
              entity_id: input_boolean.kids_school_helper
      - conditions:
          - condition: trigger
            id:
              - Kids End
        sequence:
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id: input_boolean.kids_school_helper
mode: single

According to the documentation for Calendar Trigger, if you want it to trigger 20 hours before the event, it should be a negative value.

trigger:
  - platform: calendar
    event: start
    offset: "-20:0:0"
    entity_id: calendar.kids_school
    id: Kids start
    alias: Kids Start
alias: School Calendrer Toggle
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "-20:0:0"
    entity_id: calendar.kids_school
    id: Kids start
  - platform: calendar
    event: end
    offset: "0:0:0"
    entity_id: calendar.kids_school
    id: Kids End

Yes, that’s correct; use a negative value to trigger before the event.

so basically if there is a event the next day turn on and if there is no event turn off

is the kids end school event correct as well?

It’s correct if you don’t want any offset for when the event ends.

not sure for end event I want if there is no holiday to to turn off the toggle. Also if there is a holiday it turns off the toggle when the holiday ends?

The way you designed it, it will turn on the Input Boolean 20 hours before the start of the holiday event and turn it off when the holiday event ends.

If there’s no holiday event the next day, it doesn’t turn it on or off.


Do these events last several hours or are they created as “all day” events?

all day event. I imported my kids school calendrer into my google calendar

An all-day event starts at 00:00 on the day of the event and ends 24 hours later at 00:00of the next day.

That means your automation will turn on the Input Boolean 20 hours before the holiday event and turn it off at the end of the next day. In other words, the Input Boolean will be on for 20 + 24 = 44 hours.

Is that how you want it to work?

Yes, that is it. Example would be labor day coming up on sept 9. the calendrer will check on Sunday and turn the toggle on due to labor day being on Monday. then check on labor day off for next day and if no holiday/event. It will turn toggle off

Not exactly.

Your automation doesn’t “check” the calendar for anything. Your automation is triggered by events in your calendar. If an event exists, it will be detected by your automation’s two Calendar Triggers. If there’s no event, the automation is not triggered.

I asked chatgpt for a automation and it came up with this but i get a error on this one?

Triggered manually at August 15, 2023 at 6:15:42 PM

Call a service 'Input datetime: Set' on

Call a service 'Calendar: List event' on automation.check_calendar_events

Stopped because an error was encountered at August 15, 2023 at 6:15:43 PM (runtime: 0.06 seconds)

Script requires 'response_variable' for response data for service call calendar.list_events

Yaml script:

alias: Check School Calendar Events and Toggle
description: ""
trigger:
  - platform: time
    at: "08:00:00"
action:
  - service: input_datetime.set_datetime
    data:
      entity_id: input_datetime.next_day_date
      datetime: "{{ (now().date() + timedelta(days=1)).strftime('%Y-%m-%d') }}"
  - service: calendar.list_events
    data:
      entity_id: calendar.kids_school
      start_time: "{{ states('input_datetime.next_day_date') + 'T00:00:00' }}"
      end_time: "{{ states('input_datetime.next_day_date') + 'T23:59:59' }}"
    target:
      entity_id: automation.check_calendar_events
mode: single
alias: School Calendrer Toggle Off
description: ""
trigger:
  - platform: calendar
    event: end
    offset: "--20:0:0"
    entity_id: calendar.kids_school
condition: []
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.kids_school_helper
mode: single
alias: School Calendrer Toggle On
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "-20:0:0"
    entity_id: calendar.kids_school
condition: []
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.kids_school_helper
mode: single

I thought your original problem, in your first post, has been solved by simply making the offset value negative. However, now you’re posting more non-functional automations. What’s your goal here?


NOTE

This is obviously wrong:

offset: "--20:0:0

i wanted to create an automation to check if kids google calendrer has a event the next day. if there is a event turn off toggle and if there is no event turn on toggle i made. That way I can just make a simple automation for the toggle.

Have a look at the example in Service Calls - Home Assistant

That’s exactly what the automation in your first post does. The only mistake it contains is that you used a positive 20, instead of negative 20, for offset.

I will test my first automation out and see how it runs.