Count items on the shopping list

Hi all,

Hoping I am overlooking something here, but I’ve checked through the developer area, but can’t find anything.
I wanting to know if there is a way to count the number of uncheck items on the Shopping List?

I have an automation that when at a Supermarket a notification is fired off to the person there if they want to check the shopping list, but ideally would like this only if there are actually items on the list, and do it as a prompt.

Thanks.

2 Likes

This question gets asked pretty often. I’ve seen the following suggested as a solution.

sensor:
  - platform: command_line
    name: "Shopping List"
    unit_of_measurement: "items"
    command: "jq '[.[] | select(.complete==false) | .name] | length' .shopping_list.json"

Might be worth updating the documentation if this works.

See:

2 Likes

Thank you for posting this. It does work

1 Like

Silly question but where does this go in the configuration.yaml?

When I put it in I get a dup key error which is obviously because I have the same as the sensor below? I am starting to think that my config file probably needs a re-org with all my sensors in one place under the sensor heading?

OK ignore me, I was being stupid. I have sorted it… It was too many “sensor” tags…

Hmm, it’s not working on my system. The custom sensor isn’t listed. Shouldn’t be this easier? I have no clue what the custom sensor is doing, so I have no idea where to look. Maybe the .shopping_list.json file is named differently on my system?

Update, the default sensor seems to work:

type: template
tap_action:
  action: navigate
  navigation_path: /dashboard-mushroom/todolists
icon: mdi:clipboard-list
entity: todo.shopping_list
content: '{{states(entity)}}'

You don’t need to make a template.
The sensor itself ‘todo.xxxx’ has the count as the value.

@seanmccabe
The template is used on the Mushroom Chips Card. My point was you don’t need the custom sensor mentioned earlier in this thread at all.
image

That was my point too.

This thread is old, was from before the shopping list was a todo item.