- 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.
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).
The component provides two services: export and import.
export will take the main shopping list and create files based on the prefix.
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.
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:
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
Send a notification, use the list and mark the items as you normally would.
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
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