Automation loop "For each" using a TODO list

I’m trying to iterate over all items from a todo list using a for each loop.

  1. In the automation I use the get_items service and used the response variable “dummy”

  2. Use the for-each repeat option and used “{{dummy}}” as the list.
    However, this gives an error: Error: Repeat ‘for_each’ must be a list of items

The variable contains:

dummy:
  todo.notifications:
    items:
      - summary: Test
        uid: c230fe7c-9d0e-11ee-8a07-e63b88907365
        status: needs_action
        due: '2023-12-17T20:17:00+01:00'
        description: Some long descrtiption
      - summary: Test2
        uid: ee5a735c-9d0e-11ee-8a07-e63b88907365
        status: needs_action
        due: '2023-12-17T20:18:00+01:00'
        description: Some long descrtiption2

Let’s say I want an automation to announce every descrption using TTS from every item on the list that is due for today. I feel this must be possible, but I’m lacking the advanced skills here.

I don’t understand why you were planning to use a Repeat for Each in this use case…

...
  - service: notify.tts_example
    data:
      title: Today's To-Dos
      message: |
        {{ dummy['todo.notifications']['items']
        | selectattr('due', 'ge', today_at()|string)
        | selectattr('due', 'lt', (today_at()+timedelta(days=1))|string)
        | map(attribute='description') | join(', ')  }}

Just to explain why it wasn’t working.

As you can see it is in fact not a list when you just pass {{ dummy }} because the service call can return multiple entities in one call - so you need to specify WHICH entity you want to use:

{{ dummy['todo.notifications']['items'] }}

That is the list.

{{ dummy }} and {{ dummy['todo.notifications'] }} are both dicts, because they contain another level below them. The list is the bit that starts - summary

Thanks for this answer, and is definitely easier for certain cases. Not what I was looking for but gives some new inspiration :slight_smile:

Thanks a lot. It’s working now :slight_smile:
I figured out to use individual items from the list (like only the description) as {{ repeat.item.description}}