Skip to content

Tips & Tricks: Use Calendar Events to Set Chore Due Dates

ccpk1 edited this page Feb 28, 2025 · 1 revision

πŸ“ Tips & Tricks: Use Calendar Events to Set Chore Due Dates

These automations are NOT part of the KidsChores Integration but are designed to work with it to dynamically set chore due dates based on events in your calendar. This is a custom approach that allows chore schedules to be updated automatically by simply modifying calendar events, without needing to edit the individual chores.

This method should work with any calendar that has been integrated into Home Assistant. There could be slight naming differences in the data returned, so be aware that small adjustments may be required.


πŸ“Œ Why Use a Calendar for Chores?

  • βœ… Flexible Scheduling: Chore due dates adjust dynamically without going into Home Assistant or KidsChores.
  • βœ… Easy Updates: Simply update the calendar entry to change the due date.
  • βœ… Recurring Events: Leverage recurring events to automate repeating chores.

πŸ“Œ 1. Triggering Chore Due Dates from a Calendar

Purpose:

This automation looks at upcoming events on your calendar and if it finds the event specified, it will take action to update the due date of the chore you identified.

How It Works:

  • Trigger: No trigger is defined in the example, so you can add that when you create the automation (e.g., daily, weekly).
  • Lookup: Searches the next 21 days for the first event matching the calendar_event_name that you specified.
  • Action: Sets the due date for the chore you specified in chore_name using the kidschores.set_chore_due_date service.

Example Automation:

alias: "Set Garbage Night From Calendar"
description: ""
triggers: []  # Define your own trigger, such as running daily or weekly
conditions: []
actions:
  - target:
      entity_id: calendar.parent_name  # CHANGE: Set to your calendar entity
    data:
      start_date_time: "{{ now().isoformat() }}"
      end_date_time: "{{ (now() + timedelta(days=21)).isoformat() }}"  # CHANGE: Adjust lookahead period if needed
    response_variable: calendar_events
    action: calendar.get_events
    alias: Set target calendar and date range for lookup
  - variables:
      calendar_event_name: "Garbage Night"  # CHANGE: Set this to the event name you're looking for
      next_event_start_timestamp: >-
        {% set ns = namespace(event=None) %}
        {% for key, value in calendar_events.items() %}
          {% for event in value.events %}
            {% if calendar_event_name in event.summary %}
              {% set ns.event = event %}
              {% break %}
            {% endif %}
          {% endfor %}
        {% endfor %}
        {% if ns.event.start is defined and ns.event.start not in [none, 'unknown', 'unavailable'] %}
          {{ ns.event.start | as_datetime | as_timestamp }}
        {% else %}
          {{ none }}
        {% endif %}
    alias: Define calendar_event_entry and search returned calendar entries
  - action: logbook.log
    metadata: {}
    data:
      name: ""
      entity_id: "{{ this.entity_id }}"
      message: >-
        {% if next_event_start_timestamp not in [none, 'unknown', 'unavailable'] %}
          {{ " ** Start Time - " ~ next_event_start_timestamp | timestamp_custom('%Y-%m-%d %H:%M:%S', true) ~ " ** " }} 
        {% else %}
          {{ " ** Event not found ** " }}
        {% endif %}
    alias: Log results of lookup
  - if:
      - condition: template
        value_template: "{{ next_event_start_timestamp not in [none, 'unknown', 'unavailable'] }}"
    then:
      - action: kidschores.set_chore_due_date
        metadata: {}
        data:
          chore_name: "Garbage Night"  # CHANGE: Set the chore name for KidsChores
          due_date: >-
            {{ next_event_start_timestamp | timestamp_custom('%Y-%m-%dT%H:%M:%S.000Z', true) }}
mode: single

πŸ“Œ What Needs to Be Changed?

To customize this for your setup, update the following values:

  1. Calendar Entity:

    • Change calendar.parent_name to your calendar entity name in Home Assistant.
    • Example: calendar.household_chores
    • Should work with any Home Assistant Integrated calendar.
  2. Calendar Event Name:

    • Update calendar_event_name: "Garbage Night" to match the exact title of your calendar entry.
    • ⚠️ Make the event name unique!
      • Example: ❌ "Garbage" (might match unrelated events like β€œTake Out Garbage”)
      • Example: βœ… "Garbage Night Chore" (ensures only the right event is found)
  3. Look-Ahead Period:

    • Currently, it searches 21 days ahead (timedelta(days=21)).
    • Adjust this to fit your needs (e.g., 7 days for weekly tasks, 30 days for monthly tasks).
  4. Trigger Timing:

    • No trigger is defined in the example. You must set when it runs:
      • βœ… Daily at midnight:
        triggers:
          - trigger: time
            at: "00:00:00"
      • βœ… Weekly on Sundays:
        triggers:
          - trigger: time
            at: "07:00:00"
          - trigger: time_pattern
            weekday: "sun"
  5. Chore Name for KidsChores:

    • Change chore_name: "Garbage Night" to match your chore name setup in KidsChores.

πŸ› οΈ How to Implement This in Home Assistant

To set up this automation in Home Assistant, follow these steps:

  1. Go to Home Assistant β†’ Settings β†’ Automations & Scenes β†’ Automations.
  2. Click Create Automation β†’ Select Edit in YAML.
  3. Delete any pre-filled YAML and paste in the automation provided above.
  4. Modify the required values:
    • Change the calendar entity (calendar.parent_name) to match your Home Assistant calendar.
    • Update the calendar event name (Garbage Night) to match your calendar entry
    • Update the **chore_name" to match the name of the chore setup in KidsChores
  5. Define a trigger if needed (e.g., run the automation daily at midnight).
  6. Click Save and enable the automation.
  7. Test by adding a chore event to the calendar and ensuring it updates input_datetime.

πŸ“ Automation Logging

This automation includes an action to log when it runs, whether it found the chore event, and the start time of the event (if found).

image image

Clone this wiki locally