Help, how to use: todo.get_items

Help,

how do I get a list of tasks using the todo.get_tasks

alias: "!Test todo"
description: ""
trigger: []
condition: []
action:
  - service: todo.get_items
    target:
      entity_id: todo.my_tasks
    data:
      status: needs_action
    response_variable: agenda
  - service: notify.michael_2
    data:
      title: Daily agenda for {{ now().date() }}
      message: >-
        Your agenda for today: <p> </p>

        {% for itmes in "agenda.todo.my_tasks" %} {{ itmes }} {{itmes.summary}}
        <br> {% endfor %}
mode: single

The output when caling the service in development tools looks like this

todo.my_tasks:
  items:
    - summary: "Run for cover "
      uid: U3ZYX1pMb2FreURETzdNNA
      status: needs_action
      due: "2023-12-06"
    - summary: "Task 22"
      uid: YUh4UFFvX1NlNHhfOFJwNA
      status: needs_action

is the spelling error ā€˜itmesā€™ instead of ā€˜itemsā€™ intentional?

Sorry to say, it makes no diffrence, just testet itā€¦ :frowning:

the {{ agenda }} gives this:

{'todo.my_tasks': {'items': [{'summary': 'Blodtryk ', 'uid': 'U3ZYX1pMb2FreURETzdNNA', 'status': 'needs_action', 'due': '2023-12-06'}, {'summary': 'SƦlge', 'uid': 'YUh4UFFvX1NlNHhfOFJwNA', 'status': 'needs_action'}, {'summary': 'strĆømsvigts monitor', 'uid': 'aUlIZXliUkwtRi1jNGxDcw', 'status': 'needs_action'}, {'summary': 'radar pĆ„ bad', 'uid': 'aElEMldsRWFLWWN2c1JBSQ', 'status': 'needs_action'}, {'summary': 'Kaffemaskine renses', 'uid': 'RG5WbGFHNGdlbkJRcW41dw', 'status': 'needs_action'}, {'summary': 'Fremtidsfuldmagt', 'uid': 'a0JERDFTM1U2ekU5NkZKaw', 'status': 'needs_action'}, {'summary': 'Skriv vp', 'uid': 'NGc1bHZlUkw3TjU3ZXpveA', 'status': 'needs_action'}]}}
    - service: todo.get_items
      target:
        entity_id: todo.hass_ideas
      response_variable: mylist

    - service: system_log.write
      data:
        message: >
          {%- for item in mylist['todo.hass_ideas']['items'] %}
            {{ item.summary }}
          {%- endfor %}
5 Likes

Thanks, that fixes it :smiley:

1 Like

Thanks for this as well works great for me.
Donā€™t suppose you know how to make it a persistent notification with a done button that marks the list complete.
I have a few similar notifications with buttons but they are all done through Node red but I want to try them with the automations instead.

No such thing. There are no actions for a persistent notification.

1 Like

I wrote that wrong I meant a actionable notification that is persistent.
I think Iā€™ve figured it out now Iā€™ve got the notification to be persistent Iā€™m going to set up the action part later when Iā€™m on my laptop.
Thanks

Just piping in here because this took me a while to figure out (Iā€™m pretty low-level) and this thread helped me a lot. (Thank you @jazzyisj ! )

Specifically, to reference specific items in the list I went with

variables:
    Output: "{{ TList['todo.test_list']['items'][-1]['summary'] }}"

Where ā€œTlistā€ is the output of the todo.get_tasks call. Grabs the last (newest) item in the list. For checked or unchecked this is the last thing to be changed. Using this in an automation that updates the house group in Teams whenever someone changes the chore and shopping lists. To get the oldest item in the list swap out [-1] for [0]

1 Like

Is there a way to get the output into a Dashboard Card? I am replacing Google Keep and i want to permanently list the ToDo Action in the Dhasboard.

I think the docs need to be updated, I donā€™t see the Todo card listed, but it is a thing.

