Request for Shopping List service

So, I came up with a ‘solution’ that works for me. I can complete my whole shopping list by pushing an actionable push notification. Just what I wanted. Here’s my workaround:

Create a sensor of the shopping list (found somewhere on this forum):

#!/usr/local/bin/python
# coding: utf8
import json

with open('/config/.shopping_list.json') as data_file:
    shoppingListData = json.load(data_file)

content = u"Boodschappen:\n"
for entry in shoppingListData:
    if not entry['complete']:
        content += u"- %s\n" % entry['name']

content += u"\n"

print(content)

Name this shopping_list.py and place it in your /config folder.
This creates a list with all items on your shopping list. I let Home Assistant send me this list when I enter the zone of my local supermarket.

Add this to your config file:

ios:
  push:
    categories:
      - name: Empty Shopping List
        identifier: 'empty_shopping_list'
        actions:
          - identifier: 'EMPTY'
            title: 'Empty'
            destructive: true
          - identifier: 'KEEP'
            title: 'Keep'

sensor:
  - platform: command_line
    name: shopping_list
    command: python3 /config/shopping_list.py

automation:
# Action when triggering 'Empty Shopping List' button from actionable push notification

- alias: ios actionable empty

  trigger:
    platform: event
    event_type: ios.notification_action_fired
    event_data:
      actionName: EMPTY

  action:
    service: script.toggle
    entity_id: script.empty_shopping_list

script:
# Splits the information of sensor.shopping_list and completes this item on shopping list

'empty_shopping_list':

  alias: empty shopping list

  sequence:

  - service: shopping_list.complete_item
    data_template:
      name: >-
        {{ states.sensor.shopping_list.state.split('-')[1] }}
  - service: shopping_list.complete_item
    data_template:
      name: >-
        {{ states.sensor.shopping_list.state.split('-')[2] }}
  - service: shopping_list.complete_item
    data_template:
      name: >-
        {{ states.sensor.shopping_list.state.split('-')[3] }}
  - service: shopping_list.complete_item
    data_template:
      name: >-
        {{ states.sensor.shopping_list.state.split('-')[4] }}
  - service: shopping_list.complete_item
    data_template:
      name: >-
        {{ states.sensor.shopping_list.state.split('-')[5] }}
  - service: shopping_list.complete_item
    data_template:
      name: >-
        {{ states.sensor.shopping_list.state.split('-')[6] }}
  - service: shopping_list.complete_item
    data_template:
      name: >-
        {{ states.sensor.shopping_list.state.split('-')[7] }}
  - service: shopping_list.complete_item
    data_template:
      name: >-
        {{ states.sensor.shopping_list.state.split('-')[8] }}
  - service: shopping_list.complete_item
    data_template:
      name: >-
        {{ states.sensor.shopping_list.state.split('-')[9] }}
  - service: shopping_list.complete_item
    data_template:
      name: >-
        {{ states.sensor.shopping_list.state.split('-')[10] }}
       

This works for me, and maybe someone else. The only thing that I’m left with is a completed list. Can’t find a way to delete completed items without clicking on the icon.

@moostmartijn I found this discussion while trying to work out how to send notifications based on location, I was wanting to send the shopping list out as a notification when someone was as the shops :slight_smile: I see you had already worked out how to do that, are you using goefencing? Any chance you can give an overview of what your doing? Thx.

@Eoin, Yes I use geofencing. I set up a zone for my local supermarkets:

zone:
  - name: Jumbo
    latitude: !secret latitude_jumbo
    longitude: !secret longitude_jumbo
    radius: 100
  - name: Albert Heijn
    latitude: !secret latitude_albert_heijn
    longitude: !secret longitude_albert_heijn
    radius: 150

I use Life360 as a device tracker and added this automation when I enter the zone which includes my Shopping List and actionable push notification:

# Send the shopping list items as an iOS notification when I enter the shop zones zone.jumbo and zone.albert_heijn

- alias: ios shopping list zones

  trigger:
  - entity_id: person.martijn
    event: enter
    platform: zone
    zone: zone.jumbo
  - entity_id: person.martijn
    event: enter
    platform: zone
    zone: zone.albert_heijn

  action: 
  - service: notify.ios_iphone_van_martijn
    data_template:
      message: '{{states.sensor.shopping_list.state}}'
      data:
        push:
          category: "empty_shopping_list" 
1 Like

Got this working last night moostmartijn, thank you! I did run into a problem with the .py, I’m using Android notifications rather than IOS, looks like Android doesnt like cartridge returns. Removed that to just have coma separated items and it works like a charm.

1 Like

Any updates on this project ? I am looking for exactly the same thing and if you can remove off the list as you buy, then that would be great.

I am using a 3rd party app at the moment (Owngroceries) but dont like doing this and its always last option.

I too am using Android, so hopefully someone will have found a way to list

Thanks Martyn

Since the release of 2020.09.0 it is now possible to make a service call to empty the shopping list.

Releae note:
’ * If you use the shopping list feature of Home Assistant, you can now remove all completed items at once using a service call. Thanks, @GrumpyMeow!’