Created
September 3, 2024 21:28
-
-
Save jango-blockchained/62f46d56620d36e05f57df26ceaa05ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Recurring Todo Task | |
description: "Create or update a recurring task; set persistent notification warnings and reminders" | |
domain: automation | |
input: | |
tasklist: | |
name: Todo List | |
description: List containing recurring tasks (must exist) | |
selector: | |
entity: | |
filter: | |
- domain: todo | |
taskname: | |
name: Item name | |
description: The name that represents the to-do item. | |
taskdescription: | |
name: Description | |
description: A more complete description of the to-do item than provided by the item name. | |
duration: | |
name: Days until task is due | |
description: How often should task repeat once completed (number of days) | |
selector: | |
number: | |
min: 1 | |
max: 365 | |
warn: | |
name: Days to warn | |
description: How many days in advance do you want to be notified of the upcoming due date? | |
selector: | |
number: | |
min: 1 | |
max: 365 | |
wg_member1: | |
name: Name des ersten WG-Mitglieds | |
description: Der Name des ersten WG-Mitglieds | |
wg_member2: | |
name: Name des zweiten WG-Mitglieds | |
description: Der Name des zweiten WG-Mitglieds | |
trigger: | |
- platform: time_pattern | |
hours: /1 | |
condition: [] | |
action: | |
- variables: | |
tasklist: !input 'tasklist' | |
taskname: !input 'taskname' | |
taskdescription: !input 'taskdescription' | |
duration: !input 'duration' | |
warn: !input 'warn' | |
wg_member1: !input 'wg_member1' | |
wg_member2: !input 'wg_member2' | |
alias: Set Task Details | |
- service: todo.get_items | |
target: | |
entity_id: | |
- "{{ tasklist }}" | |
data: | |
status: needs_action | |
response_variable: todos | |
alias: Get list of existing tasks | |
- alias: If task exists... | |
if: | |
- condition: template | |
value_template: >- | |
{{taskname in todos[tasklist]['items'] | map(attribute='summary') | |
| list}} | |
alias: See if task exists | |
then: | |
- alias: Task exists and is due today or overdue | |
if: | |
- condition: template | |
value_template: |- | |
{% for task in todos[tasklist]["items"] -%} | |
{% if task['summary'] == taskname %} | |
{% set delta = as_local(strptime(task['due'], "%Y-%m-%d")) - today_at("00:00") %} | |
{% if delta.days == 0 %} True | |
{% elif delta.days < 0 %} True | |
{% elif delta.days > 0 %} False | |
{% endif %} | |
{% endif %} | |
{%- endfor %} | |
alias: If task is due today or overdue... | |
then: | |
- service: persistent_notification.create | |
data: | |
notification_id: "{{ taskname }}" | |
title: "Due: {{ taskname }}" | |
message: | | |
{% for task in todos[tasklist]["items"] -%} | |
{% if task['summary'] == taskname %} | |
{% set delta = as_local(strptime(task['due'], "%Y-%m-%d")) - today_at("00:00") %} | |
{% if delta.days < 0 %} Task OVERDUE by {{ (delta.days | abs) }} day(s) {{ '\n\n' -}} {{ task['description'] }} | |
{% elif delta.days == 0 %} Task due TODAY {{ '\n\n' -}} {{ task['description'] }} | |
{% endif %} | |
{% endif %} | |
{%- endfor %} | |
alias: Create or update Persistent Notification | |
- service: persistent_notification.create | |
data: | |
notification_id: "{{ taskname }}_wg_member2" | |
title: "Due: {{ taskname }} ({{ wg_member2 }})" | |
message: | | |
{% for task in todos[tasklist]["items"] -%} | |
{% if task['summary'] == taskname %} | |
{% set delta = as_local(strptime(task['due'], "%Y-%m-%d")) - today_at("00:00") %} | |
{% if delta.days < 0 %} Task OVERDUE by {{ (delta.days | abs) }} day(s) {{ '\n\n' -}} {{ task['description'] }} | |
{% elif delta.days == 0 %} Task due TODAY {{ '\n\n' -}} {{ task['description'] }} | |
{% endif %} | |
{% endif %} | |
{%- endfor %} | |
alias: Create or update Persistent Notification for WG-Member 2 | |
- alias: Task exists and is within warning period | |
if: | |
- alias: If task is due today or overdue... | |
condition: template | |
value_template: |- | |
{% for task in todos[tasklist]["items"] -%} | |
{% if task['summary'] == taskname %} | |
{% set delta = as_local(strptime(task['due'], "%Y-%m-%d")) - today_at("00:00") %} | |
{% if delta.days > 0 and delta.days < warn %} True | |
{% endif %} | |
{% endif %} | |
{%- endfor %} | |
then: | |
- service: persistent_notification.create | |
data: | |
notification_id: "{{ taskname }}" | |
title: "Upcoming: {{ taskname }}" | |
message: | | |
{% for task in todos[tasklist]["items"] -%} | |
{% if task['summary'] == taskname %} | |
{% set delta = as_local(strptime(task['due'], "%Y-%m-%d")) - today_at("00:00") %} | |
{% if delta.days > 0 %} Task due on {{ task['due'] }} {{ '\n\n' -}} {{ task['description'] }} | |
{% endif %} | |
{% endif %} | |
{%- endfor %} | |
alias: Create or update Persistent Notification | |
- service: persistent_notification.create | |
data: | |
notification_id: "{{ taskname }}_wg_member2" | |
title: "Upcoming: {{ taskname }} ({{ wg_member2 }})" | |
message: | | |
{% for task in todos[tasklist]["items"] -%} | |
{% if task['summary'] == taskname %} | |
{% set delta = as_local(strptime(task['due'], "%Y-%m-%d")) - today_at("00:00") %} | |
{% if delta.days > 0 %} Task due on {{ task['due'] }} {{ '\n\n' -}} {{ task['description'] }} | |
{% endif %} | |
{% endif %} | |
{%- endfor %} | |
alias: Create or update Persistent Notification for WG-Member 2 | |
- alias: If task DOES NOT exist... | |
if: | |
- alias: Ensure task does NOT exist | |
condition: template | |
value_template: >- | |
{{taskname not in todos[tasklist]['items'] | | |
map(attribute='summary') | list}} | |
then: | |
- variables: | |
newdue: "{{ (now() + timedelta(days=duration)).strftime('%Y-%m-%d') }}" | |
- service: todo.add_item | |
target: | |
entity_id: "{{ tasklist }}" | |
data: | |
due_date: "{{ newdue }}" | |
item: "{{ taskname }}" | |
description: "{{ taskdescription }}" | |
alias: Add new task with due date and description |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment