Sync your Alexa/Todoist shopping list to the Home Assistant shopping list!

Works a treat :slight_smile:

Does this shopping list sync still work with 2023.11? Iā€™m a bit hesitant to update to .11, because I donā€™t want to break my shopping list sync, that I really use every day.

Works ā€œnativelyā€ in 2023.11. I installed it this morning, just having the todoist skill in Alexa and the integration in HA

1 Like

it didnā€™t appear to be working after I upgraded, but itā€™s quite easy to switch over to the new system-

  1. disable the pyscript addon (if you donā€™t have any other pyscripts)
  2. disable your update-shopping-list automation
  3. remove the command line/shopping_list_sensor from your configuration.yaml
  4. add the todoist integration (use the API from your shopping_list_sync.py)
  5. make revisions to your scripts/automations that reference the old shopping list entities

Notes:

  • I donā€™t see a way to use webhook for the todoist integration, so it can take 30 seconds or so for it to update from that direction, but changes to your HA list are pretty much immediately propogated back to todoist
  • todo.alexa_shopping_list contains the count of items on your shopping list
  • calendar.alexa_shopping_list attribute all_items contains the list of items

For example, here is my revised automation that notifies anyone when entering a predefined shopping area (edit in your list of mobile device entities and grocery location entities)

alias: notify-shopping-list
description: ""
trigger:
  - platform: zone
    entity_id: device_tracker.first_phone,device_tracker.second_phone
    zone: zone.grocery_1
    event: enter
  - platform: zone
    entity_id: device_tracker.first_phone,device_tracker.second_phone
    zone: zone.grocery_2
    event: enter
condition:
  - condition: numeric_state
    entity_id: todo.alexa_shopping_list
    above: 0
action:
  - service: notify.mobile_app_{{ states[trigger.to_state.entity_id].object_id }}
    data:
      title: Grocery List ({{ states('todo.alexa_shopping_list') }} Items)
      message: >-
        {{ state_attr('calendar.alexa_shopping_list','all_tasks') | join(',\n')
        }}
      data:
        tag: grocery-list
        notification_icon: mdi:food-apple
        clickAction: /shopping-list
        url: /shopping-list
3 Likes

Hi @fenty17,

When an item is completed in the Shopping List (HA) is removed since the todoist API does not return the completed tasks or items.

I modified the script to fetch the completed items and combine with the active items.

def get_completed_tasks():
    get_tasks_url =f"https://api.todoist.com/sync/v9/completed/get_all?project_id={TODOIST_PROJECT_ID}"
    headers = {"Authorization" : f"Bearer {TODOIST_TOKEN}"}

    status_code = 500

    while status_code is not 200:
        response = task.executor(requests.get, get_tasks_url, headers = headers)
        status_code = response.status_code
        task.sleep(1)
    json = response.json()
    json = json['items']
    tasks = []
    for item in json:
        item['is_completed'] = True
        item['content'] = item['content'].replace(" @Alexa", "")
        tasks.append(item)
    return tasks

def get_tasks():
    get_tasks_url =f"https://api.todoist.com/rest/v2/tasks?project_id={TODOIST_PROJECT_ID}"
    headers = {"Authorization" : f"Bearer {TODOIST_TOKEN}"}

    status_code = 500

    while status_code is not 200:
        response = task.executor(requests.get, get_tasks_url, headers = headers)
        status_code = response.status_code
        task.sleep(1)
    json = response.json()
    completed_tasks = get_completed_tasks()
    return json + completed_tasks

Itā€™s working fine for me.

I can submit a pull request if you want.

Thanks in advance.

1 Like

Hey Team,

may someone can support me here. I installed everything liked descripted but I can not start the pyscript.sync_shopping_list via services.
I just doesnt show up. The picture shows where I put the files. May there is a issue.
Thank you

image

I think a lot of us have probably moved to using the native HA to do lists with Todoist integration. Thatā€™s what I did and it works better than this script did.

Hey, everyone, I see that Todoist are soon to stop support for the Alexa integration as stated on The Verge. I guess this is going to mean a lot of changes to make this as convenient as it has been

1 Like

I donā€™t know how that will work since looks like its Amazon who is closing the API

1 Like

Following this thread, because I have the same concern. While I can always use the Alexa app to pull up my shopping list, it was nice having them syncā€™d.

1 Like

Maybe someone can write a scraper for Amazonā€™s web page version of the list

2 Likes

Hi, Does someone found a solution to replace this tool? Thanks!

Iā€™m using this scraper: https://community.home-assistant.io/t/alexa-list-api-to-be-deprecated-july-1st-2024/735626/12

Hi all,

I created a project that is able to do a one-way sync from Amazon Shopping List to HA using a js scraper.

  • This is based on another project that was created by @Jon_White and improved by @emilypeek
    This is not a ā€œstableā€ version, so use with caution.
    I also added the instructions on how to use it.

Maybe somebody with more knowledge can take this and make a better version of it :slight_smile:

3 Likes

Hello everyone

Thanks to @thiagobruch for the inspiration, this is my Python version of a scraper and add-on.

The scraper itself supports adding, updating, removing and marking complete but the HA integration still needs work to support updates. If anyone more knowledgeable is reading then please help out!

Updates from HA to Alexa are handled by automations via the list events and the Alexa to HA sync runs every minute within the add-on itself.

1 Like