Need to clear a to-do list? Look here!

Huge thanks to Petro for pointing out the myriad of errors in the first draft. If you find this useful, buy Petro a coffee.

Code
alias: Chores List Clear
fields:
  list_to_clear:
    selector:
      entity:
        domain: todo
        multiple: false
    name: List to clear
    required: true
    default: todo.shopping_list
variables:
  items: |
    {{ [list_to_clear] if list_to_clear is string else list_to_clear }}
sequence:
  - service: todo.get_items
    target:
      entity_id: "{{ items }}"
    data: {}
    response_variable: todo_list
  - repeat:
      for_each: "{{ items }}"
      sequence:
        - variables:
            todo: "{{ repeat.item }}"
        - repeat:
            for_each: "{{ todo_list[todo]['items'] }}"
            sequence:
              - service: todo.update_item
                data:
                  item: "{{ repeat.item.summary }}"
                  status: needs_action
                target:
                  entity_id: "{{ list_to_clear }}"
mode: single
icon: mdi:broom

This is set up to be able to add to automations and then just pass the list you want to clear into the script. Petro tested it with multiple lists and reported it worked - I prefer to run it on a single list and then run that action in parallel in automations to do multiple lists.

2 Likes

Nice! Just saved me a bunch of time :slight_smile:

Hello! When a I run the script on a chosen todo list, it’s not removing its items. If there are completed items it just marks them to active again. Is there any change to the integration causing the script not to work?

I don’t believe so … I haven’t adjusted the script since I posted and it is working for me.

Can you share a trace of the script running?

hi friends. I’m new in home assistant. I tried to copy this script in my automation and I get msg:

Preformatted textMessage malformed: extra keys not allowed @ data[‘fields’]

Can I please more info how I should use it?
Many thanks.

Its script, so you you have to create a new script and then use it in the automation

Ok, nice one. Thank you.

@antonpopov
You have to change the code in status from: needs_action to: completed.
After that in automation clear completed items on that list.

Thank you very much @weeboo!

1 Like