Trying to get todo list notifications

Using the google tasks integration - I’m trying to sort out how I can make an automation/or script to parse my tasks, and ship them off.

I can call the service, works as expected:

service: todo.get_items
target:
  entity_id: todo.my_tasks
data:
  status: needs_action
response_variable: tasks

I can template the results:

{% set tasks = {
  "todo.my_tasks": {
    "items": [
      {
        "summary": "Empty the Dorkbot bin",
        "uid": "N3E2X2ZGWk1IdmhHSzFlUQ",
        "status": "needs_action"
      },
      {
        "summary": "Medicine reminder",
        "uid": "dDJCNjN1LXVpX3JZNHFHSw",
        "status": "needs_action",
        "due": "2024-01-08"
      }
    ]
  }
} %}

{%- for item in tasks['todo.my_tasks']['items'] %}
{{ item.summary }}
{%- endfor %}

and it spits out the data I expect, the summary of both tasks in the list that are status = needs_action (in dev tools > templates)

I’m struggling on putting this together into an automation… The trigger is arbitrary (unless this needs to be a script that will assign the variable or something, but I couldn’t get that working either).

alias: Task Notify
description: ""
trigger: []
condition: []
action:
  - service: todo.get_items
    target:
      entity_id: todo.my_tasks
    data:
      status: needs_action
    response_variable: tasks
  - wait_template: |-
      {%- for item in tasks['todo.my_tasks']['items'] %}
        {{ item.summary }}
      {%- endfor %}
    continue_on_timeout: true
  - service: notify.mobile_app_pixel_8_pro
    metadata: {}
    data:
      message: {{ tasks }}
mode: single

Any pointers would be greatly appreciated.

What are you trying to do with the Wait?

alias: Task Notify
description: ""
trigger: []
condition: []
action:
  - service: todo.get_items
    target:
      entity_id: todo.my_tasks
    data:
      status: needs_action
    response_variable: tasks
  - service: notify.mobile_app_pixel_8_pro
    metadata: {}
    data:
      message: "{{ tasks['todo.my_tasks']['items'] | map(attribute='summary') | list | join(', ') }}"
mode: single

I know you stated “The trigger is arbitrary”, but FWIW if you’re using an automation you should have a trigger… some users have had issues when the trigger configuration is left empty. If you don’t have a specific trigger for this action, set it up as a script instead.

1 Like

Thank you, internet wizard!

I’m not sure - I thought I needed the template piece in there, and that was a stab in the dark. Rolled a nat 1 I guess. Seems I was also misunderstanding that I could put the template bits in the message itself - was down a variable rabbit hole there.

Just FYI, you can template the value for pretty much any configuration variable in a service call. Other action type have more limited acceptance of templates.

1 Like

Good to know. Thanks!