Skip to content

Instantly share code, notes, and snippets.

@harung1993
Created February 10, 2025 02:51
Show Gist options
  • Save harung1993/d02c64d381f75a701f6658106d679813 to your computer and use it in GitHub Desktop.
Save harung1993/d02c64d381f75a701f6658106d679813 to your computer and use it in GitHub Desktop.
blueprint:
name: Morning Todo Task Automation with Expanded Scheduling Options
description: A blueprint to remove completed tasks and add new optional tasks, with expanded scheduling options.
domain: automation
input:
tasklist:
name: Todo List
description: The to-do list entity to manage.
selector:
entity:
filter:
- domain:
- todo
multiple: false
schedule:
name: Update Frequency
description: |
Choose how often the task list should be updated.
- **Daily:** Runs every day at **01:00 AM** (removes completed) and **01:05 AM** (adds new tasks).
- **Weekend:** Runs **only on Saturdays** at 01:00 AM / 01:05 AM.
- **Every Other Weekend:** Runs **only on odd-numbered ISO weeks** (e.g., Week 1, 3, 5, etc.) on Saturdays.
- **Once a Month (First Weekend):** Runs **only on the first Saturday of the month**.
selector:
select:
options:
- Daily
- Weekend
- Every Other Weekend
- Once a Month (First Weekend)
task_1_name:
name: Task 1 Name (Optional)
description: The name of the first to-do item.
selector:
text:
default: ""
task_2_name:
name: Task 2 Name (Optional)
description: The name of the second to-do item.
selector:
text:
default: ""
task_3_name:
name: Task 3 Name (Optional)
description: The name of the third to-do item.
selector:
text:
default: ""
task_4_name:
name: Task 4 Name (Optional)
description: The name of the fourth to-do item.
selector:
text:
default: ""
task_5_name:
name: Task 5 Name (Optional)
description: The name of the fifth to-do item.
selector:
text:
default: ""
trigger:
- platform: time
at: "01:00:00" # Removes completed tasks
- platform: time
at: "01:05:00" # Adds new tasks
- platform: event
event_type: manual_trigger # Allows manual execution
condition:
- condition: template
value_template: >
{% set schedule_option = '!input schedule' %}
{% if trigger.platform == 'event' and trigger.event.event_type == 'manual_trigger' %}
true
{% elif schedule_option == "Daily" %}
true
{% elif schedule_option == "Weekend" %}
{{ now().weekday() == 5 }}
{% elif schedule_option == "Every Other Weekend" %}
{{ now().weekday() == 5 and now().isocalendar()[1] % 2 == 1 }} # Odd ISO weeks
{% elif schedule_option == "Once a Month (First Weekend)" %}
{{ now().weekday() == 5 and now().day <= 7 }} # First Saturday of the month
{% else %}
false
{% endif %}
variables:
tasklist: !input tasklist
tasks:
- name: !input task_1_name
- name: !input task_2_name
- name: !input task_3_name
- name: !input task_4_name
- name: !input task_5_name
action:
# Remove completed items from the to-do list
- service: todo.remove_completed_items
target:
entity_id: "{{ tasklist }}"
# Get existing tasks with "needs_action" status and store in response variable
- service: todo.get_items
target:
entity_id: "{{ tasklist }}"
data:
status:
- needs_action
response_variable: todos
- alias: Add new tasks if not already in "needs_action"
repeat:
for_each: "{{ tasks | selectattr('name', '!=', '') | list }}"
sequence:
- variables:
taskname: "{{ repeat.item.name }}"
- condition: template
value_template: >
{{ taskname not in todos[tasklist]['items'] | map(attribute='summary') | list }}
- service: todo.add_item
target:
entity_id: "{{ tasklist }}"
data:
item: "{{ taskname }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment