Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for by barcode #324

Open
phil-schneider opened this issue Jan 14, 2025 · 6 comments
Open

Support for by barcode #324

phil-schneider opened this issue Jan 14, 2025 · 6 comments

Comments

@phil-schneider
Copy link

Hello,
Are there an Plan to Support Operations by barcode?
Like "Add Product To Stock" or "Consume Product From Stock"
I have a barcode Scanner and want to use Service to add or cobsume from Stock.
I saw the python api Supports this.
If there are no plans, is there a Chance that a PR will get accepted and merged?
I would create a fork, work on this and if everything is working create a PR back to you.

What Do you think?

@phil-schneider
Copy link
Author

So a short update:
I have a version working with "by barcode". Need to spend some more time. But I can add a product to stock or consume a product to stock all by barcode instead id.

Why is this needed? Because this:
https://github.com/SmartHome-yourself/barcode-scanner-for-esphome
I want to change the code from this esphome, to read the ean barcode and call the service.

What is needed, besides running code, for a pull request?

@V69dxz
Copy link

V69dxz commented Jan 29, 2025

That is very cool!

Right now, I use a workaround by using the rest api integration in HA

rest_command:
  lookup_product:
    url: "http://XXX:9192/api/stock/products/by-barcode/{{ barcode }}"
    method: GET
    headers:
      GROCY-API-KEY: !secret grocy_api
    timeout: 10

The {barcode} is fetched by my esp barcode scanner.

@phil-schneider
Copy link
Author

@V69dxz cool a response :-)
You can see my fork here:
https://github.com/phil-schneider/ha-custom-grocy

Currently I have no GET-by-barcode, but I plan to.
At least the python lib returns the object back.
But currently I have no knowledge about "returning data/object from a service".

Thanks for your example of the rest command.
Can you please share your automation?
What do you do with the response?

My Plan:

  • esphome with barcode scanner (waiting for the scanner hardware from china)
  • scan a product
  • substract from stock and display the name and current stock value on the display

@V69dxz
Copy link

V69dxz commented Jan 30, 2025

Will look at your fork!, but can’t help directly as i’m a novice in Python.

Considering my automation: Well, barcode scanned -> fetch product name and id from grocy addon -> product -1 from stock through grocy integration -> tts: “you have taken [product name] from stock, have a great meal’ (sonos speaker)

Some lessons learned:

  • i have the same barcode scanner ( actually two) as you show in your link, works generally ok, but good back light is required (as in the barcode needs to be clearly visible; i have by coincidence a lamp perfectly aligned with one of the scanners). So, point of advice: test your setup in the full sun light and not in a dimmed light or even dark room (and if you find a way to make the scanner more sensitive to light in the settings, I am very interested to learn about this)
  • I originally had a switch to add barcodes/products, but find it more convenient to use the app, because on way or another after a year of use there still variations of barcodes coming in… thus new products. I know the grocy developer recommends a real barcode scanner.
  • sometimes the integration fails to load (after restart of HA), then the -1 fromstock does not work (but the product name is given). haven’t had time to add error message, so if you could add this, that would be great.

But it’s cool ánd we have generally a good overview of our stock :)

@V69dxz
Copy link

V69dxz commented Jan 30, 2025

Oh, almost forgot: i have a tts error message if the amount of the scanned product is zero (thus we forgot to add the product in the first place) or if the barcode is unknown

@phil-schneider
Copy link
Author

@V69dxz wow thanks for your response.

I also dont know python (but other languages) and with the help of ChatGPT I was able to add (copy&paste) two services:

My barcode scanner has not arrived yet, but the code is ready :-)
The esphome will scan the ean and call a script from HA with the ean as parameter.
The script will call the new "consume_product_from_stock_by_barcode"
Since the service returns information about the product, it will display it.

Here is the script:
scan_barcode_keller: alias: "Scan Barcode Keller" mode: restart fields: ean: description: "Barcode" example: "4105250022331" sequence: - action: grocy.consume_product_from_stock_by_barcode continue_on_error: true data: spoiled: false barcode: "4105250022331" amount: 1 response_variable: product_response - action: input_text.set_value target: entity_id: input_text.barcode_display_zeile1 data: value: "{{ product_response.name }}" - action: input_text.set_value target: entity_id: input_text.barcode_display_zeile2 data: value: "Bestand: {{ product_response.available_amount }}" - action: input_text.set_value target: entity_id: input_text.barcode_display_zeile3 data: value: " - Prost - " - delay: milliseconds: 200 - action: switch.turn_on target: entity_id: switch.barcode_keller_barcode_keller_buzzer - delay: milliseconds: 200 - action: switch.turn_off target: entity_id: switch.barcode_keller_barcode_keller_buzzer - delay: milliseconds: 100 - action: switch.turn_on target: entity_id: switch.barcode_keller_barcode_keller_buzzer - delay: milliseconds: 200 - action: switch.turn_off target: entity_id: switch.barcode_keller_barcode_keller_buzzer - delay: seconds: 30 - action: input_text.set_value target: entity_id: input_text.barcode_display_zeile1 data: value: "----------------------" - action: input_text.set_value target: entity_id: input_text.barcode_display_zeile2 data: value: "Barcode scannen" - action: input_text.set_value target: entity_id: input_text.barcode_display_zeile3 data: value: "----------------------"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants