Export To-Do List

I am wondering if anyone has some Ideas or expertise to create an automation to export a to-do list?
My thoughts are

  1. Get the list items with the todo.get_items service
  2. Use the result of this service to export the items with a notify service.
    I have successfully created a notify service that creates a File using the file notify function.
    File - Home Assistant
    I am just unaware on how to get the items to populate the file.
    I assume I should be able to do this with a response variable but I am not sure how this works.
    Any help would be greatly appreciated.

I had used something similar in the past, so not sure if it’s fully up to latest format, but it may help you…
Here is the notify service defined in yaml:

notify 21:
  - platform: file
    name: List-File-Notify
    filename: List-File-Notify.txt
    timestamp: false

And here is the action part example from the automation:

action:
  - service: notify.list_file_notify
    data:
      message: >-
        {{ as_timestamp(states.sensor.example_temperature.last_changed) |
        timestamp_local }}

You would need to adjust with your variables of course.
The file will end up in your config folder.
I think the above appends data, so doesn’t erase previous data, but please check as it has been a long while since I’ve used it.
edit: forgot to mention … the variables part - yes, use response variables… :slight_smile:

action:
  - service: calendar.get_events
    target:
      entity_id:
        - calendar.my_cal
      device_id: []
      area_id: []
    data:
      duration:
        hours: 30
        minutes: 0
        seconds: 0
    response_variable: the_list

The above would be similar to your to-do list, then use the response variable to seed into the notify service (may need to use data_template:

   data_template:
      value: |-
        {%- PROCESS YOUR List variable here %}
         {{ WRITE OUTPUT AS NEEDED }}

Sorry don’t have better example, but I hope it will point you in the right direction

This is definitely on the same path as I am investigating. I have the notify portion working, do you have more of an example of getting the response variable the_list to “seed” the notify service?

Try something like this …

action:
    service: notify.list_file_notify
    data_template:
      message: |-
          {%- for item in the_list['todo.hass_ideas']['items'] %}
            {{ item.summary }}
          {%- endfor %}

Edit: this last part came from another post, so edit your todo. … part as needed.
Here is a link to that post - may be more helpful :slight_smile: Help, how to use: todo.get_items

@eftimg
Thank you so much for your responses. I now have this working/
I have done the following.
Created an “Around the house” list in my to-do.
image
Created a list notify in my configuration.yaml

notify:
  - platform: file
    name: List Export
    filename: To-Do.List

Created the following automation (trigger is for testing only).

alias: Export List
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - input_number.automation_test_number
    above: 5
condition: []
action:
  - service: todo.get_items
    metadata: {}
    data:
      status: needs_action
    response_variable: mylist
    target:
      entity_id: todo.around_the_house
  - service: notify.list_export
    data_template:
      message: |-
        {%- for item in mylist['todo.around_the_house']['items'] %}
          {{ item.summary }}
        {%- endfor %}
mode: single

I now have a file created that contains the items in my list.
Thanks again!

1 Like

Awesome - glad it’s working for you.

Hello everyone!

I tried to replicate what is described in this thread, unfortunately today, with version 2025.02, it SEEMS it is no longer possible to create notify from yaml, and I have not understood how to do it from UI.

But I did not let myself be discouraged, and for my use case (having all the lists exported and easy to send to keep them offline when we go shopping) I created this script, startable with a button from UI:

alias: Export List
sequence:
  - action: todo.get_items
    metadata: {}
    data:
      status: needs_action
    target:
      entity_id:
        - todo.carne_pesce
        - todo.colazione
    response_variable: mylist
  - action: notify.persistent_notification
    metadata: {}
    data:
      title: Lista Spesa Export
      message: |-
        {%- for todo_key, todo_value in mylist.items() %}
          {%- if todo_value['items'] %}
          ### {{ todo_key.split('.')[1] }}
            {%- for item in todo_value['items'] %}
              - {{ item.summary }}
            {%- endfor %}
          {%- endif %}
          ---
        {%- endfor %}
description: ""

(obviously adapt the entity_id with your lists)


Using this code you can generate a list between notifications and do “Select all → copy” to take it wherever you want.

If anyone knows how to send it directly on whatsapp or telegram that would be great!
In the meantime I’m happy to share my work with you :blush:

Note, after import, is possible edit the first part with UI editor! :laughing:


Example view:

1 Like