Skip to content

Instantly share code, notes, and snippets.

@Pukimaa
Forked from hectorzin/synchronize_todo_list.yaml
Last active February 11, 2024 20:29
Show Gist options
  • Save Pukimaa/d7aa4bca673f0bed58d8ab75d8ec315c to your computer and use it in GitHub Desktop.
Save Pukimaa/d7aa4bca673f0bed58d8ab75d8ec315c to your computer and use it in GitHub Desktop.
Synchronize 2 Home Assistant todo list
blueprint:
name: "Synchronize 2 Home Assistant todo list"
description:
This blueprint for Home Assistant synchronizes 2 to-do lists. Originally designed to sync Google Keep lists with the Bring shopping list, its versatility allows syncing any list. Currently limited to syncing only active items, those marked as completed are removed from the lists
source_url: https://gist.github.com/Pukimaa/d7aa4bca673f0bed58d8ab75d8ec315c
domain: automation
input:
google_list:
name: List 1
description: Select your first list to synchronize
selector:
entity:
domain:
- todo
multiple: false
bring_list:
name: List 2
description: Select your second list to synchronize
selector:
entity:
domain:
- todo
multiple: false
temp_list:
name: Temp List
description: Select the temporary list that is used as the basis of the synchronization
selector:
entity:
domain:
- todo
multiple: false
trigger:
- platform: state
entity_id:
- !input 'google_list'
- platform: state
entity_id:
- !input 'bring_list'
condition: []
action:
- variables:
google_list: !input 'google_list'
bring_list: !input 'bring_list'
temp_list: !input 'temp_list'
- service: todo.get_items
target:
entity_id: "{{ google_list }}"
data:
status: needs_action
response_variable: google_incompleted
- service: todo.get_items
target:
entity_id: "{{ bring_list }}"
data:
status: needs_action
response_variable: bring_incompleted
- service: todo.get_items
target:
entity_id: "{{ temp_list }}"
data:
status: needs_action
response_variable: temp_incompleted
- variables:
deleted_items: |
{%- for temp_item in temp_incompleted[temp_list]['items'] -%}
{% set ns = namespace(found=false) %}
{%- for google_item in google_incompleted[google_list]['items'] -%}
{%- if google_item.summary|capitalize == temp_item.summary|capitalize -%}
{% set ns.found = true %}
{%- endif -%}
{%- endfor -%}
{%- if not ns.found -%}
{{ temp_item.summary }};
{%- endif -%}
{%- endfor -%}
{%- for temp_item in temp_incompleted[temp_list]['items'] -%}
{% set ns = namespace(found=false) %}
{%- for bring_item in bring_incompleted[bring_list]['items'] -%}
{%- if bring_item.summary|capitalize == temp_item.summary|capitalize -%}
{% set ns.found = true %}
{%- endif -%}
{%- endfor -%}
{%- if not ns.found -%}
{{ temp_item.summary }};
{%- endif -%}
{%- endfor -%}
- repeat:
for_each: "{{ (deleted_items).split(';') | list }}"
sequence:
- condition: template
value_template: "{{ repeat.item != \"\" }}"
- service: todo.update_item
target:
entity_id:
- "{{ temp_list }}"
data:
item: "{{ repeat.item }}"
status: completed
- variables:
delete_google: |
{% set ns = namespace(found="") %} {%- for google_item in
google_incompleted[google_list]['items'] -%}
{%- if google_item.summary|capitalize == repeat.item|capitalize -%}
{% set ns.found = google_item.summary %}
{%- endif -%}
{%- endfor -%}
{%- if ns.found != "" -%}
{{ ns.found }}
{%- else -%}
{%- endif -%}
- if:
- condition: template
value_template: "{{ delete_google != \"\" }}"
then:
- service: todo.update_item
target:
entity_id:
- "{{ google_list }}"
data:
item: "{{ repeat.item }}"
status: completed
- variables:
delete_bring: |
{% set ns = namespace(found="") %}
{%- for bring_item in bring_incompleted[bring_list]['items'] -%}
{%- if bring_item.summary|capitalize == repeat.item|capitalize -%}
{% set ns.found = bring_item.summary %}
{%- endif -%}
{%- endfor -%}
{%- if ns.found != "" -%}
{{ ns.found }}
{%- else -%}
{%- endif -%}
- if:
- condition: template
value_template: "{{ delete_bring != \"\" }}"
then:
- service: todo.update_item
target:
entity_id:
- "{{ bring_list }}"
data:
item: "{{ repeat.item }}"
status: completed
- service: todo.get_items
target:
entity_id: "{{ temp_list }}"
data:
status: needs_action
response_variable: temp_incompleted
- service: todo.get_items
target:
entity_id: "{{ google_list }}"
data:
status: needs_action
response_variable: google_incompleted
- service: todo.get_items
target:
entity_id: "{{ bring_list }}"
data:
status: needs_action
response_variable: bring_incompleted
- variables:
items_to_buy_rep: |
{%- for google_item in google_incompleted[google_list]['items'] -%}
{% set ns = namespace(found=false) %}
{%- for temp_item in temp_incompleted[temp_list]['items'] -%}
{%- if google_item.summary|capitalize == temp_item.summary|capitalize -%}
{% set ns.found = true %}
{%- endif -%}
{%- endfor -%}
{%- if not ns.found -%}
{{ google_item.summary|capitalize }};
{%- endif -%}
{%- endfor -%}
{%- for bring_item in bring_incompleted[bring_list]['items'] -%}
{% set ns = namespace(found=false) %}
{%- for temp_item in temp_incompleted[temp_list]['items'] -%}
{%- if bring_item.summary|capitalize == temp_item.summary|capitalize -%}
{% set ns.found = true %}
{%- endif -%}
{%- endfor -%}
{%- if not ns.found -%}
{{ bring_item.summary|capitalize }};
{%- endif -%}
{%- endfor -%}
- variables:
items_to_buy: |
{% for index in range(items_to_buy_rep.split(';')|length-1) -%}
{% set ns = namespace(found=false) %}
{%- set item = items_to_buy_rep.split(';')[index] -%}
{% for index2 in range(index+1,items_to_buy_rep.split(';')|length-1) -%}
{%- set item2 = items_to_buy_rep.split(';')[index2] -%}
{%- if item == item2 -%}
{% set ns.found = true %}
{%- endif -%}
{%- endfor -%}
{%- if not ns.found -%}
{{ item }};
{%- endif -%}
{%- endfor -%}
- service: todo.get_items
target:
entity_id: "{{ temp_list }}"
data:
status: completed
response_variable: temp_completed
- variables:
items_to_delete: |
{% for index in range(items_to_buy.split(';')|length-1) -%}
{% set ns = namespace(found=false) %}
{%- set item = items_to_buy.split(';')[index] -%}
{%- for temp_item in temp_completed[temp_list]['items'] -%}
{%- if item|capitalize == temp_item.summary|capitalize -%}
{{ temp_item.summary }};
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
- repeat:
for_each: "{{ (items_to_delete).split(';') | list }}"
sequence:
- condition: template
value_template: "{{ repeat.item != \"\" }}"
- service: todo.remove_item
target:
entity_id: "{{ temp_list }}"
data:
item: "{{ repeat.item }}"
- repeat:
for_each: "{{ (items_to_buy).split(';') | list }}"
sequence:
- condition: template
value_template: "{{ repeat.item != \"\" }}"
- service: todo.add_item
target:
entity_id: "{{ temp_list }}"
data:
item: "{{ repeat.item }}"
- service: todo.get_items
target:
entity_id: "{{ temp_list }}"
data:
status: needs_action
response_variable: temp_incompleted
- variables:
items_to_bring: |
{%- for temp_item in temp_incompleted[temp_list]['items'] -%}
{% set ns = namespace(found=false) %}
{%- for bring_item in bring_incompleted[bring_list]['items'] -%}
{%- if bring_item.summary|capitalize == temp_item.summary|capitalize -%}
{% set ns.found = true %}
{%- endif -%}
{%- endfor -%}
{%- if not ns.found -%}
{{ temp_item.summary|capitalize }};
{%- endif -%}
{%- endfor -%}
- service: todo.get_items
target:
entity_id: "{{ bring_list }}"
data:
status: completed
response_variable: bring_completed
- variables:
items_to_delete: |
{% for index in range(items_to_bring.split(';')|length-1) -%}
{% set ns = namespace(found=false) %}
{%- set item = items_to_bring.split(';')[index] -%}
{%- for bring_item in bring_completed[bring_list]['items'] -%}
{%- if item|capitalize == bring_item.summary|capitalize -%}
{{ bring_item.summary }};
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
- repeat:
for_each: "{{ (items_to_delete).split(';') | list }}"
sequence:
- condition: template
value_template: "{{ repeat.item != \"\" }}"
- service: todo.remove_item
target:
entity_id: "{{ bring_list }}"
data:
item: "{{ repeat.item }}"
- repeat:
for_each: "{{ (items_to_bring).split(';') | list }}"
sequence:
- condition: template
value_template: "{{ repeat.item != \"\" }}"
- service: todo.add_item
target:
entity_id: "{{ bring_list }}"
data:
item: "{{ repeat.item }}"
- variables:
items_delete_bring: |
{%- for bring_item in bring_incompleted[bring_list]['items'] -%}
{% set ns = namespace(found=false) %}
{%- for temp_item in temp_incompleted[temp_list]['items'] -%}
{%- if bring_item.summary|capitalize == temp_item.summary|capitalize -%}
{% set ns.found = true %}
{%- endif -%}
{%- endfor -%}
{%- if not ns.found -%}
{{ bring_item.summary }};
{%- endif -%}
{%- endfor -%}
- repeat:
for_each: "{{ (items_delete_bring).split(';') | list }}"
sequence:
- condition: template
value_template: "{{ repeat.item != \"\" }}"
- service: todo.update_item
target:
entity_id: "{{ bring_list }}"
data:
item: "{{ repeat.item }}"
status: completed
- variables:
items_to_google: |
{%- for temp_item in temp_incompleted[temp_list]['items'] -%}
{% set ns = namespace(found=false) %}
{%- for google_item in google_incompleted[google_list]['items'] -%}
{%- if google_item.summary|capitalize == temp_item.summary|capitalize -%}
{% set ns.found = true %}
{%- endif -%}
{%- endfor -%}
{%- if not ns.found -%}
{{ temp_item.summary|capitalize }};
{%- endif -%}
{%- endfor -%}
- service: todo.get_items
target:
entity_id: "{{ google_list }}"
data:
status: completed
response_variable: google_completed
- variables:
items_to_delete: |
{% for index in range(items_to_google.split(';')|length-1) -%}
{% set ns = namespace(found=false) %}
{%- set item = items_to_google.split(';')[index] -%}
{%- for google_item in google_completed[google_list]['items'] -%}
{%- if item|capitalize == google_item.summary|capitalize -%}
{{ google_item.summary }};
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
- repeat:
for_each: "{{ (items_to_delete).split(';') | list }}"
sequence:
- condition: template
value_template: "{{ repeat.item != \"\" }}"
- service: todo.remove_item
target:
entity_id: "{{ google_list }}"
data:
item: "{{ repeat.item }}"
- repeat:
for_each: "{{ (items_to_google).split(';') | list }}"
sequence:
- condition: template
value_template: "{{ repeat.item != \"\" }}"
- service: todo.add_item
target:
entity_id: "{{ google_list }}"
data:
item: "{{ repeat.item }}"
- variables:
items_delete_google: |
{%- for google_item in google_incompleted[google_list]['items'] -%}
{% set ns = namespace(found=false) %}
{%- for temp_item in temp_incompleted[temp_list]['items'] -%}
{%- if google_item.summary|capitalize == temp_item.summary|capitalize -%}
{% set ns.found = true %}
{%- endif -%}
{%- endfor -%}
{%- if not ns.found -%}
{{ google_item.summary }};
{%- endif -%}
{%- endfor -%}
- repeat:
for_each: "{{ (items_delete_google).split(';') | list }}"
sequence:
- condition: template
value_template: "{{ repeat.item != \"\" }}"
- service: todo.update_item
target:
entity_id: "{{ google_list }}"
data:
item: "{{ repeat.item }}"
status: completed
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment