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.