Grocy - Custom component and card(s)

I would probably try to get a jinja template to iterate over the individual tasks and check the dates somehow and then put that in a template sensor/binary sensor and put the card in a conditional card based on that. Can’t help with the templating though, but should probably be possible.

1 Like

Manged to get is working with some forum help. I created to sensors that check if there are any chores or tasks:

- platform: template
  sensors:
    tasks_check:
      friendly_name: 'Tasks Check'
      value_template: >
        {% set days = 3 %}
        {{ state_attr('sensor.grocy_tasks', 'tasks')
        | map(attribute ='count')
        | list | count > 0 }}


- platform: template
  sensors:
    chores_check:
      friendly_name: 'Chores Check'
      value_template: >
        {% set days = 3 %}
        {{ state_attr('sensor.grocy_chores', 'chores')
        | map(attribute ='next_estimated_execution_time')
        | sort | reject('gt', (today_at()+timedelta(days=(days+1)))|string)
        | list | count > 0 }}

I could then use these in the conditional card to display a small chip to let me know there are chores / tasks due. This chip then takes me to my chores dashboard.

1 Like

On the add task section, would there be any way to add some sort of calendar popup to this? Or even better, to use the devices date picker??

Really nice!
As to the date picker, it would be nice. I added a feature request “issue”: Datepicker for add task · Issue #112 · isabellaalstrom/lovelace-grocy-chores-card · GitHub

1 Like

Hello Great work. I’ve implemented to make easier to deal with pellet stove.
With service i can add or consume pellet in stock.
What i’d like is to have an input number in lovelace to insert how many pellets bag i bought and pass this number with template to amount.
Is it possible?

Just downloaded the datepicker version - great work!!

I may be missing something basic, but while this custom card was working for the first week or so, now whenever I try to mark a chore as complete I am getting a 400 error “pygrocy.errors.grocy_error.GrocyError: <Response [400]>”. Can anyone point me in the right direction to fix this?

hi all,
I have installed and configured the integration but the entities are always unavailable

I tried to install both the latest stable version and the 4.10 beta version.
The Grocy addon is updated to the latest version 3.3.2 and is populated with some products and tasks
I have enabled all entities in the integration.

Home Assistant 2023.5.3

in the system logs I have this:

Source: helpers/update_coordinator.py:237
Integration: Grocy (documentation, issues)
First occurred: 14:43:12 (1 occurrences)
Last logged: 14:43:12

Error fetching grocy data: Update failed: 2 validation errors for ProductDetailsResponse quantity_unit_stock none is not an allowed value (type=type_error.none.not_allowed) default_quantity_unit_purchase none is not an allowed value (type=type_error.none.not_allowed)`Preformatted text`

where am i doing wrong?

Thank you, this solved my issue as well!

I’m must doing something very basic wrong here and I’m probably skipping a step.

If I change the port to 9192, Grocy will not start. If I leave default, I can’t get the integration to find the API key.

EDIT:
Home Assistant 2023.5.3
Supervisor 2023.04.1
Operating System 10.1
Frontend 20230503.3

So I have an idea, but I’m not sure how to execute it…
Current setup:
when my washer finishes, I use the grocy.add_generic service to add a task “move clothes to the dryer”.
when my dryer finishes, I use the grocy.add_generic service to add a task “bring the cloths up from the dryer”.

desired future setup:
I will add reed switches to the washer and dryer doors so i know when they are opened.
When the washing machine door is opened, i want to run the grocy.complete_task service, to complete “move clothes to the dryer”, but it requires the task_id. I know it is in the attributes of sensor.grocy_tasks, but I don’t know how to get that data in this context.

can someone point me in the right direction? (keeping in mind im not a jinja master)

Ok, I’m not sure it is the “right” way to do it, but I figured out a way to complete my desired setup.

I made some template sensors (one per task i wish to automatically complete)

