Todoist Support

Wondering if there’s a developer willing to take a crack at adding support for a todo list into Home Assistant. Todoist seems to be ideal since there is an open API already and it syncs with Alexa.

https://developer.todoist.com/#add-a-new-project

Here’s how I see it’s integration. Home Assistant would have sensors like
sensor.todoist_list_item
for all to dos, or at least the first 10 in each list.

My use case would be, in my morning tts script, remind me of the last few reminders I set for myself. I’m sure the community may think of a few more use cases for having lists integrated in Home Assistant.

You can already do it yourself using a REST sensor in conjunction with the Todoist REST API. You can generate tokens to use with the API here. There’s also a nice IFTTT integration.

That being said, it should be fairly trivial to code up a Python implementation for a sensor which can keep track of that sort of stuff. I rely on Todoist pretty heavily myself, so I’ll take a look at making a custom component for Todoist tonight.

2 Likes

I am doing this with IFTTT and it works well. I would definitely use a custom component if it were available

Thanks for the tip. Let me know how the component comes. I can help beta test if you need someone. Appreciate it!

Development is moving right along, and I can say I’m pretty much there (I’m just polishing things and adding some more features to the component).

I tried going the sensor route, but the more I thought about it, the more I realized that it’s actually a calendar component. Here’s a screenshot of what I’ve done so far (ignore my 40 billion tabs):

You can see that the start time for these calendar events is set to right now. I had to set it to something (the calendar component expects a date and time for things; go figure!), and the more I thought about it, the more I realized that really a task is something you could do now (in most cases). I could do my homework right now, or I could technically pay next month’s rent right now. I can’t do my midterm right now, but a good portion of the time, a task is something that you could do now – which is why I set the tasks to be starting right now, and ending when they’re due.

Limitations

I can also only give full information about one event at a time – technically, I could display a giant JSON object in there, but none of the other HASS components do that, and ideally I’m trying to make something that could get accepted in a pull request. I wrote a little bit of logic to determine which event is the most important:

  • Completed events are disregarded; they’re complete.

  • Events without any due date are selected only if they’re the only things available. If there’s nothing in a project which has a due date, events without a due date will be selected based on their priority.

  • Events with a closer due date are selected first. If you have a priority 4 event due on the 15th and a priority 1 event due on the 16th, the priority 4 event takes precedence. The logic here is that you still have an extra day to do the priority 1 event if needed.

  • When 2 events are due on the same day, the higher-priority one comes first. If there’s a priority 4 event due at 12 PM and a priority 1 event due at 9 PM, the priority 1 event would be the one displayed.

  • If 2 events are due on the same day and have the same priority, the one due earlier in the day wins.

If a task without a due date is the task selected to be the “most important”, the “all_day” attribute gets set to “true”. Otherwise, it’s “false”.

As you can see, though, I did implement a “all tasks” array, which lists all the tasks due in a project. This array is sorted so that the ones which are more important are at the beginning, while the least-important tasks are at the end.

Further Improvements

I’m looking to integrate an optional parameter in the configuration file which creates a new “calendar” that only looks at the next n days, where n is a number you specify. As an example, you could have a calendar which only takes into consideration all events due in the next 3 days. Another idea I have is to have an optional array of labels in the configuration file. Each label would get its own calendar, so if you wanted to have a reminder to (as an example) work on homework once you get home any time you have homework, you could. Most likely I’ll find a way to implement both of those together.

I haven’t tested it with overdue events yet, and I’m not sure what will happen, to be honest.

I’d also like to take a look at a project “blacklist” of some kind. Right now, there’s no way to specify that you don’t want to see a particular project at all, and things can get kind of cluttered if you use projects to organize other projects like I do. I don’t generate any new .yaml files or anything, so it would have to be set in the configuration file directly. Alternatively, I’m looking at implementing labels – maybe users can specify labels to blacklist?

Right now, there’s no support for actions. I haven’t even looked into doing anything for that yet; I want to get the actual sensor done first, then I can take a look at adding some actions.


I should hopefully have something up on GitHub in the next day or two. One thing that would be really hard would be listing all your most recent things you added to your to-do list; I don’t think I get that data from the API at all, so it would be guesswork, essentially. An easy thing to do would be to give day-of reminders for things that are due that day, or have your text-to-speech tell you everything you need to get done in a particular project. Note that I can only work on actual due dates, not Todoist reminders (although if it reminds you via email, you can get a sensor that detects that).

In the meantime, let me know if you have any ideas for things I can implement!

2 Likes

@Jay2645. This is AMAZING!! Exactly what I have been looking for. Thank you so much. Looking forward to trying it out soon.

I agree, the calendar is the best approach given the dates for tasks and I like your logic. One question I have is, since I have a list that syncs with Alexa, would it take the last task I added from Alexa? I usually don’t assign a due date, just simply say “Alexa, add a todo list to Call my doctor” as an example. I’m assuming if nothing has a due date it takes the last entry?

I’m pretty excited about this as well. Is there a github repo I can star/watch?

