Add to-do list item only if unique (avoiding duplicates)

The new to-do list feature looks promising, but there are still a few things needed before it will work for some of the use cases I want to use it for. My first idea was to replace another app I am using for daily routines, for instance things I need to check or do every or almost every evening, but with the added power of being able to add items to the list based on conditions (day of week, state of charge of the EV etc.).

My approach is to have an automation that runs at a certain time of the day that adds items in a to-do list, conditionally or unconditionally, depending on which item.

The problem: I must make sure to manually (or automatically) tick off each individual item in the list, or there will be duplicates created the next day. There seems to be neither any service for completely clearing a list nor a service to add an item only if it would not create a duplicate (based on the title). My suggestion is to add support for both of these:

  • Service to clear todo list, e.g., todo.clear_list or todo.remove_all_items
  • Boolean option for service todo.add_item to “Only add if an item with this title does not exist” or similar.

I could of course call todo.remove_item for all items in the list before adding new ones, but that means I need to duplicate all the titles, which makes the automation harder to maintain.

I kind of solved this by using the calendar and todo-list integration in tandem,
for example, when i tick off “clean bed sheets” in the todo-list, an automation adds a calendar event to “clean bed sheets” 2 weeks later. then when the calendar event starts, a todo item is created with that same title. this way you never get duplicates because a new todo item gets created later, based on you ticking it off now.

1 Like

can you share the code?

I solved this in my node-red instance with a flow that contains a get_items service node and a switch node based on the following Jsonata expression:

$boolean($filter(payload.results."todo.maintenance".items[].summary, function($v) {$v = payload.entity_name} ))

Where the payload.results was the return from the get_items service call node, “todo.maintenance” is the string literal name of the todo list that get_items targetted, and payload.entity_name is the to-do list item the flow is deciding whether to add or not.

I just coded this within the last 24 hours, so no idea if there are any bugs or untrapped errors yet, but I thought that I would share anyway.


But I agree, that a “data” field like “prevent_duplicates: true” in the add_items service call would be a very useful addition to the to-do list HA integration!