Multiple shopping lists based in zones

UPDATE: November 2023

I haven’t tried it but it might all be deprecated in favor of this 2023.11 To-do: Add release title - Home Assistant :heart_eyes:

DISCLAIMER:

  • it’s very rough, it’s my first time doing a custom component (and working with Python, for that matter)
  • it has some moving parts and requires some orchestration with automations, so might not be for everybody.
  • I know it has being discussed over and over, there’s even a feature request somewhere but this approach has worked for me.
  • If it’s stupid but it works, it’s not stupid. :smiley:

SITUATION AND GOAL

I buy stuff in different places, and I receive a notification with the shopping list when I enter certain zone. So I started adding prefixes to the items, for example:

  • SUPERMARKET - chicken
  • SUPERMARKET - salt
  • PHARMACY - Ibuprofen

This was not a bad solution specially if you sort the items alphabetically with the automation that sends the notification. But it was annoying to scroll through all the supermarket list to get to the ones below.

I wanted to only see the supermarket list when in the supermarket. Specially for the WAF.

So I added this rudimentary custom component that reads and writes the json file created by the Shopping List integration (/config/.shopping_list.json).

HOW IT WORKS

The component provides two services: export and import.

export will take the main shopping list and create files based on the prefix.

Screenshot 2023-06-07 at 14.06.09

It will also export an “all” file to be able to re-import the whole list.

import will import a list file, either an specific (supermarket, pharmacy) or the file containing all the items if “list_name” is not provided.

USAGE (Or at least how I use it)

1.- Add the items as you normally would, but with a prefix. For example in our wall mounted tablet, I have a bunch of predefined items that already contain the prefix.

2.- Once I leave zone.home an automation executes:

service: shopping_list_splitter.export

This will update each separate file.

3.- When I enter zone.supermarket, another automation executes:

service: shopping_list_splitter.import
data:
  list_name: supermarket

This will remove all the items from the shopping list and it will import the items from .shopping_list_supermarket.json

Send a notification, use the list and mark the items as you normally would.

Screenshot 2023-06-07 at 14.52.40

4.- When I’m back to zone.home, an automation executes:

service: shopping_list_splitter.import
data:
  list_name: all

It will add the -incomplete- items from all the files

Screenshot 2023-06-07 at 14.54.51

known issues

There are some conceptual problems, mostly related to synchronisation and usage, for example if two users enter different zones at the same time. or if one enter home while the other is in the supermarket. But this hasn’t been a deal breaker for us just yet.

I hope this helps :smiley:

2 Likes