New service calls and sensors for shopping list component

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.