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

This fixed it for me too! Thanks!

Hopefully someone might answer this. Is it possible to keep the items in the HA shopping list when you sync them with Alexa etc?

I wanted to share that for the last few weeks my HA install has been freezing every few hours and I couldn’t figure out the reason, and the cause was this script. It was blocking the whole system in a never-ending sleep.

For now I’ve disabled it, I’ll try the second version when I have some time.

Just wanted to add, that I had the same problem as cibernox and also searched for days, maybe weeks what caused the problem.
I just tried the new script and it seems like that fixed it. Won’t know for sure until some days without issues passed, but it’s definetly worth the try, @cibernox !

Yeah it’s pretty ugly if you are stuck on the first version. Better just to disable it until you have the time to fix it properly.

is there an advantage to using aiohttp over the built-in task.executor, which takes the functions out of the IO loop:

https://hacs-pyscript.readthedocs.io/en/latest/reference.html?highlight=task.executor#task-executor

e.g.

response = task.executor(requests.get, url, headers=headers)

Any possibility to do this with a connected o365 calendar, where sharing isnt allowed? I could integrate it to alexa. Would be nice to do the same stuff as the todo list

This is really cool, thanks for making it!

I don’t have my HA instance exposed to the Internet and I’m a bit hesitant to punch a hole in my firewall. Would there be any way to have this poll the Todoist APIs rather than using a webhook? I know that’s less clean / efficient, but according to the Todoist v9 APIs the rule is that you shouldn’t hit the partial sync API more than 450 times in 15 minutes so it seems like hitting them once every few minutes should be okay…

Has anyone gotten to the bottom of why a webhook wont work in todoist?
Anything I do on the shopping list in Home assistant is replicated on the todoist website in around 2 seconds.
Any changes made on the todoist site need a manual sync, at which point the lists sync.
So all working fine apart from todoist not getting a message to HA to trigger the sync. The Automation is fine as if I manually fire it the list syncs too.
What am I missing in Todoist?
I can see in the app setup that the webhook status is “active”
The callback url is my https://nabucasa address82.ui.nabu.casa/api/webhook/-FlgBBIganDsMallLetters
I have all the item watched Events selected

If you get creative you can set up a free AWS account and set up a simple relay. I use API gateway to put messages onto an SQS queue from various endpoints (for different purposes, the todoist webhook is one). I then have a docker inside my LAN running a simple python script that reads the queue and passes on the messages to whoever needs to know (in this case it calls the HASS webhook). The call and message rate is so small you easily stay in the free tier. If anyone is interested I can share more details.

When you manually fire the automation is that from inside Hass or using curl? To rule out any issues with the webhook have you tried firing it from curl if you haven’t already:
curl -X POST <the webhook url>

Well i;'m not sure how but the reboot gods seem to have deemed me worthy. After a few restarts for other updates this seems to be working now.
Thank you for responding though guys.

Is this path still working? I tried several months back and it didnt work for me. My HA just hung up sevral times and i had to backup. Maybe ill give it a new try

Since HA 2023.06 I got this error with this script. Someone else with the same issue?

 Logger: custom_components.pyscript.file.shopping_list_sync
Source: custom_components/pyscript/global_ctx.py:341
Integration: Pyscript Python scripting (documentation, issues)
First occurred: 16:00:09 (14 occurrences)
Last logged: 16:27:14

    Exception in </config/pyscript/shopping_list_sync.py> line 10: import write_file ^ UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9e in position 0: invalid start byte
    Exception in </config/pyscript/shopping_list_sync.py> line 12: write_file = reload(write_file) ^ NameError: name 'write_file' is not defined
    Exception in </config/pyscript/shopping_list_sync.py> line 6: import write_file ^ UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9e in position 0: invalid start byte
    Exception in </config/pyscript/shopping_list_sync.py> line 7: import write_file ^ UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9e in position 0: invalid start byte
    Exception in </config/pyscript/shopping_list_sync.py> line 11: import write_file ^ UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9e in position 0: invalid start byte

1 Like

So, I figured it out. It turns out my pyscript_modules/write_file.py got corrupted, so I couldn’t load the script. I simply retrieved a backup and restored it, and the script started working again!

1 Like

Only put the number part of your project URL. I did the same mistake (the instructions are misleading). :wink:

You should never call time.sleep() from pyscript. That will cause the main HA event loop to block, and you’ll see a warning from HASS about that.

Instead, replace each time.sleep() with task.sleep(), which does the correct asynchronous sleep. See this github issue.

I’m getting the following error:
Exception in </config/pyscript/shopping_list_sync.py> line 10: import write_file ^ ModuleNotFoundError: No module named 'write_file'

EDIT: restarting home assistant after installing pyscript fixed this error

if anyone is having issues where the service doesnt show up to sync shopping list. my pyscript install created a folder in config as config/pyscript but the sync file references config/pyscript_modules so I opted to change this in the file if “/config/pyscript” not in sys.path:
sys.path.append("/config/pyscript") and it now shows up after a restart

Hello everyone! I’m quite new with this so I’m not sure what’s wrong…

I’m trying to have this script working. I have already installed VStudio, Terminal, HACS, Pyscript. Added the “shopping_list_sync.py” file, and dumped the code there (from fenty17 GitHub).

The codes makes a reference to config/pyscript_modules, but it doesn’t exists or was not created when I installed Pyscript. So I change the refence to “config/pyscript”, and added write_file.py on the same folder.

I even added a line to services.yaml (from config/pyscript folder):

sync_shopping_list:
  description: Sync the shopping list with Todoist API.

Anyway, I can’t call the service, or maybe I’m not doing it correctly. Because it’s not listed on Developer Tools > Services. Nor by itself, either using pyscript.sync…

Is there something I’m missing?

Todoist is correctly configured, the list ID is correct as I can access the list from the URL indicated on the code. And the API Token, I got it accessing my account, then going to Settings, Integrations, Developers.

Please let me know if you have any idea what I could’ve missed…

Thanks!!