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

Manually creating the folders is fine. Scripts should appear as a service automatically I think, but for me it took a couple of restarts. Once the
pyscript.sync_shopping_list service shows in Developer Tools > Services you know it’s been picked up, then call the service and check log for any errors.

I reinstalled the whole thing, and this time a /pysripct folder appeared in my config. I put the required file there and create the other folder with the other file. After that, the service appeared on my list in the developer tools, but when I call it, seemingly nothing happens. In the log, I only find this with the corresponting time:
2023-10-24 01:16:59.389 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Running websocket_api script
2023-10-24 01:16:59.390 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Executing step call service

UPDATE
In the meantime I found out that it is working, but it takes 30 minutes to call the service and sync the two shopping lists.
Now I tried to set up the webhook. I created the autmation in HA and the app in todoist, created the webhook URL wit my HA URL and webhook ID in it, activated the webhook and created the test token, restarted HA couple of times, but the automation do not activate when I put something to the Todoist list. I have never worked with webhooks before, and I don’t know what else should I do.Is there anything with the test token in Todoist or just to create it?

Thank you very much for such an awesome script.

It’s working perfectly for me.

I was not able to configure the webhook because Todoist is not invoking my webhook which is opened to the Internet (I tested).

To solve this, I’ve added another trigger to the webhook automation to trigger the automation every 3 minutes. This way my shopping lists are synced.

Hi. I have this now fully working as it should after reading the original post and some of your ideias and adjustments.

I couldn,t make it work with the original pyscripts so i used the one posted here . Althow i had some issues with that code, the HA shopping list to alexa worked , but the alexa to HA didnt, althow if i went to the file config/shopping_list.json the new items were there but not in the shopping list. I read here that this happened to other user too, my deleting the shopping list didn,t solve the problem.

I had an error in HA logs after i run the pyscript service “*object int can’t be used in ‘await’ expression line 45 *” , so i searched what i could do and did this:

this is the original code from line 44,45 and 46

    async with aiofiles.open(filename, mode='w') as f:
        await f.write(j)
        await f.flush()

so i just deleted the await in the ines 45 and 46:

    async with aiofiles.open(filename, mode='w') as f:
              f.write(j)
              f.flush()

and my problem was solved. I now have instant update in both directions and no error on the logs. And the webhook worked with no problem and using the original post orientations.

Now one thing that could be enanced: When we put an item has complete in HA it is cleared too one second later, i guess it is beacuse of the pyscript. Would it be nice not to clear it , just complete it. And the other end , it would be great if when we clear it from HA it would clear too in alexa app. Seems like items in alexa shopping list after we complete them only can be deleted by hand in the app itself.

Looks like we gonna have this oficial in HA in the Next release :

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