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.

1 Like

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