Seems I’m late to the party, but I found this thread while looking if it would be possible to integrate the 2D barcode scanner I impulse bought on an Amazon Lightning Deal.
I’d like to have a component that would allow us to check household inventory if we make a random grocery stop, or to check when the last time we bought some random spice.
I want to support this request because I like the way the shopping list works and how it looks. However, I am struggling with working with the shopping list at the moment.
My intention is to send the filled shopping list via email and start a new one afterwards. At the moment, I am able to send it via email (using an external script reading the .shopping_list.json) but I have no idea how to clear the complete list to start a new one.
In the future, I also want to add voice control by snips. I guess the new services should help with that, so I already appreciate what has been done so far
Sure. It is just a little quick & dirty python code that I added as a shell command to homeassistant:
#!/usr/bin/python
# coding: utf8
import json, smtplib, datetime
sender='XXX'
reciever='YYY'
account='ZZZ'
password='BBB'
with open('PATHTOHOMEASSISTANT/.shopping_list.json') as data_file:
shoppingListData = json.load(data_file)
# build message
content = u"Shopping list:\n"
for entry in shoppingListData:
if not entry['complete']:
content += u"- %s\n" % entry['name']
content += u"\nThank you for shopping!"
mail=smtplib.SMTP('smtp.gmail.com',587)
mail.ehlo()
mail.starttls()
mail.login(account,password)
message = """From: %s\nTo: %s\nSubject: %s\n\n%s""" % (sender, reciever, "Shopping list", content)
mail.sendmail(sender,reciever,message.encode('utf-8'))
mail.close()
The code was tested using gmail. However it should work with other email providers by replacing the SMTP server accordingly. You need to enter the sender email address, the receiver email address and your mail account information that are hard coded (there certainly is room for improvements )
I’m wondering if someone is working on recognize 2D Barcode (specific hardware device or using image processing ?).
There is an API for matching barcode and a specific product. It could be cool to scan a barcode to automatically add the product to the shopping list.
This is great. Thanks for the simple python script. At first the sensor reported a status of unknown for me. I had to set the sensor up slightly differently in Hassio by prefacing the command with python3.
Hello All and Flovie in particular.
New to Homeassistant and Linux
Im trying to use your python script above but i dont know how to execute it.
I have created a folder under the homeassistant folder called “python_scripts” and created a send.py file there with your script , ofcourse edited with my e-mail address and path
home/homeassistant/.homeassistant/python_scripts/shopping_list.json
I dont know how to activate or run the script, can i create a button “send email” to run this script or can i controll it with a simple voice command?
Any help appreciated.
#!/usr/bin/python
# coding: utf8
import json, smtplib, datetime
sender='[email protected]'
reciever='[email protected]'
account='[email protected]'
password='xxx'
with open(' home/homeassistant/.homeassistant/python_scripts/shopping_list.json') as data_file:
shoppingListData = json.load(data_file)
# build message
content = u"Shopping list:\n"
for entry in shoppingListData:
if not entry['complete']:
content += u"- %s\n" % entry['name']
content += u"\nThank you for shopping!"
mail=smtplib.SMTP('smtp.gmail.com',587)
mail.ehlo()
mail.starttls()
mail.login(account,password)
message = """From: %s\nTo: %s\nSubject: %s\n\n%s""" % (sender, reciever, "Shopping list", content)
mail.sendmail(sender,reciever,message.encode('utf-8'))
mail.close()
I didn’t get the correct indentation working in this example, so be careful with copy&paste. This code will expose the python code as a service to your home assistant.
3. You are free to call this service how you like. May it be voice command or an automation.
If you are in a more restricted environment, then you should take a look at the code by Mark_Meijer and use a notification component of your choice.
I hope this helped you out and pointed in the right direction.
Thank you Flovie
Yes that helped me, i have it all working now.
Ran into more problems with gmail thoo, they have beefed up their security and default setting is Not to allow unsecure apps to e-mail. I logged into my gmail and under “security…” there was an option to turn off the setting for unsecure apps.
not sure about google home. but i manage to sync the shopping list with alexa shopping list using IFTTT. Whenever Alexa shopping list is updated (i.e. item added or remove), IFTTT will update my HA shopping list via webhook.
I would like to get a easyer way to have a inventory list for all my food storages. Eg one for the freezer and a other food storages like the dry cabinets and the fridge.
Now I use google shopping lists: https://shoppinglist.google.com
With google home I can use voice to add items to my primary list and all family members can do the same.
With NFC stickers I can open a spesific inventory list for the cabinet. This could also be done with QR code and camera on the phone (just opens a url).
But for a better user experience it would be good to be able to scan the barcode on my item as I put it in the trashcan, then it would be removed from my inventory list and added to the main shopping list.
Same if I put a new item into the freezer I culd just scan the barcode with the phone and it would update the inventory for the freezer.
So my wishlist for the shopping list is:
The ability to add/remove items with a QR/barcode scanner for a spesific list.