Try this or you can configure the ToDo card in the dashboard edit UI.

type: todo-list
title: Jason Tasks
entity: todo.jasons_tasks

1 Like

thanks thats exactly what i was looking for

I didnā€™t find any examples, Iā€™ll add them as an addition to your code. There will be another option

If you use the code that you specified, then the list will go in one line in the message

{%- for item in mylist['todo.hass_ideas']['items'] %}
  {{ item.summary }}
{%- endfor %}

image


I wanted the list in the message to be not in one line, but in a column.

      message: >
        {% set shop_list = shopping_list['todo.shopping_list']['items'] %}
        {%- for item in shop_list -%}
        - {{ item.summary ~ "\n" }}
        {%- endfor -%}

image

1 Like

Probably a newbie question : How to get only the 1st element/item in the todo list ?

How to get only the 1st element/item in the todo list ?

test:
  sequence:
    - service: todo.get_items
      target:
        entity_id: todo.hass_ideas
      response_variable: mylist

    - service: persistent_notification.create
      data:
        title: "First Item"
        message: >
          {% if mylist['todo.hass_ideas']['items'][0] is defined %}
          {{ mylist['todo.hass_ideas']['items'][0]['summary'] }}
          {% endif %}
      continue_on_error: true
1 Like

Thank you all for the inputs! But Iā€™m having some problems, when i run it it only sends a message ā€œagenda.toā€ with each letter on an own row:

alias: "Test: todo"
description: ""
trigger: []
condition: []
action:
  - service: todo.get_items
      target:
        entity_id: todo.kvantum_apotek
      response_variable: mylist
    
    - service: system_log.write
      data:
        message: >
          {% set shop_list = shopping_list['todo.kvantum_apotek']['items'] %}
          {%- for item in shop_list -%}
          - {{ item.summary ~ "\n" }}
          {%- endfor -%}
  - service: notify.mobile_app_samsung_s22
    data:
      title: Daily agenda for {{ now().date() }}
      message: >-
        Your agenda for today: <p> </p>

        {% for itmes in "agenda.todo.kvantum_apotek" %} {{ items }}
        {{itmes.summary}} <br> {% endfor %}
mode: single

What have i done wrong?!

Thank you in advance

You used the non working example above.
It should be something like

      message: >
        Your agenda for today:
        {%- for item in mylist['todo.kvantum_apotek']['items'] %}
        {{ item.summary }}
        {%- endfor %}

if todo.kvantum_apotek is really your entity.

1 Like

Thank you for the reply!

Sorry, forgot to write that I have tried Jasons and DivanX10s solution and i get the same outcome. Mistakenly pasted an old copy

alias: "Test: todo"
description: ""
trigger: []
condition: []
action:
  - service: todo.get_items
      target:
        entity_id: todo.kvantum_apotek
      response_variable: mylist
    - service: system_log.write
      data:
        message: >
          {% set shop_list = shopping_list['todo.kvantum_apotek']['items'] %}
          {%- for item in shop_list -%}
          - {{ item.summary ~ "\n" }}
          {%- endfor -%}
mode: single

Yes it is

not sure why you try to create new array (shop_list).
sure this doesnā€™t work?

alias: "Test: todo"
description: ""
trigger: []
condition: []
action:
  - service: todo.get_items
      target:
        entity_id: todo.kvantum_apotek
      response_variable: mylist
    - service: system_log.write
      data:
        message: >
          {%- for item in mylist['todo.kvantum_apotek']['items'] -%}
          - {{ item.summary ~ "\n" }}
          {%- endfor -%}
mode: single
1 Like

When i wrote my post i had been awake for 23h I thought i understood a little, but now with a clear head I think I understand nothing :sweat_smile:

Iā€™m trying to get the same outcome as the thread maker, get a message with the items in one of my lists. Does system_log.write send the list? How does it know where to send it

Sorry, Iā€™m still a beginner and unlucky in thinking