sensor:
  - platform: template
    sensors:
      dryer_task_id:
        value_template: "{% for task in state_attr('sensor.grocy_tasks', 'tasks') %}{% if task.name == 'Bring up clothes from the Dryer' %}{{ task.id }}{% endif %}{% endfor %}"
      washer_task_id:
        value_template: "{% for task in state_attr('sensor.grocy_tasks', 'tasks') %}{% if task.name == 'Move clothes to the dryer' %}{{ task.id }}{% endif %}{% endfor %}"
      dishwasher_task_id:
        value_template: "{% for task in state_attr('sensor.grocy_tasks', 'tasks') %}{% if task.name == 'Empty Dishwasher' %}{{ task.id }}{% endif %}{% endfor %}"

and now im able to use those in an automation:

alias: "Grocy: Complete dryer task"
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.dryer_door
    to: "on"
condition: []
action:
  - service: grocy.complete_task
    data:
      task_id: "{{ states('sensor.dryer_task_id') }}"
mode: single

If anyone sees a fatal flaw in my plan, I would love to know, otherwise, this seems like it will work for me.

Not fatal, but there’s no need for the sensors unless you have some other use for those pieces of information.

alias: "Grocy: Complete dryer task"
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.dryer_door
    to: "on"
condition: []
action:
  - service: grocy.complete_task
    data:
      task_id: |-
        {{state_attr('sensor.grocy_tasks', 'tasks')
        | selectattr('name', 'eq', 'Bring up clothes from the Dryer')
        | map(attribute='id')|first}}
mode: single
1 Like

this is exactly what i was looking for!
I was trying to get selectattr() working, but your answer shows me that i wasn’t even getting close :stuck_out_tongue:

You know what they say… ask for help, and you wont get a response for 4 days. Suggest a sub-par solution, and someone will correct you in an hour :wink:

thanks!

Ok. Started getting an error message on my Grocy component. The Grocy addon is running normally, on port 9192, so I removed the HACS component, rebooted, and then reinstalled it. When I try to start the component installation, I’m getting the following error:

image

Any ideas?

I only just installed Grocy and the integration, so I’m no expert. One oddity is that all the entities are disabled by default. You have to turn them on yourself.

Have the same problem. Has it been solved?

Have the latest Home Assistant, HACS and the AddOn. Here is my log:

Logger: homeassistant.util.package
Source: util/package.py:107
First occurred: 17:51:47 (3 occurrences)
Last logged: 17:51:59

Unable to install package pygrocy==1.4.1: ERROR: Cannot install pygrocy==1.4.1 because these package versions have conflicting dependencies. ERROR: ResolutionImpossible: for help visit Dependency Resolution - pip documentation v23.2.dev0

EDIT 26.06.2023: works for me with beta (v4.10.0)

Same for me. Same error: 500 server error.

OK get it solved. Just change the pygrocy in the manifest.json to version 1.5.0. Then restart HA.

{

“domain”: “grocy”,

“name”: “Grocy”,

“documentation”: “GitHub - custom-components/grocy: Custom Grocy integration for Home Assistant”,

“issue_tracker”: “Issues · custom-components/grocy · GitHub”,

“dependencies”: [

"http"

],

“config_flow”: true,

“codeowners”: [

"@SebRut",

"@isabellaalstrom"

],

“requirements”: [

"pygrocy==1.5.0"

],

“version”: “v4.8.0”,

“iot_class”: “local_polling”

}

1 Like

How to create Dashboard in HA with the sensors? I mean if there are products added to the shopping list, I would like to see them in a list. The sensor gives a value of items on the shopping list besides that the sensor gives attributes but these are nested attributes and there for difficult to extract in my opinion. Also for the sensor with expired products. The sensor gives the value on or off e.g. but I like to see what product. So that I can make a nice dashboard where I can see the status of my Grocy.

How to do this?

There’s another custom integration that has some example cards you may find instructive

You can also use a Markdown Card or other cards that accept templates, including Mushroom template cards.

type: markdown
content: |-
  {% for g_product in state_attr('sensor.grocy_shopping_list', 'products')%}
  {{ g_product.product.name }}
  {% endfor %}
title: Grocy Shopping List