Yeah! Here is the project on GitHub; feel free to check it out and let me know what you think. I’m still working on it, so it’s not 100% finished yet, but it should hopefully be somewhat usable. You should be able to use it by copying todoist.py into your configuration/custom_components/calendar directory.

Add this to your configuration file:

calendar:
  - platform: todoist
    token: <YOUR API TOKEN HERE>

Get your token here, at the bottom of the page.

I’ll try to get some more work done on it today.

2 Likes

Awesome! I’m going to try it out tonight. Thanks Jay

Went ahead and installed/set it up from work and it seems to be working as expected; great work! What does the off/on state represent?

On/Off represents whether you have a task in that project or not. The task could be due today, tomorrow, next year, or may not be due at all – you just have a task in that project which hasn’t been marked as complete yet. The message in the entity tells you what exactly is due, and then ends tells you when the due date is.

On that note, I’ve made a few improvements and moved my work onto a new branch on GitHub.

Notably:

  • You can now see what priority a task is by looking at the entity’s priority.

  • I added a due_today flag that’s true when a task is due today. (I just realized that overdue tasks technically aren’t due today; I’ll fix that later tonight.)

  • I fixed a bug where the priorities on tasks were reversed (i.e. lower-priority tasks came before high-priority ones).

  • I reversed the order in which tasks without due dates get returned. The one you added the most recently is now the one that gets returned (assuming all tasks without due dates have the same priority).

The coolest thing of all is that I added very basic support for “custom” projects. Here’s an example:

calendar:
  - platform: todoist
    token: !secret todoist_token
    extra_projects:
        # Iterates over all your projects
      - name: 'All Projects'
        # Find all projects due today
      - name: 'Due Today'
        due_date_days: 0
        # Find all projects due in the next 7 days
      - name: 'Due This Week'
        due_date_days: 7

There’s no way to filter this by project (yet); it just goes over all the tasks you have.

When asking for all tasks due in the next n days, if a task doesn’t have a due date, it doesn’t get included in the list. I’m planning to add ways to filter them by project name or by label. I might also have a toggle to include tasks without due dates.

1 Like

@Jay2645 I’ve been playing around with this custom component and it works great!

Since I use Alexa to say my todos, they rarely get a due date but I’ve created template sensors to pull 3 reminders so it can announce in my morning wakeup script. If anyone else is interested, here’s what I did to get more items in a particular list.

  todoist_1:
    value_template: "{{ states.calendar.due_today.attributes.all_tasks[0] }}"
  todoist_2:
    value_template: "{{ states.calendar.due_today.attributes.all_tasks[1] }}"
  todoist_3:
    value_template: "{{ states.calendar.due_today.attributes.all_tasks[2] }}"

My next question is, is it possible to have an attribute that does a count of the current todo’s in the array? Thanks

The length filter will do that for you: {{states.calendar.all_projects.attributes.all_tasks|length}}

1 Like

That’s right! I don’t know why I didn’t think of that. Thanks!

Another update! This time, I added support for filtering projects by label or by name. In a breaking change, I also renamed “extra_projects” to “custom_projects”.

Filtering by label means that any task with one of the listed labels will be added to your custom project. Filtering by name will return all tasks in any project name(s) you specify.

Here’s an example:

calendar:
  - platform: todoist
    token: !secret todoist_token
    custom_projects:
      - name: 'All Projects'
      - name: 'Due Today'
        due_date_days: 0
      - name: 'Due This Week'
        due_date_days: 7
      - name: 'Math Homework'
        labels:
          - Homework
        include_projects:
          - Mathematical Structures II
          - Calculus II

You can mix-and-match any filters you want, so you can find all things with a certain label due in the next 30 days, you can “combine” 2 projects together into 1 project listed in Home Assistant, etc.

All that’s left to do is to add some automation support (automatically making a task to update HASS once an update gets pushed out, or automatically making a task to get the mail once a USPS sensor says there’s mail on the way, as a couple examples).

1 Like

I haven’t had much time to play with my Home Assistant setup to integrate this, but I just want to say that you’ve done amazing work here-- this is exactly what I was looking for.

1 Like

I’ve submitted a pull request to the Home Assistant guys. Hopefully it’ll make it in time for 0.53.

1 Like

@Jay2645 How do I update to the latest version? It looks like I need to add some dependencies??

@Jer78 So the Home Assistant guys wanted me to move to using the “official” Todoist API. I wanted to stay away from dependencies, but they insisted and pointed out it’s part of the style requirements listed for contributing to Home Assistant.

The end result was I had to move to the official Todoist Python API. It’s an easy fix to install the dependency, though – activate your Home Assistant virtual environment (assuming you have HASS installed in a virtual environment; if not, skip this step) and then type pip install todoist-python. Once it’s installed, it should work just fine.

You could build from my source and it should install everything automatically, but I would caution against it as I haven’t pulled from Upstream in a while, so you’d be stuck with this weird 0.52-0.53 hybrid.

I guess I’m still missing something. I installed Todoist-python but it still says I’m missing dependencies. Is there something else I need to do or just copy the latest Todoist.py to my custom_components/calendar directory? I’m using a Mac for my HA install. Thanks