Just wanted to share how I extract unfinished tasks from Google Tasks

I’ve recently moved from the HACS gtasks integration to the official integration with Google Tasks now that Home Assistant supports due dates.

This should probably work with any todo lists that have due_dates, used on a pixel clock as a long string but could probably be edited to display on a screen through ESPHome or anything else with a physical display.

The reason I’m sharing is because I spent more than a few hours muddling through trying to get it working and hoping it helps anyone else.

  - service: todo.get_items
    target:
      entity_id: todo.to_do
    data:
      status:
        - needs_action
    response_variable: mylist
    continue_on_error: true
  - service: esphome.pixelclock_text_screen
    data:
      default_font: false
      text: |-
        {% for items in mylist['todo.to_do']['items'] -%}
          {% if "due" in items and items.due <= states('sensor.date') -%}
            {{"~"}} {{ items.summary }} {{" "}}
          {%- endif %}
        {%- endfor %}
      lifetime: 1
      screen_time: 3
      r: 255
      g: 128
      b: 128
    continue_on_error: true
3 Likes

Thanks for sharing. Could I tweak what you have done to create a template that returns a count of the ToDo list items that have a due_date equal to today’s date?

Currently working on a template to get a better list for a sensor:

I posted the gist here: Home Assistant configuration.yaml to pull todo data · GitHub

But you could probbaly change the first one to:

          today: >
            {%- set todo_today_counter = namespace(total = 0) %}
            {%- set todo_today = namespace(todo = []) %}
            {%- for items in mylist["todo.to_do"]["items"] %}
              {%- if "due" in items and items.due <= states('sensor.date') %}
                {%- set todo_today.todo = todo_today.todo + [(items.summary)] %}
                {%- set todo_today_counter.total = todo_today_counter.total + 1 %}
              {%- endif %}
            {%- endfor %}
            {{todo_today_counter.total}}
1 Like

Thank you.
I’m trying to use the counter as a boolean value_template in an automation.

Is the namespace(total = 0) a way of specifying the type for the variable?

action:
  - service: todo.get_items
    target:
      entity_id: todo.tasks
    data:
      status: needs_action
    response_variable: todo_items
  - if:
      - condition: template
        value_template: |-
          {% set todo_today_counter = namespace(total = 0) %}
          {% for item in todo_items["todo.tasks"]["items"] %}
          {% if "due" in item and item.due <= states('sensor.date') %}
          {% set todo_today_counter.total = todo_today_counter.total + 1 %}
          {% endif %}
          {% endfor %}
          {% if todo_today_counter.total > 0 %}true{% else %}false{% endif %}
    then:

No. In my attempts to avoid using the namespace, the value was reset to 0 when exiting the ‘for’ loop.

BTW, if you’d like to avoid doing the entire loop you can probably add an ‘if’ in the loop to check for the value and then {break} the loop. You’re only checking if there’s 1 or more right?

If you’d like to experiment with the template, here’s a great guide on how to use the “new” way of getting a starting variable that will match what ends up in your yaml: Debugging templates and service response_variables

Thank you. The if and break is a sensible idea. :man_facepalming:

So that little thing turned into this:

The template yaml has much better examples hwo to extract data from todo lists.

1 Like