Home Assistant Community Add-on: Grocy

Hi, can you tell me how you got your printer working. I’m not sure what you mean by adding device during install. I have my addon already installed and working.

@frenck, would it be possible to add setting to the yaml to add a thermal printer, or is this already an option?

I never succeed to add a thermal printer in grocy’s server… but I found a better way to adapt my printed shopping list:

I wrote a php code in another server running on a RPi using Grocy’s API, and I plugged the thermal printer on RPi.

1 Like

Hi,
Could you possibly share the code and what I need running on the pi. Thanks

Hi,

  • Install php dependancies,

  • Plug your thermal print, then : ls /dev/usb/lp*
    The result is the way to your printer. For the following, I guess the way is lp0.

  • Then, create a file print_list.php (for example, but you can name it as you want) and insert:

<?php

// Set the new timezone
date_default_timezone_set('Europe/Paris');
$date = date('d-m-y h:i:s');

            /* ASCII constants */
            const ESC = "\x1b";
            const GS="\x1d";
            const NUL="\x00";

            $server = "http://your_internal_ip:9192/api/";
            $api_key = "?GROCY-API-KEY=your_grocy_api";
            $printer = "/dev/usb/lp0";

            $url = $server . "objects/shopping_list" . $api_key;
            $jsonobj = file_get_contents( $url );
            $arr = json_decode($jsonobj, true);

            echo ESC."@"; // Reset to defaults
            echo ESC."E".chr(1); // Bold
            echo ESC."a".chr(1); // Centered printing
            echo "Stock of the house\n";
            echo $date;

            echo ESC."d".chr(2); // 2 Blank lines
            echo "List of things\n";
            echo ESC."E".chr(0); // Not Bold

            $elementCount  = count($arr);

            $x = 0;

            while($x <= $elementCount-1) {
              $product_id = $arr[$x]["product_id"];

              $amount = $arr[$x]["amount"];

              $url_product = $server . "stock/products/" . $product_id . $api_key;
              $RecupUrl_product = file_get_contents( $url_product );
              $arr_product = json_decode($RecupUrl_product, true);

              $name = $arr_product["product"]["name"];
              $unity_singular = $arr_product["quantity_unit_stock"]["name"];
              $unity_plural = $arr_product["quantity_unit_stock"]["name_plural"];

              $x++;

              if ($amount <= 1) {
                 $str = htmlentities("$name ($amount $unity_singular)", ENT_NOQUOTES, 'utf-8');
                 $str = preg_replace('#&([A-za-z])(?:uml|circ|tilde|acute|grave|cedil|ring);#', '\1', $str);
                 $str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str);
                 $str = preg_replace('#&[^;]+;#', '', $str);

                 echo $str;
                 echo "\n";
              }

              if ($amount > 1) {
                 $str = htmlentities("$name ($amount $unity_plural)", ENT_NOQUOTES, 'utf-8');
                 $str = preg_replace('#&([A-za-z])(?:uml|circ|tilde|acute|grave|cedil|ring);#', '\1', $str);
                 $str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str);
                 $str = preg_replace('#&[^;]+;#', '', $str);

                 echo $str;
                 echo "\n";
             }

            }

            echo ESC."d".chr(2); // 2 Blank lines

/* ############################################################################################  */

            $url_missing = $server . "stock/volatile" . $api_key;
            $jsonobj = file_get_contents( $url_missing );
            $arr = json_decode($jsonobj, true);

            echo ESC."@"; // Reset to defaults
            echo ESC."E".chr(1); // Bold
            echo ESC."a".chr(1); // Centered printing
            echo "Missing Products (at least)\n";
            echo ESC."E".chr(0); // Not Bold

            foreach($arr["missing_products"] as $item)
            {

                    $product_id = $item["id"];
                    $url_product = $server . "stock/products/" . $product_id . $api_key;
                    $RecupUrl_product = file_get_contents( $url_product );
                    $arr_product = json_decode($RecupUrl_product, true);

                    $name = $item["name"];

                    $min_stock_amount = $arr_product["product"]["min_stock_amount"];
                    $stock_amount = $arr_product["stock_amount"];

                    $missing_amount = $min_stock_amount - $stock_amount;

                    $unity_singular = $arr_product["quantity_unit_stock"]["name"];
                    $unity_plural = $arr_product["quantity_unit_stock"]["name_plural"];

                    if ($missing_amount <= 1) {
                       $str = htmlentities("$name ($missing_amount $unity_singular)", ENT_NOQUOTES, 'utf-8');
                       $str = preg_replace('#&([A-za-z])(?:uml|circ|tilde|acute|grave|cedil|ring);#', '\1', $str);
                       $str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str);
                       $str = preg_replace('#&[^;]+;#', '', $str);

                       echo $str;
                       echo "\n";
                    }

                    if ($missing_amount > 1) {
                       $str = htmlentities("$name ($missing_amount $unity_plural)", ENT_NOQUOTES, 'utf-8');
                       $str = preg_replace('#&([A-za-z])(?:uml|circ|tilde|acute|grave|cedil|ring);#', '\1', $str);
                       $str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str);
                       $str = preg_replace('#&[^;]+;#', '', $str);

                       echo $str;
                       echo "\n";
                    }

            }

            echo "--------------------------------\n";
            echo ESC."d".chr(2); // 4 Blank lines

?>
  • To test to print: php print_list.php > /dev/usb/lp0
2 Likes

Thank you very much, have got it working, just trying to change the layout now so it prints product on the left side and amount on the right side.
Got it all sorted, just how I want it. Thanks again

Hello
the grocy module works but when I try to connect the android application via api I get an error message => create a long term access token in your home assistant profile settings
But I can’t find where to perform this action. I’ve only found the api key generation with qr code sounds.

You can create a long term token at the bottom of your profile page in Home Assistant → https://[your url]/profile

This maybe a dump question but where does Grocy addon store the data? Can it be exported for backup or to import it on another Grocy server? I was thinking that maybe putting it on HA it may fill up my NUC so I was thinking of creating another server of Grocy on my UnRaid with a docker container. The issue is, is there a way to sync both or have one export to the other? Just curious if that can be done.

1 Like

To copy the data file, you can you this sort of command:

sudo docker cp 0c1ac9440306:/var/www/grocy/data/ /home/

But I don’t know if you can simply copy the file in an other server to recover your information…
Let us know the result :slight_smile:

Hi there,
i build an ESP-32 Barcodescanner with MQTT controlls/sensors.
The scanner has three modes

  • scan and consume
  • scan and add
  • scan (only to show the product data)

when you are interested look here

1 Like

Am I the dumbest person in the ha world? I created 4 chores but don’t see them in entities. Am I missing a step?

Hello, I installed Grocy as an addon in HomeAssistant.
To use Grocy via a browser I opened port 9192 without SSL. The website can now open without any problems.
I can create new products and also enter purchases into the database. What is not possible is to use up a product. When I selected a product and sent the process with the OK button, nothing happened except for a rotating mouse cursor. Even after waiting for a long time, nothing happens and no product is deleted from the database.
I then also installed the Grocy app on my smartphone and successfully connected it to the Grocy server. Using my smartphone, I can add new purchases to the database as well as delete products from the database using the consumption function.
I can’t find any explanation for the error and hope that you can help me with the problem.
I use the following versions:

Core
2024.2.1
supervisor
2024.01.1
Operating system
11.5
Front end
20240207.1

Grocy
Current version: 0.21.0

greeting
dnwalker

I wish I can use Grocy add-on with Grocy-Tablet. Is there any way I can integrate this?

Do you mean the Grocy app on the tablet?

It’s web app based on Grocy nginx config. I want to use this at Fully kiosk using http://homeassistant.local:9192/grocy-tablet

I’ve had Grocy working great for a while but suddenly when I click on several tabs from the web interface (like Shopping List, Purchase, and many others) I get a blank page and the logs show a memory error message:

2024/03/28 08:53:54 [error] 379#379: *19 FastCGI sent in stderr: “PHP message: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /var/www/grocy/packages/morris/lessql/src/LessQL/Row.php on line 72” while reading response header from upstream, client: REDACTED, server: a0d7b954-grocy, request: “GET /purchase HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9002”, host: “REDACTED.ui.nabu.casa”, referrer: “https://REDACTED.ui.nabu.casa/api/hassio_ingress/REDACTED/stockoverview

and so on… same error for the other tabs that don’t work.

The Grocy version is 4.0.3. which should be the latest Add-On version.

Core
2024.3.3
Supervisor
2024.03.1
Operating System
12.1
Frontend
20240307.0

There is a addon available to scan barcodes to Grocy, but it doesn’t have the option to connect a barcode scanner to the HA server itself.
I’ve cloned the repo, modify some code and made it possible to connect a barcode scanner.
At this moment I don’t have a barcode scanner available to test it, so please be my guest and try my modification. If you add my custom repository to the system, then you will be able to download it en test it.

Let me know if you find any errors or problems.

After updating the addon some days ago i got this error on trying to view or configure shopping lists (backup restored - working again):

General error: 1 no such table: shopping_lists_view (View: /var/www/grocy/views/shoppinglist.blade.php)

Is there a way to remove these from the items that are expired?

type: entity
entity: binary_sensor.grocy_overdue_products
attribute: overdue_products
state_color: true