Lovelace Custom Card: Todoist-List

Heys guys!

Someone know why i can’t visualise my icons on the list?
Got message:

todoist-card.js?hacstag=xxx:256 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘attributes’)
at HTMLElement.getCardSize (todoist-card.js?hacstag=xxxx:256)
at i (c0f67be7.js:4594)
at HTMLElement.value (76a58ed6.js:937)

Thank you!

Ehm… Hi all, I followed all the steps in the manual procedure but something is wrong.

- platform: rest
    name: To-do List
    method: GET
    resource: 'https://api.todoist.com/sync/v8/projects/get_data'
    params:
      token: !secret todoist_api_token
      project_id: https://todoist.com/app/project/2279274393
    value_template: '{{value_json[''project''][''id'']}}'
    json_attributes:
      - items
    scan_interval: 30

rest_command:
  todoist:
    method: post
    url: 'https://api.todoist.com/sync/v8/sync'
    payload: !secret todoist_api_payload
    content_type: 'application/x-www-form-urlencoded'


a1

@Grinstantin thanks for your work on this card its brilliant. It allows me to simply sync my alexa shopping list to todoist . I was working for ages to link the Alexa shopping to the native shoping list , but this is much simpler.

I have added a second template sensor to extract the todoist list info a simple list which just hold the outstanding list and the number of items in the list.

shop_list:
  value_template: >
    {{state_attr("sensor.to_do_list","items")|length}}
  attribute_templates:
    list: >
      {% set ns=namespace(list = []) %}
      {% for items in state_attr("sensor.to_do_list","items") %}
        {% set ns.list = ns.list + [items.content] %}
      {% endfor %}
      {{ns.list}}

I then use this sensor in a script to send the list via email in nice printable form.

email_shopping_list:
  sequence:
  - service: notify.gmail
    data:
      title: Shopping List
      message: Your current shopping list contains {{states("sensor.shop_list")}}
        items  :- {{ '\n' -}}{{ '\n' -}} {% for items in     state_attr("sensor.shop_list","list")
        %}{{items}}{{ '\n' -}}{% endfor %} {{     '\n' -}} Remember to update the
        shopping list on Alexa when complete.
  mode: single
  alias: Email shopping list

Thanks again for your hard work

2 Likes

project id should look like this:

project_id: "2279274393

only the numbers of the id, not the whole url to the project. :wink:

(post deleted)

@lonebaggie Thanks for sharing your template sensor…I must be doing something wrong because I keep receive a configuration error when I place it in my .configuration.yaml file. I receive the following when I check the config before rebooting:

Invalid config for [sensor.template]: expected a dictionary for dictionary value @ data[‘sensors’][‘shop_list’][‘attribute_templates’]. Got None
extra keys not allowed @ data[‘sensors’][‘shop_list’][‘list’]. Got ‘{% set ns=namespace(list = []) %} {% for items in state_attr(“sensor.to_do_list”,“items”) %}\n {% set ns.list = ns.list + [items.content] %}\n{% endfor %} {{ns.list}} \n\n \n’. (See ?, line ?).

Here is what I pasted in:

  - platform: template
    sensors:
      shop_list:
        value_template: >
          {{state_attr("sensor.to_do_list","items")|length}}
        attribute_templates:
        list: >
          {% set ns=namespace(list = []) %}
          {% for items in state_attr("sensor.to_do_list","items") %}
            {% set ns.list = ns.list + [items.content] %}
          {% endfor %}
          {{ns.list}}  

Any suggestions?

Think you might have a format issue

I have a format error :frowning: sorry
needs to be

- platform: template
    sensors:
      shop_list:
        value_template: >
          {{state_attr("sensor.to_do_list","items")|length}}
        attribute_templates:
          list: >
            {% set ns=namespace(list = []) %}
            {% for items in state_attr("sensor.to_do_list","items") %}
              {% set ns.list = ns.list + [items.content] %}
            {% endfor %}
            {{ns.list}}

Got it! Appreciate the assist! I can now have this list text to my wife’s phone on demand! lol…thanks again!

1 Like

Can’t thank everyone enough for this card! It’s been a game changer here in the family! I do have another question, is there any sort of HA service that can add or delete all items from the list?

I would love to create an automation that counts how many times the dishwasher has ran and add some new soap pods to the list automatically or be able to create a webhook to clear the list after we are done shopping (my wife wants nothing to do with adding the HA app on her phone…so I have a script that texts her the list)…Again, thanks for all the effort on this great card!

