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

@fenty17
oh the webhook! I totally forgot about that… I haven’t actually set that up as I didn’t think I needed it. I am a little confused with the webhook does then? My Shopping list already updates when I add something both via alexa or via the shopping list in HA directly. I mean… Both directions update all of the chain

HA > TodoList > Alexa
Alexa>Todolist> HA

All work, so what is the webhook for?

The webhook is simply a mechanism for triggering an automation. In my case it triggers the pyscript to sync the shopping list and a refresh of my mounted tablet dashboard.

@fenty17

right! yes makes sense, just setting it up now although it doesn’t seem to be firing. Got my webhook call back URL setup properly as far as I can see and I can also see my app under integrations…

Any clues as to any logs I can look at to see why it might not be firing?

Maybe check the settings of the webhook trigger. Settings cog icon next to the webhook id in the trigger part of your automation. Make sure ‘Only accessible from the local network’ is unticked. There’s another way to get to those settings, just can’t remember right now!

Thanks!

That was indeed turned on, didnt know that was even there so that is good to know. That looks like it was it. I thought it wasn’t working at first as expected the event to fire instantly but there does seem to be some delay. Once I was patient enough to leave it it does look like it works.

So back to your original suggestion, I should be able to trigger a notification off the back of this now

Thanks again @fenty17 I will let you know once I get the notifications working.

by any chance do you know how to extract the data from the JSON webook payload to use in a notification? When I run the trace in the webhook automation I can see the content: in the event data but I am not sure how I get at it?

image

I think in your notify action you can use the template:

{{ trigger.json.event_data.content }}

I don’t do this myself so guessing a little here. You will need to add a few test items to your list whilst trialling this until you are happy with it! And yes the slight delay you mention is expected.

Just to let you know that you were spot on and that worked perfectly!

Thanks so much for all your help!

Shame you can’t drive multiple lists with this thing.

Great! Very glad I could help. Yeah no idea why HA doesn’t allow mutiple lists instead of just shopping list. Seems like it would be such a simple thing to add on!

Hi All!

I have set up the Alexa-Todoist skill, and my todoist list updates, if I say something to Alexa.
I also downloaded pyscript, created the folders and files, and copied the API key and the project ID (which should be “alexa-shopping-list-111111111”, not just the numbers right?) to the code.
After that, I restarted everything and wanted to call the service, but it says “Unable to find service pyscript.sync_shopping_list”, and in the log it is unknown error.
Any ideas, what might help?
Thank you!

Nope, it’s just the numbers :grin:

Okay, than at least this is clear now!
But it is still unable to find service… I double checked the name of the folders and files

I’m having the same problem. After installing pyscript, I had restarted my whole raspberry pi. I uninstalled and reinstalled the Shopping List integration. Double checked that I have /config/pyscript/shopping_list_sync.py and /config/pyscript_modules/write_file.py I tried the code from MrLemur (with the v2 changes) and from fenty17. Just can’t get the pyscript.sync_shopping_list service to show up!

In my experience at least two restarts are needed to make the pyscript service appear.

Is the pyscript integration create any folder in the config? Because I created both the /pyscript and the /pyscript_modules folders manually. I wonder if I should reinstall it, but I don’t know what is the change that I am looking for, that tells me the process was successful.

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 :