Barcode scanner input/auto select input_text field

I am trying to get started with Grocy, which is a home ERP(it has a hassio add-on and a custom component). And of course it has to be well integrated into HA.

I had planned to have an android table in the kitchen and connect a bluetooth barcode scanner to it and via the Grocy API and by selecting an option in HA add/remove/open food and drinks.

The scanner basically works as a keyboard. The problem I have is that I can not get the HA to auto-select a text_input field and the keyboard input would require the scanner to be connected directly to the server. My idea was to have lovelace button card, change to an “empty” view (or popup via browser-mod), but for the best experience the input_text field would auto select.

I imagine press “remove/eat”, scan and you are back. But at the moment it would be, press “remove”, select input_text field, scan.

Is it possible to auto select an input_text when you enter a view for example (or access the background keyboard presses) or does anyone have a good workaround?

You’d need a custom card for something like this. I deal with this in applications and you have to specifically call out capturing text or grabbing focus. Also, you’d have fights with other things that want focus on the page as well.

Tbh I’m not sure, what you’re trying to do. Why would you use HA and not Grocy for this task? Maybe I do not understand the way, you’re trying to do this.

What I understand from reading (I don’t have a scanner yet), you can simply send your Input to Grocy directly. I wouldn’t use a detour over HA. Send the commands (products) from your scanner (I asume you have the scanner hooked up with an RPi) to Grocy and let Grocy do the work.

Then you need HA only to show things from Grocy, but otherwise it isn’t involved.

Well, two parts:

  1. I want to do more HA stuff as well, such as trigger scenes and scripts.
  2. The control of the UI is better in HA, and I want to do very simple Grocy operations from this tablet.

I was hoping someone had a custom card for it or work around or be able to use the browser-mod in some smart way. It is a not uncommon thing to do in a web app…

I doubt a custom card like this already exists. And there probably won’t be a work around because you’d need to capture all keyboard events.

The bare minimum I need is home assistant to auto focus on a text input field, which I hoped would be possible.

Everything you want to do requires code changes. I’m not sure how else I can spell this out to you. I’ve said this in about 3 different ways so far. There is nothing plug and play that you can do. You’ll have to build something custom.

I guess learning how to create a custom card is the only way forward then.

Worst case I guess I have to do a python/kivy thing that talks to the HA API and Grocy API.

Grocy has a nice little API, where you can easily control all kinds of tasks. You can use HA to send commands, but “essential” stuff like scanning (in or out) should be handled in Grocy. E.g. you could control or add items to your shopping list via HA by sending a command to the Grocy API. For this you wouldn’t need “lovelace” or input fields. The scanning process on the other hand is handled between your scanner and Grocy.

And the tablet could very well be a scanner as well. The camera can be used very nice. For other taskes in Grocy, depending on what kind of task, you could use something like button card.

I don’t see where it is necessary to use a custom developed card in lovelace, for a task that can be easily done outside of HA. That doesn’t mean, you couldn’t do other things in HA, that interact / affect Grocy. :slight_smile:

Nonetheless, if this doesn’t fit your needs or wants, you could always develop something using the addOns from Grocy. E.g. pygrocy or barcodebuddy. These would allow to implement the needed software into a custom component for HA. :slight_smile: Take a look on the grocy page down to the end, there are some addOns listed.

Hi!

Yes I understand it might seem small, but my experience from setting up similar systems at work is that the small things make all the difference. I had intended to use the grocy api directly or through the addon. It has a “product by barcode” part that I wanted to use. The speed of using a camera and a real barcode scanner is not comparable. Since in the operation of opening a carton of milk Grocy add work, that extra work need to be minimal, else the risk of it not happening is huge.

Since I from this tablet wanted to do a very limited set of operations from Grocy and a very limited set of operations from HA, switching browser windows or even panels or do an iframe thing is just not seamless enough in my opinion. (I will check if I can do an iframe in a popup that goes direct to consume/purchase window and still auto focus correctly, however a problem for open and spoil…)

If you really want it all in HA, I’d investigate creating an ‘invisible’ card that captures all keyboard events for the current browser in use. It shouldn’t be too hard, but you may need to program your barcode scanner to send “ENTER” after every barcode capture.

The only caveat is that you wouldn’t want to put this in the same ‘view’ as a text control because it’s capturing all keyboard events.

I see where you want to go, that’s the same direction, I’m heading. What I still don’t get, is why you want to do all of this in HA with lovelace.

What I propose is taking functionalities out of the UI (so, out of lovelace) and let HA and Grocy do the work part. Why are you insisting on taking this to the frontend, where it is not needed?

Would you mind to descripe exactly, what you want to do, and where you want to do it.

I’m quite sure, HA is ready to solve this, but you may need to do things in another way. And this has nothing to do with the kind of scanner you want to use. If you want to use a specific bar code scanner (btw. could you recommend a good bar code scanner as you work with them?), you need to divide the scanning and modifying of the result and the actual task you want to do in HA or Grocy. E.g. take an RPi, setup the scanner with this Pi and then modify your input from the scanner to REST or MQTT commands / topics, that you send to Grocy directly (via the REST-API). The product will be listed in Grocy and if you have a sensor setup in HA, this sensor will reflect the newly scanned product. See where I’m getting? :wink:

Whatever you then want to do with the product, you can setup in HA, but totally away from any scanning or things like that.

I do find this discussion very interesting, as I’m new to Grocy, and want to find a good way, to integrate it in my personal routines. As you said, if it is to difficult or takes to long, no one will use it and inconsistencies will come up. I plan to setup one of my old android phones as a reserve scanner in my garage, so I can track things that stay there, e.g. potatoes or milk cartons.

1 Like