A Home Assistant custom integration for barcode scanning that automatically detects item types and routes them to the appropriate backend (Grocy, Homebox, or future library apps).
- Automatic Item Type Detection: Uses UPC lookup data to automatically determine which backend to use
- Batch Scanning: Scan multiple items and process them all at once
- Grocy Integration: Full support for Grocy API (check existence, add quantity, create products)
- Extensible Architecture: Easy to add new backends (Homebox, library apps, etc.)
- Simple UI: Custom Lovelace card for easy scanning interface
- USB Scanner Support: Works with USB barcode scanners that act as keyboards
- Make sure HACS is installed in your Home Assistant instance
- Go to HACS → Integrations
- Click the three dots in the top right corner → Custom repositories
- Add this repository:
- Repository:
https://github.com/needo37/barcode_router - Category: Integration
- Repository:
- Click Add
- Search for "Barcode Router" in HACS
- Click Download
- Restart Home Assistant
- Go to Settings → Devices & Services → Add Integration
- Search for "Barcode Router" and follow the setup wizard:
- Enter your Grocy URL (e.g.,
http://grocy.local:9283) - Enter your Grocy API key
- Test connection
- Enter your Grocy URL (e.g.,
- Download the latest release from the Releases page
- Extract the
custom_componentsfolder to your Home Assistant config directory - Restart Home Assistant
- Go to Settings → Devices & Services → Add Integration
- Search for "Barcode Router" and follow the setup wizard
The integration is configured through the Home Assistant UI during setup. The configuration requires:
- Grocy URL (e.g.,
http://grocy.local:9283) - Grocy API key
The integration provides three services:
Scans a barcode and adds it to the batch.
Service Data:
barcode(required): The barcode to scanbackend(optional): Manual backend override (grocy, homebox, library)quantity(optional): Quantity to add (default: 1)
Example:
service: barcode_router.scan_barcode
data:
barcode: "0123456789012"
quantity: 2Processes all items in the current batch.
Service Data:
item_overrides(optional): Override specific item data before processing
Example:
service: barcode_router.process_batch
data:
item_overrides:
"0123456789012":
quantity: 3
pending_confirmation:
name: "Custom Product Name"Clears all items from the current batch.
Example:
service: barcode_router.clear_batch-
Copy the card file to your Home Assistant
wwwfolder:cp custom_components/barcode_router/www/barcode-scanner.js <config>/www/barcode-scanner.js
-
Load the card resource (one-time setup):
- Go to Settings → Dashboards → Resources (or Developer Tools → YAML → Lovelace Dashboards → Resources)
- Click Add Resource (or edit
ui-lovelace.yamlif using YAML mode) - Set URL to:
/local/barcode-scanner.js - Set Type to: JavaScript Module
- Click Create (or save if using YAML)
-
Add the card to your dashboard:
type: custom:barcode-scanner-card
The card provides:
- Barcode input field (works with USB scanners)
- Real-time scan feedback
- Batch review panel
- Process and clear batch buttons
- Auto-refresh every 5 seconds when items are in batch
-
Scan Barcode: When you scan a barcode, the integration:
- Looks up product information from upcitemdb.com
- Automatically detects the item type (grocery, tool, book, etc.)
- Checks if the item exists in the appropriate backend
- Adds it to the batch
-
Batch Review: Review all scanned items, adjust quantities, and confirm new items
-
Process Batch: All items are sent to their respective backends:
- Existing items: Quantity is added via purchase API
- New items: Product is created with all details
The integration automatically detects item types based on:
- UPC category data from upcitemdb.com
- Product title and description keywords
- Defaults to Grocy for groceries/consumables
- Grocy: Food, Beverages, Snacks, Dairy, Cleaning Supplies, Personal Care, etc.
- Homebox: Tools, Hardware, Electronics, Office Supplies, etc.
- Library: Books, Media, Movies, Music, Video Games, etc.
To add a new backend (e.g., Homebox):
- Create a new file
backends/homebox.py - Implement the
BackendBaseinterface:from .base import BackendBase class HomeboxBackend(BackendBase): async def check_item_exists(self, barcode: str) -> bool: # Implementation pass # ... implement other required methods
- Register the backend in the coordinator
- Update item type detection if needed
- Make sure HACS installation completed successfully
- Check Home Assistant logs for any errors
- Ensure you've restarted Home Assistant after installation
- The integration will still add the item to the batch with minimal data
- You can manually enter product information when processing the batch
- Check your Grocy URL and API key
- Verify Grocy is accessible from Home Assistant
- Check Home Assistant logs for detailed error messages
- USB scanners that act as keyboards should work automatically
- Make sure the input field is focused when scanning
- Some scanners may require configuration to add a newline after scan
- Home Assistant 2024.4 or later
- Python 3.13
- aiohttp library (installed automatically)
This integration is provided as-is for personal use.