Skip to content

Instantly share code, notes, and snippets.

@hectorzin
Last active May 1, 2024 07:11
Show Gist options
  • Save hectorzin/53f9811ff2d6a673af9ff3a9801df7af to your computer and use it in GitHub Desktop.
Save hectorzin/53f9811ff2d6a673af9ff3a9801df7af 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/hectorzin/53f9811ff2d6a673af9ff3a9801df7af
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 -%}
- variables:
deleted_items: |
{% for index in range(deleted_items.split(';')|length-1) -%}
{%- set item = deleted_items.split(';')[index] -%}
{%- for google_item in google_incompleted[google_list]['items'] -%}
{%- if item|capitalize == google_item.summary|capitalize -%}
{{ google_item.summary }};
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
{% for index in range(deleted_items.split(';')|length-1) -%}
{%- set item = deleted_items.split(';')[index] -%}
{%- for bring_item in bring_incompleted[bring_list]['items'] -%}
{%- if item|capitalize == bring_item.summary|capitalize -%}
{{ bring_item.summary }};
{%- endif -%}
{%- endfor -%}
{%- 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.remove_item
target:
entity_id:
- "{{ google_list }}"
data:
item: "{{ delete_google }}"
- 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: "{{ delete_bring }}"
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