Lovelace Custom Card: Todoist-List

Sorry, I completely forgot about existence of this topic :frowning: But changes in configuration files were mentioned in the release notes (as it is the most efficient way to communicate with users of this card):

There are changes to how Todoist handles authorization, so you need to update your configuration files.

Hey everyone! I’ve been playing with todoist-card, and finding it very useful.

Thanks @Grinstantin, great work. I hope life is not being too hard on you with the war and all :pray:

I’ve been playing with Javascript changes to the card, to add functionality. Eventually if I get things generic enough I could make a Pull Request to improve the card for everyone.

I have a few things going: mostly I am looking to do more actions when an Item is completed: write a description (“Done by user XYZ at 7:55pm”), add a Label, move to a different section.

I have all of these working, but just for my peculiar case, not generic, not configurable yet. That’s a lot more work.

I’m thinking of bringing in the Labels into HASS, so I can graphically see them on the items.

I also want to try building a swipe-card with multiple todo lists side by side, or maybe different sections, to emulate a Kanban view (without drag-and-drop, sorry). This part can be done just with HASS configs, no JS tweaks are necessary.

I’d just like to ask, has anybody else been doing this sort of thing? And what Todoist functionality would you most want to be able to access from the Home Assistant side?

1 Like

Just curious, has anyone used something like a zigbee button to trigger a ‘job completion’ of a todoist task? And how did you do it if so? @Grinstantin , is this even possible?

You can make the Zigbee button call an automation.

Using the existing REST command recommended in todoist-card installation instructions, you can set up an automation for it, and in the actions do this:

service: rest_command.todoist
data: 
  url: sync
  payload: >-
    commands=[{ "type": "item_complete", 
    "uuid": "a74bfb5c-5f1d-4d14-baea-b7415446a873", 
    "args": {"id": "6874471432",
    "date_completed": "2023-05-29T01:00:00.000000Z"}
    }]

I am following the todoist API reference found here: Sync API Reference | Todoist Developer

But this has a few problems: that ID is the item’s ID, so it specifies which task you will be completing. You can get it from the URL inside todoist when editing the task, so something like https://todoist.com/app/project/2342185948/task/6874471432

I don’t know if this will be useful to you in such a static way, but maybe yes.

The other problem, which is really going to require a solution, is that the uuid needs to be different each time. It can be anything, but it has to be unique because that is what the Todoist API uses to distinguish requests from one another. If you can find a way for HASS to put in some random number there, or a timestamp, then you’re good to go.

I think you can just omit the data_completed argument and it should work.

I hope this helps.

1 Like

I think this is very much a step in the right direction. It seems like I would need a way to not just generate the uuid daily (as these are daily tasks), but perhaps automatically update the automation(s) with this information as well? Pardon my ignorance, but is it even possible to adjust an automation like that from the backend?

I’m waiting on my zigbee buttons to arrive to the States (gogo AE!) but if all else fails I think I could set a task (ironic) to myself to update each of those UUIDs at night (when all those other tasks are complete).

Appreciate you, @pgr !

I was being silly, of course you can use templates in Automations, so this works:

service: rest_command.todoist
data:
  url: sync
  payload: >-
    commands=[{ "type": "item_complete",  "uuid": {{ range(1, 500) | random }}, 
    "args": {"id": "6874471432"} }]

I removed the complete_data, and Todoist uses the current date. I added a random number for uuid, there are probably better ways to generate random numbers, but that’s a start.

You can also probably use templates to facilitate getting the task id, if it’s not completely stable. If you want to complete the same action often, then you will also need some way to “uncomplete”.

1 Like

It’s going to be 3 different daily tasks (each to take medications, as it were). So if I was only doing the trigger once daily, it should be reset by the next time I trigger it, yes?

Have a look at how Todoist allows recurring tasks, that should be fine for your purposes and will keep the ids stable.

1 Like

Many thanks, friend. You’ve made me a happy little geek.

1 Like

