Skip to content

Instantly share code, notes, and snippets.

@andrew-codechimp
Last active April 22, 2024 09:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrew-codechimp/2d348f9b35ddbea526b88102c972539d to your computer and use it in GitHub Desktop.
Save andrew-codechimp/2d348f9b35ddbea526b88102c972539d to your computer and use it in GitHub Desktop.
Home Assistant - Add unique to-do item
alias: Add unique to-do
mode: single
icon: mdi:clipboard-list
sequence:
- service: todo.get_items
target:
entity_id: "{{ list }}"
data:
status: needs_action
response_variable: mylistneedsaction
- service: todo.get_items
target:
entity_id: "{{ list }}"
data:
status: completed
response_variable: mylistcompleted
- if:
- condition: template
value_template: >-
{{
mylistcompleted[list]['items']|selectattr('summary','search',item)|list|count
== 1 }}
then:
- service: todo.update_item
data:
item: "{{ item }}"
status: needs_action
target:
entity_id: "{{ list }}"
else:
- if:
- condition: template
value_template: >-
{{
mylistneedsaction[list]['items']|selectattr('summary','search',item)|list|count
== 0 }}
then:
- service: todo.add_item
metadata: {}
data:
item: "{{ item }}"
target:
entity_id: "{{ list }}"
fields:
item:
selector:
text: null
name: Item
description: The to-do item to add
required: true
list:
selector:
entity:
filter:
- domain: todo
name: List
required: true
description: The to-do list
@andrew-codechimp
Copy link
Author

Modified so that it will now check if an item is completed and mark it as uncompleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment