Caution
This is a work in progress and made using GPT and basic knowledge.
The Pantry Tracker add-on is a Home Assistant designed to help you keep track of products in your kitchen, pantry, or any other storage space. With a user-friendly interface and a powerful backend, this add-on simplifies the organization and management of your items by allowing you to create categories, assign products to them, and maintain an up-to-date inventory.
The add-on operates using a Flask API server hosted locally. All product and category data is stored persistently in a .db file using JSON, ensuring your data is retained across reboots.
🖥️ Responsive User Interface
The add-on provides a sleek, easy-to-navigate interface that adapts to different screen sizes for seamless use on both desktop and mobile devices.
📦 Product Management
Add, update, or remove products from your inventory. Automatically track counts for individual products.
🗂️ Category Management
Create, edit, or delete custom categories. Assign products to specific categories for better organization.
🔄 Real-Time Updates
Sensors in Home Assistant are updated in real time to reflect changes made via the API or the interface.
💾 Backup & Restore
The ability to save a copy of the database and restore an existing database
1: Add https://github.com/mintcreg/pantry_tracker/ to repositories to the addon store
2: Install Addon from the addon store
Tip
Visit the Setup Guide for full installation instructions
Endpoint | Method | Description | Parameters | Response |
---|---|---|---|---|
/ |
GET |
Root endpoint that serves the HTML UI with the current API key. | Headers: X-API-KEY required |
200: Renders index.html . |
/index.html |
GET |
Route to render index.html with the current API key. |
Headers: X-API-KEY required |
200: Renders index.html . |
/categories |
GET |
Fetch all categories. | Headers: X-API-KEY required |
200: List of category names. Example: ["Fruits", "Vegetables"] 500: Error message if fetch fails. |
/categories |
POST |
Add a new category. | Headers: X-API-KEY required Body: {"name": "CategoryName"} |
200: Updated list of categories. 400: Validation errors or duplicate category. 500: Error message if addition fails. |
/categories |
DELETE |
Delete a category and reassign its products to "Uncategorized". | Headers: X-API-KEY required Body: {"name": "CategoryName"} |
200: Updated list of categories. 400: Validation errors. 404: Category not found. 500: Error message if deletion fails. |
/categories/<old_name> |
PUT |
Edit an existing category's name. | Headers: X-API-KEY required Path Parameter: <old_name> Body: {"new_name": "New Category Name"} |
200: Updated list of categories. 400: Validation errors or duplicate category. 404: Category not found. 500: Error message if editing fails. |
/products |
GET |
Fetch all products along with their categories and URLs. | Headers: X-API-KEY required |
200: List of products with their details. Example: [{"name": "Apple", "url": "image.jpg", "category": "Fruits"}] 500: Error message if fetch fails. |
/products |
POST |
Add a new product. | Headers: X-API-KEY required Body: {"name": "ProductName", "url": "ProductImageURL", "category": "CategoryName", "barcode": "Barcode"} |
200: Updated list of products. 400: Validation errors or duplicate product/barcode. 500: Error message if addition fails. |
/products |
DELETE |
Delete a product by name. | Headers: X-API-KEY required Body: {"name": "ProductName"} |
200: Updated list of products. 400: Validation errors. 404: Product not found. 500: Error message if deletion fails. |
/products/<old_name> |
PUT |
Edit an existing product's details. | Headers: X-API-KEY required Path Parameter: <old_name> Body: {"new_name": "New Product Name", "category": "New Category Name", "url": "New Image URL", "barcode": "New Barcode"} |
200: Updated list of products. 400: Validation errors. 404: Product not found. 500: Error message if editing fails. |
/update_count |
POST |
Update the count of a specific product by product name. | Headers: X-API-KEY required Body: {"product_name": "ProductName", "action": "increase/decrease", "amount": 1} |
200: Updated count. Example: {"status": "ok", "count": 5} 400: Validation errors. 404: Product not found. 500: Error message if update fails. |
/counts |
GET |
Fetch the current count of all products. | Headers: X-API-KEY required |
200: Dictionary of product counts keyed by entity_id . Example: {"sensor.product_apple": 5} 500: Error message if fetch fails. |
/health |
GET |
Health check endpoint to verify the service is running. | Headers: None | 200: Health status. Example: {"status": "healthy"} |
/backup |
GET |
Render the backup.html template for database backup and restore functionalities. |
Headers: X-API-KEY required |
200: Renders backup.html . |
/download_db |
GET |
Download the current database file as an attachment (pantry_data.db ). |
Headers: X-API-KEY required |
200: Sends the database file as an attachment. 404: Database file not found. |
/upload_db |
POST |
Upload a database file to replace the existing database. | Headers: X-API-KEY required Body: File upload with key file (multipart/form-data). |
200: Redirects to base path after successful upload. 400: No file part or no file selected. 500: Failed to migrate, replace, or reinitialize the database. |
/fetch_product |
GET |
Fetch product data from OpenFoodFacts using the barcode. | Headers: X-API-KEY required Query Parameter: barcode |
200: {"status": "ok", "product": {...}} with product data. 400: Barcode is required. 404: Product not found or failed to fetch data. |
/delete_database |
DELETE |
Delete the database and reinitialize it, creating a backup beforehand. | Headers: X-API-KEY required |
200: {"status": "ok", "message": "Database deleted and reinitialized."} or {"status": "ok", "message": "Database already deleted."} 429: {"status": "error", "message": "Delete operation is already in progress."} 500: {"status": "error", "message": "Failed to delete and reinitialize the database."} |
/theme |
GET |
Return the current theme from config.ini . |
Headers: X-API-KEY required |
200: {"theme": "light"} or {"theme": "dark"} . 500: Error message if retrieval fails. |
/theme |
POST |
Save the selected theme (light/dark) to config.ini . |
Headers: X-API-KEY required Body: {"theme": "light/dark"} |
200: {"status": "ok", "theme": "light/dark"} . 400: Invalid theme. 500: Error message if setting theme fails. |
/get_api_key |
GET |
Securely provide the API key to the frontend. | Headers: None (This endpoint is exempt from API key authentication.) | 200: {"api_key": "the_api_key"} . 500: Error message if retrieval fails. |
/regenerate_api_key |
POST |
Regenerate the API key. |
Required: X-API-KEY: your_current_api_key |
200: {"status": "ok", "api_key": "new_api_key"} 401/403: Unauthorized or Forbidden if X-API-KEY is missing or invalid. 500: Error message if regeneration fails. |
This project uses data and images provided by OpenFoodFacts.
- Data and images are licensed under the Open Database License (ODbL) and the Database Contents License (DbCL).
- You are encouraged to contribute to OpenFoodFacts by adding missing products and improving data accuracy.
Visit OpenFoodFacts to learn more.