Syncing Alexa/Google with the Shopping List

Alrighty, after working on this for a little bit and not finding clear answers I finally figured it out and thought I would share how:

NOTE: I use Nabu Casa Cloud. If you don’t you need to set up HTTPS. I cant help with that, but I can highly recommend just using the cloud.

Step 1: In the Home Assistant UI go to configuration -> integrations -> (+) and add IFTTT as an integration. This will give you the URL

Step 2: Add this to automations.yaml

- id: webhook
  alias: 'Webhook Recieved'
  hide_entity: False
  initial_state: 'true'
  trigger:
    platform: event
    event_type: ifttt_webhook_received
    event_data:
      action: call_service
  action:
    service_template: '{{ trigger.event.data.service }}'
    data_template:
      name: '{{ trigger.event.data.name }}'

Step 3: Format your IFTTT aplet. Use whatever If statement (In this case Added item to shopping list), and

URL: Taken from IFTTT integration
Method: Post
Content Type: Application/JSON
Body:

{ "action": "call_service", "service": "shopping_list.add_item", "name": "{{AddedItem}}"}

Step 4: Add items! It should work. It does for me

5 Likes

See above post I made for help

I tryied buto don’t work for me

this is my action

{ “action”: “call_service”, “service”: “shopping_list.add_item”, “name”: “$”}

is right?

I have this error

Error while executing automation automation.ifttt. Invalid data for call_service at pos 1: extra keys not allowed @ data[‘entity_id’]

Thanks

I tryed also

{ “action”: “call_service”, “service”: “shopping_list.add_item”, “name”: {{TextField}}}

but nothing happen

Thanks

Did you put the automation for IFTTT Webhooks in your automations.yaml (or wherever your automations are). Make sure that is exactly as I have in my above code. It has to match the format exactly. If you use IFTTT for other webhooks and have “data_template: entity_id” not “data_template: name” it wont work. I dont use IFTTT for anything else so I didnt attempt to solve using data of multiple types.

Thank for yor answer the problem seem to be the action, because if i write

{“action”: “call_service”, “service”: shopping_list.add_item", “name”: “’$’”}

‘S’ is memorazed in the shopping list

my problem is to pass the ingredient from the action to HA. I made a lot of test without success!

It works… a stupid error… i was tired last night! Thanks for your script!!!

Glad you got it working, sorry for not following up sooner, been busy and out of town.

I’m having a hard time wrapping my mind around this.
I see this as adding an item, but how does it remove one from Alexa?

Nice, I’m glad adding items works, I’ve only had a quick glance at the shopping list docs:

Would just calling the Service shopping_list.complete_item service not remove the item?

Also is IFTTT easy enough to set up to do this? I may give this a try myself at some point.

EDIT: Oh I see you’re trying to make it so NodeRED is able to remove items from the Alexa shopping list, that my turn out to be a little more tricky, I can’t think of an easy way right now.

I also get it working to add an item, but when I attempt to clear out an item, it tells me the trigger is undefined.

Just want to add that you can check the items on the list in Home Assistant as well.

{ "action": "call_service", "service": "shopping_list.complete_item", "name": "{{CompletedItem}}"}

Love this, thank you!

If you need to use ifttt service calls with entity id’s, as well as as this - you can create simple webhook calls for each once you have integrated ifttt:


- id: shopping_list_webhook
  alias: IFTTT shopping webhook received
  trigger:
    platform: webhook
    webhook_id: shopping_list
  action:
    service_template: '{{ trigger.json.service }}'
    data_template:
      name: '{{ trigger.json.name }}'


- id: generic_ifttt_hook
  alias: IFTTT entity webhook received
  trigger:
    platform: webhook
    webhook_id: ifttt
  action:
    service_template: '{{ trigger.json.service }}'
    data_template:
      entity_id: '{{ trigger.json.entity_id }}'

in IFTTT (using the above examples) you would use the following urls for the webhook:

Standard Entity automations: https://your.domain.here/api/webhook/ifttt
Shopping List automations: https://your.domain.here/api/webhook/shopping_list

I’m confused about how to set up Alexa and IFTT
I presume I need to add IFTTT to Alexa?
What triggers the IFTTT in Alexa when I say Add [item] to shopping list?

Hi dbrunt, the way it works is that IFTTT is doing the magic. Within IFTTT, you create a trigger that says: “If a new item is added to my Alexa shopping list [requires to link your IFTTT account with Amazon Alexa, native Alexa object in IFTTT], then add this item to Home Assistant [webhook in IFTTT]”.

I’ve followed the instructions from SMRThome and it works like a charm. However, my lovelace shopping card is not automatically refreshed. I’ve searched for several solutions and only found a way to achieve this using browser_mod.lovelace_reload, which requires the installation of the community integration of browser_mod. Isn’t there a native way to call a service within the automation, to force the shopping card to refresh when the shopping list is updated? Thx for your help.

I have both Add and Completed working from Alexa now.

Required

Configuration

IFTTT My Applets:
Create:

  • If Item added to your shopping list
  • Then Make a web request
  • URL:
  • Method: POST
  • Content Type : application/json
  • Body: { “action”: “call_service”, “service”: “shopping_list.add_item”, “name”: “{{AddedItem}}”}

Create:

  • If Item completed on your shopping list
  • Then Make a web request
  • URL:
  • Method: POST
  • Content Type : application/json
  • Body: { “action”: “call_service”, “service”: “shopping_list.complete_item”, “name”: “{{CompletedItem}}”}

Home Assistant Automation

alias: Webhook Recieved
description: ''
trigger:
  - platform: event
    event_type: ifttt_webhook_received
    event_data:
      action: call_service
condition: []
action:
  - service: '{{ trigger.event.data.service }}'
    data_template:
      name: '{{ trigger.event.data.name }}'
  - service: shopping_list.clear_completed_items
mode: single

The Lovelace panel seems to need a browser refresh/reload to display the new/modified shopping list…

2 Likes

Thanks for this discussion, I now have my Alexa Shopping List copying over to my Home Assistant shopping list. Has anyone managed to get it working in the other direction? As in when you update Home Assistant’s shopping list it updates Alexa?

@mlw05 I ended up going with the todolist plugin (Amazon Alexa support only) and it works surprisingly well! It allows me (and my wife) to add items via voice prompts as well as directly typing them in on the HA dashboard. You can cross off items by either asking Alexa to remove XYZ from the shopping list or deleting it off the card. I even built in some custom scripts to have it text the shopping list to either my wife or my cell phone when executed.

Hello,
I didn’t find a way to sync from HA to Alexa, so instead, I decided to clear the Alexa shopping list every week, just after a reminder is set.
If that could be useful to anyone, I do it as follows:
I call the service media_player.play_media on my Alexa dot, with the following data

{
   "media_content_type": "custom",
   "media_content_id": "clear the shopping list"
}

Then put a 5s wait node, and call the same service again with

{
   "media_content_type": "custom",
   "media_content_id": "yes"
}

(because Alexa asks to confirm if I want to clear my shopping list - the above confirms the action)