I’ve been scratching my head, learning bits of jinja2 and I am clearly not a developer/programmer!
I’ve found various articles describing how to push to-do lists to persistent notifications but I can’t get it to output via TTS properly.
Whilst I can get an output to tell me how many outstanding tasks I have, I want to filter the output so it only counts todays tasks, not future.
Here is an example of where I am so far, any advice would really be appreciated!!
YAML:
action: todo.get_items
metadata: {}
data:
status:
- needs_action
response_variable: tasks
target:
entity_id: todo.phill_s_list
TTS YAML:
action: tts.cloud_say
metadata: {}
data:
cache: false
entity_id: media_player.ma_office_speaker
message: >-
{% if tasks['todo.phill_s_list']['items'] | length == 0 %}
You have no outstanding tasks.
{% else %}
You have {{ tasks['todo.phill_s_list']['items'] | length }} tasks pending.
{% endif %}
This works but tells me the total of outstanding tasks in my list.
This intent reads out my shopping list - and inserts an “and” between the last two items:
CustomShoppingList:
action:
- service: todo.get_items
target:
entity_id: todo.shopping_list
data:
status: needs_action
response_variable: shopping_list_data
- service: script.willow_tts_response
data:
tts_sentence: >-
{% if states('todo.shopping_list') | float(0) > 0 %}
{{ states('sensor.starter_phrase') }} At the moment you've got,
{% set x = shopping_list_data['todo.shopping_list']['items'] | map(attribute='summary')| list %}
{{' and '.join((x|join(', ')).rsplit(', ', 1)) }}
{% else %}
Nothing on the shopping list at the moment.
{% endif %}
Not my creation, I hasten to say. I love the “and” bit. 
Edit: Ignore {{ states(‘sensor.starter_phrase’) }} - that just puts phrases like “Well…” “OK, so…” etc in front.
Looks very creative but I’m still looking to filter items based on the due date, I’m not convinced it can be done but really hoping someone would be able to prove me wrong!
The following will get everything that, has a due date and is due today or overdue:
action: tts.cloud_say
metadata: {}
data:
cache: false
entity_id: media_player.ma_office_speaker
message: >-
{% set due_today = tasks['todo.phill_s_list']['items']
| selectattr('due','defined')
| selectattr('due','lt', (today_at() +timedelta(days=1)) | string)
| list | count %}
You have
{% if due_today == 0 %}
no outstanding tasks.
{% else %}
{{ due_today }} tasks pending.
{% endif %}
If you only want what’s due today, add another selection before the list
filter:
| selectattr('due', 'ge', today_at() | string)
Thank you so much, works a treat!!
@Didgeridrew I think my shopping list intent may have been yours originally too. Thanks! 
1 Like