Although this post was completely ignored (which is highly unusual when somebody asks “does anybody want new features?”, eh eh), I have made a lot of progress and will soon be releasing a Power-Todoist card (a fork from the current card) which adds a ton of features.

It’s highly configurable with practically all Todoist actions available from buttons that are fully customizable. You can add and remove labels, filter your tasks with a bunch of criteria, move tasks between sections and projects, etc.

Some of the stuff looks really cool, like a swiper-card to swipe between different Todoist sections, which is a nice way to get a working Kanban into HA.

I allow for a handful of variable substitutions, so I can filter the card with a “dynamic” label that is the user name, for example. With that, I can keep separate lists for separate HA users in a single Todoist managed centrally. Very powerful and practical.

2 Likes

I at least am looking forward to seeing this!

@pgr , another question for you, if you don’t mind.

I’ve got two Todoist accounts, and these tasks I’m currently trying to add to HA are on the account that wasn’t previously associated with HA. So I added this (as an example) to my configuration.yaml:

  - platform: rest
    name: Kitchen (Personal)
    method: GET
    resource: 'https://api.todoist.com/sync/v9/projects/get_data'
    params:
      project_id: xxxxxxxxxx
    headers:
      Authorization: !secret todoist_api_token2
    value_template: '{{ value_json[''project''][''id''] }}'
    json_attributes:
      - project
      - items
    scan_interval: 300

and then modified this:

rest_command:
  todoist:
    method: post
    url: 'https://api.todoist.com/sync/v9/{{ url }}'
    payload: '{{ payload }}'
    headers:
      Authorization: 
        - !secret todoist_api_token
        - !secret todoist_api_token2
    content_type: 'application/x-www-form-urlencoded'

and my secrets.yaml has the appropriate info for those 2 api tokens. This doesn’t seem to be the right way to do this, however, as when trying to check and restart, I get the following error:

Invalid config for [rest_command]: template value should be a string for dictionary value @ data['rest_command']['todoist']['headers']['Authorization']. Got ['Bearer xxxx', 'Bearer yyyyy']. (See /config/configuration.yaml, line 327).

Any suggestions on how to accomplish this? I mean I can always move these tasks over to the Todoist that IS connected to HA, but I’d prefer not to if I can help it.

Don’t put two secrets in one request.

You need to duplicate the entire rest_command section so that you have both a “todoist” and a “todoist2” rest commands, each with its own method, url, payload, secret, etc

1 Like

Perfect, that did the trick, and once I fixed the template in my automation to reflect that it was Todoist2, the button press completed the task. Huzzah!

You’re a hero, sir.

Ah heck, I spoke too soon.

The template code you provided didn’t just complete the task as done for that day, it marked it as done, period.

I just went looking for that task and it was nowhere to be seen.

Ideas?

In Todoist, there is an option to “show completed tasks”, turn that on.

Todoist only restarts tasks if you created them as recurring. To do this I think you need to create them with a “quick add” saying something like “Take medication every day”. These tasks will have a due date, and when you close them, instead of being marked as done, they get assigned a new due date for tomorrow.

I just noticed there are peculiarities for those tasks when completing them through the API. But they seem to provide a facilitated route which is the close_item command.

So try just changing that command type from item_complete to close_item, it should work for recurring tasks.

1 Like

Unfortunately, making this change doesn’t seem to have any effect on the tasks at all. I tried with one automation this morning to no avail, and just tried a few minutes ago with another automation, with the same results.

My bad - it’s item_close instead of close_item. I just tested it and it works.

Keep you eye on Todoist website when trying these things - first you need to get it operational there, only afterwards see if the todoist-card in HA is showing you what you want.

Yep, I had the Todoist app open on my phone. That did the trick, thank you. I can see that task in tomorrow’s list, so mission accomplished.

Very much appreciate your help - do you have a ko-fi or something I can donate to?

I’m glad to hear it’s working!

If you really want to buy me a coffee you can head over to my GitHub sponsorships page that I have for work related to another project. You can use the “one-time amount” option. I appreciate it, thanks. :+1:

1 Like