1 Like

It would be great if the “Quick Add” functionality (See: Sync API Reference | Todoist Developer ) would be used when adding new entries through the card (since the natural language scheduling would work!) Thanks for a great card!

2 Likes

My wife is the same, an email or txt only ! , hence the script . You can just ask alexa to delete the list once you finish shopping

1 Like

Glad the card is useful for someone :slight_smile:

I would have replied to you earlier, but… I’m from Ukraine, and you probably know what is happening here now.

@mboarman, @Mats_Karlsson
No problem, I’ll add requested features to the project roadmap and most likely include them in the next release this month.

1 Like

Say nothing more…I can’t even begin to imagine what you and your family are dealing with right now. It times like these that make the rest of us take time to put things into perspective. I appreciate all you’ve done and wish you and your fellow countryman nothing but the best. Stay safe.

1 Like

Been looking for a “to do” list card for ages and this one is fantastic, thanks for your hard work.

Being a bit new to the YAML, would someone be able to post the code to show multiple lists? Ive created another project, but not sure how to edit the YAML to make a second sensor

1 Like

Try this:

configuration.yaml
sensor:
  - platform: rest
    name: First To-do List
    method: GET
    resource: 'https://api.todoist.com/sync/v8/projects/get_data'
    params:
      token: !secret todoist_api_token
      project_id: FIRST_TODOIST_PROJECT_ID
    value_template: '{{value_json[''project''][''id'']}}'
    json_attributes:
      - items
    scan_interval: 30
  - platform: rest
    name: Second To-do List
    method: GET
    resource: 'https://api.todoist.com/sync/v8/projects/get_data'
    params:
      token: !secret todoist_api_token
      project_id: SECOND_TODOIST_PROJECT_ID
    value_template: '{{value_json[''project''][''id'']}}'
    json_attributes:
      - items
    scan_interval: 30

Just replace FIRST_TODOIST_PROJECT_ID and SECOND_TODOIST_PROJECT_ID with IDs of your projects.

1 Like

@Grinstantin I really love your great work on this card, been looking for this since a long time.
Hope you and your family are safe over there…
I was wondering if there is any way to create different lists (so different rest sensors) filtering out on certain Todoist labels ? I use those labels to identify who of the family needs to perform a task, so would be nice I could create seperate lists in HA.

1 Like

Finally implemented your request - there is new option use_quick_add (disabled by default). It automatically appends “#YourProjectName” to request, so new tasks will be added to the selected project, but I haven’t tested this with project names that contain spaces or special characters.

New release contains breaking changes, so you need to update your configuration.

@GeertV, thank you for the kind words. Todoist Sync API doesn’t have “label” filter, REST API has it, but I can’t get it to work. The problem is that HA REST Sensor integration writes a response to the sensor value (and not to its attributes), which is limited to 255 characters. We can work around this limitation by using Todoist Sync API since its response is an object, and we can put parts of it to the sensor attributes using json_attributes parameter. But, for now, I can’t figure out how to do the same thing with Todoist REST API response since it’s an array.

You can try to create a template sensor which will filter “main” sensor attributes. But there is another problem - I’m not sure that Jinja2 has something like “contains” test ("[A, B, C] contains A?"). It has “in” test (“is A in [A, B, C]?”), but that’s not quite what we need. There is another way to do this if you use only one label for each task - using selectattr filter and eq test. Or I can add label filtering to the card in the next release.

Thanks for all this work and info.
Template sensor was indeed one of my ideas, but can’t figure out how to make this…
I will only have 1 label on each task, what is your idea with selectattr ?

Add this to your configuration.yaml:

template:
  - sensor:
      - name: 'Todoist Test'
        state: '{{ states(''sensor.to_do'') }}'
        attributes:
          project: '{{ state_attr(''sensor.to_do'', ''project'') }}'
          items: '{{ state_attr(''sensor.to_do'', ''items'')|selectattr(''labels'', ''eq'', [''LABEL''])|list }}'

Replace LABEL with name of your label. Make sure you’re using 9th version of Todoist API (.../sync/v9/... in configuration.yaml, two occurrences). If I’m not mistaken, version 8 returns the label IDs instead of their names. In this case you need to use

{{ state_attr(''sensor.to_do'', ''items'')|selectattr(''labels'', ''eq'', [LABEL_ID])|list }}

and replace LABEL_ID with ID of your selected label.

1 Like

Fixed a couple of typos in README.