New service calls and sensors for shopping list component

Thx, I stumbled upon this. My plan is to scan a barcode before throwing away the packaging and have the product added to a shopping list automatically. I have no idea how to do it but it’s good to know it is possible and sooner or later I’ll archive it :slight_smile:
I wonder if we could use the smartphone to scan the barcode or does it have to be a dedicated barcode scanner?
Also, current state is that the scanned barcode has to be manually linked to a product? Or is there some way to browse a db for the barcode to get the product automatically?

I’m kinda in the same boat as you… knowing it’s possible I was able to back-burner it while I get the rest of my system up to that level.

Without going back and looking- I think using a cell phone camera and external database are both things that were being worked towards, but I paid both limited attention as I have a wireless/wired barcode scanner I impulse bought from Amazon and a desire to review the items in my database both to make sure everything is configured properly (locally available brands of milk are all identified as ‘milk’) and to keep my local database to a reasonable size.

(also- the technical details of someone providing a free UPC database make me reluctant to invest too much time and effort into dependency on one source… that’s a lot of data to move and there is a reason paid databases have hefty price tags.

I didn’t even know the name of those barcodes. I found https://devs.upcitemdb.com/ and they offer free api access for 100 requests per day. Do you think this could be inteterated/connected to grocy somehow?
I mean this website probably is more for american items, I guess. I’d need sth. with european stuff.

This sounds good: https://github.com/grocy/grocy-pyscanner
Edit: oh…did you write this? :smiley:

Oh, no… I’m not affiliated with Grocy in any way… just a potential user that was happy to see there was functionality out there to handle what I consider to be an important part of my future ‘assistive human habitat’. …I’m the kind of shopper… ‘Ya know… I haven’t bought q-tips in a while’… next thing I know- I have 6 tubes of toothpaste in my bathroom closet… 9 sticks of deodorant… 6 boxes, totaling 7,500 q-tips…

…I haven’t bought shower gel in 3 years. Still have at least 2 in the closet.

Sorry… went off on a tangent… as far as database/api calls… whether 100/day is enough… depends on, well… how many things you buy when you go shopping and how the program handles lookups… if it checks the local database first or if it sends every call to the service provider.

That said- if shopping days are light in your house or your product selection… it’d be pretty hard to exceed 100/day, really…

also: …it looks like Grocy addon ‘BarcodeBuddy’ might be headed in the direction you’re looking to go.

Thx for teh addon link. 100/day is more than enough, I just need to find a database with free api calls that has products specifically sold in austria :smiley:

Eh… give building your own database a go. I briefly played with it when I found the addon and had a workflow that went something like 'go shopping>take a picture of each item I buy using my phone camera>using the browser on my phone- create basic item records, add item pictures>move over to my laptop and review/revise the item records there>adjust and tweak accordingly.

That said- I used my wireless barcode scanner via my laptop for that part of the process. your mileage may vary.

What did you use in the Body portion of the IFTTT webhook?

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

I cant seem to find the right commands to fire the shopping_list.add_item service. I have other webhooks running so I know that the issue is only in what I am using for the body.

Nevermind, I figured this out. For anyone who runs into this issue in the future:

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

AND in 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 }}'

Hay bro

thanks :beers:

That was so easy thanks

I am fairly new to home assistant. I have loaded your python script and am able to see the call service for the script, however when I run it nothing is sent. I replaced XXX, YYY, ZZZ, and BBB with [email protected] and password for password. I also update the path to my .shopping_list.json (I am running docker on UNRAID so its in my root folder so just “.shopping_list.json”. I also went and changed my security settings in gmail, is this script still working is there a change required?

This is the error I am getting:

Log Details (ERROR)

Logger: homeassistant.components.shell_command
Integration: shell_command , issues)
First occured: 11:14:12 AM (2 occurences)
Last logged: 11:24:39 AM

Error running command: python_scripts/shopping_list.py, return code: 126

NoneType: None

Sorry for being a bit oftopic here, but I’d like to propose a new function to Shopping List and since everyone here are using it - I think it may be a good place to bring attention.
Please vot for it here: Shopping list - add possibility to reorder items

It would be great and very usefull to have a ShoppingList Sensor directly in HASS…
I want to create App notification, if something on my list and I am currently in my default supermarket.

Grocery is overkill, thats not an alternative.

I hope that you can make this happen!

I know that this topic is a little old, but I have made some modifications on the python script from @Mark_Meijer to create a more complete sensor for shopping list

This is the first time that I do something in python, so be nice :wink:

sensor:
 - platform: command_line
   name: Shopping List
   command: python3 /config/python_scripts/shopping_list_json.py
   json_attributes:
     - not_complete
     - content
   value_template: '{{ value_json.state }}'
#!/usr/local/bin/python
# coding: utf8
import json

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

class shoppingList:
    content = u""
    not_complete = 0
    state = u""

myList = shoppingList()

myList.not_complete = 0
myList.state = ""
myList.content = ""

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

if myList.not_complete == 0:
    myList.state = u"empty"
else:
    myList.state = u"not_empty"


print(json.dumps(myList.__dict__))
2 Likes

With storing the output from the posted python scripts in a command line sensor state there is a problem.

A state can only store max. 255 chars. So the shopping list can not get too long.

Different method is to call the shopping list JSON directly from the undocumented API using a REST sensor. However the value template ignores the “complete” status, which isn’t a problem for me. Nice and simple :grinning:

# Shopping list
- platform: rest
  name: Grocery List
  headers:
    authorization: !secret shopping_list
    content-type: 'application/json'
  resource: http://<HA-IP>:8123/api/shopping_list
  value_template: "{{ value_json | map(attribute='name') | list | join(', ') }}"
  method: GET
  scan_interval: 60

More information can be found here

1 Like

Biggest FR I need for shopping list is to be able to limit the amount of items shown by the shopping list card. Mine gets so long it takes over my whole dashboard!

Did u find a way how to do this?

Nope, I didn’t pursue this further.