Unfortunately, my programming skills are not even close to being able to contribute… but I tried using the grocy
integration and have some thoughts:
- it would be nice if each product in the grocy database could be a
sensor
entity.
Example:
- entity_id:
sensor.grocy_stock_id_1_clif_bar_peanut_butter
- friendly_name
Clif Bar Peanut Butter
(= whatever the user has set as product name in grocy)
- attributes (I copied these values by looking at the grocy API; basically, use whatever is available because you never know what people might need it for)
- “id”
- “description”:
- “product_group_id”
- “active”
- “location_id”
- “shopping_location_id”
- “qu_id_purchase”
- “qu_id_stock”
- “qu_factor_purchase_to_stock”
- “min_stock_amount”
- “default_best_before_days”
- “default_best_before_days_after_open”
- “default_best_before_days_after_freezing”
- “default_best_before_days_after_thawing”
- “picture_file_name”
- “enable_tare_weight_handling”
- “tare_weight”
- “not_check_stock_fulfillment_for_recipes”
- “parent_product_id”
- “calories”
- “cumulate_min_stock_amount_of_sub_products”
- “due_type”
- “quick_consume_amount”
- “hide_on_stock_overview”
- “row_created_timestamp”
- “userfields”
- allow users to use these values in a service call
Example
- service: grocy.consume_product_from_stock
data:
entity_id: sensor.grocy_stock_id_1_clif_bar_peanut_butter
amount: 1
spoiled: false
transaction_type: "CONSUME"
- service: grocy.add_product_to_stock
data:
entity_id: sensor.grocy_stock_id_1_clif_bar_peanut_butter
amount: 3
price: 1.99
- allow users to correct stock information via service call
Example: I consumed 6 items by accident, when I meant to only consume 3. Of course, I could just use the grocy.add_product_to_stock
service from above to add another 3 to make up for the additional 3 I accidentally consumed; but it’d be nice to do something like this
- service: grocy.correct_stock_value
data:
entity_id: sensor.grocy_stock_id_1_clif_bar_peanut_butter
current_stock: 12
Let’s say somebody used a wireless barcode scanner and meant to scan an item once, but for some weird reason, it got submitted 200 times. The stock would actually be 1 (or whatever there was previously + 1), not 200. With a correct_stock_value
service, one could easily fix this - especially by creating an input_number.correct_stock_value
and doing this
- service: grocy.correct_stock_value
data:
entity_id: sensor.grocy_stock_id_1_clif_bar_peanut_butter
current_stock: "{{ states('input_number.correct_stock_value') }}"
Current situation
I don’t know if I set up grocy in a way that causes this (using both Home Assistant and grocy as (separate) docker services)… but I have immense trouble with the integration telling me correct stock values!
There is a zigbee button on the fridge that is supposed to keep track of the water and Club Mate bottles we have in the fridge…
In order to get the current stock, I needed to create sensors like this one
sensor:
- platform: template
sensors:
helper_mate_kuehlschrank:
friendly_name: "Mate"
unit_of_measurement: "Flaschen"
value_template: "{{ state_attr('sensor.grocy_stock', 'products')[2]['available_amount'] | int }}"
# icon_template: "mdi:cup-water"
entity_picture_template: "/local/img/bottle_mate.png"
While this would be fine, it seems like the number in brackets does not correspond with the actual product id grocy uses. The sensor.grocy_stock
only returns items that currently are in stock!! So, in this case, the “Mate” drink is currently "{{ state_attr('sensor.grocy_stock', 'products')[2]['available_amount'] | int }}"
and water is "{{ state_attr('sensor.grocy_stock', 'products')[1]['available_amount'] | int }}"
.
However, and this is bad: when there is no water left in the fridge (-> stock amount = 0
), water vanishes from sensor.grocy_stock
, therefore “Mate” suddenly becomes "{{ state_attr('sensor.grocy_stock', 'products')[1]['available_amount'] | int }}"
(the number changed)
I don’t know how relevant this is for the rest of you. But we use TTS for this (take a bottle of water and hear There are only <x> bottles left in the fridge
. This is not a matter of live and death, as one sees the amount of bottles left when taking one, anyway. But if we have the means to integrate this into Home Assistant, it should be reliable.
What’s also very confusing is that one would make sure to both
- have at least 1 product of whatever is in stock left (because when it reaches 0, it will disappear from the
sensor.grocy_stock
sensor) and
- always to double check when writing automations. ==> I naturally assumed that, when water is product_id 2, it will also be
(...)[2](...)
in the sensor. However, that is not the case. Let’s say some product is product_id 24, but all other products are out of stock… then it would be (...)[0](...)
, not (...)(23](...)
. When you know this, you can work with it. But it is counter intuitive and confusing.
Sorry, I hope this doesn’t come across like I just want to bash the project!! I love that there even is a grocy integration (when I tried integrating it myself years ago, I used HTTP calls). I just wanted to mention these things because I am trying to get more things done with grocy, and these things I mentioned made things a bit difficult. But perhaps the person who wrote it never wanted to actually display the amount of available stock in lovelace and that’s why they didn’t consider it… so I thought it wouldn’t hurt to just mention The service calls were just another idea, because Home Assistant becomes more and more configurable via the webUI, and if every single item (regardless of the current stock amount) would be a sensor starting with sensor.grocy_stock_id_*
, one could even find the desired product via dropdown menu instead of having to manually find the product_id via grocy API).