Raisand Vallipuram
Stock Assistant: Managing your product inventory in Home Assistant
Article contents
Introduction
My wife runs her own tattoo and piercing shop (Inked Fox, if you’re curious). In no time, she’s fallen head over heels for the trade and is absolutely rocking it! But, as any self-employed artist knows, the glamorous side comes with its fair share of grunt work.
One particular challenge? Keeping track of her shop’s stock. Tattoo cartridges, piercing needles, saline sprays – you name it, she’d often find herself mid-booking with a mini-crisis because she forgot to reorder. Cue the frustration (and a newfound talent for improvisation).
So, as a tech geek with a soft spot for solving problems, what could be more fun than whipping up a Home Assistant solution to help her out?
The plan
The first question I had to ask myself was if Home Assistant could genuinely simplify this process. A completely automated solution did not seem feasible when you need to keep track of your stock, some manual registration will always be needed.
After some brainstorming, I was confident that I could at least make the process a bit easier than it was right now. Tracking a list of products and their quantities in Home Assistant seemed straightforward. The real challenge was figuring out how to let her easily update the list without constantly having to open the Home Assistant mobile app and updating the products manually.
The solution? NFC! She always keeps her products neatly stored in their original boxes. What if I could put physical NFC cards in these boxes so that when she takes a product out, she simply sets the card out of that box aside? Then, after her booking, she could scan all the cards she set aside before putting them back in the boxes, and voilà – her stock register would be perfectly updated with only a fraction of the manual hassle.
With the plan in place, it was time to get started!
Requirements
For this project, I used the following tools and products.
Required:
- Empty, writable NFC tags (1 per item that you want to track)
- Smartphone with Home Assistant app installed
- The plugin template-entity-row by thomasloven
Optional:
- DYMO Label Writer
Getting to it!
Adding Number helpers
The first thing we have to do is getting a complete list of the inventory that she needs to keep track of. For each item, I created a Number helper. You can do this under
Settings > Devices & services > Helpers
For each helper, make sure to include:
- A name
- An icon
- A maximum value (don’t include a minimum, we’re taking care of that another way!)
- Display Mode > Input field
- Step size: 1
- Unit of measurement: stuks (units)
Creating the dashboard
The next step is to create a separate page on your dashboard, to display the actual stock lists. My goal is to have two lists, ‘Low Stock’ and ‘Sufficient Stock’, in which the entities are dynamically displayed and hidden based on their stock.
The card type we will be using for this, is template-entity-row by thomasloven. This card type allows us to make changes to the ‘Secondary’ attribute, which I want to use to display the minimum stock a product should have. This plugin can be installed via HACS.
After installing the plugin, go ahead and create two new ‘Manual’ cards. You can use the two templates below. Make sure to adjust the following field for each entity:
- entity: replace the input_number with the Number Helper that you created in the previous step
- secondary: set the minimum amount of units
- state: replace the input_number with the correct Number Helper
- condition: replace the input_number with the correct Number Helper and change the int value to the minimum amount of units
type: entities
title: Low Stock
entities:
- type: custom:template-entity-row
entity: input_number.product1
secondary: 'Minimum: 5 units'
state: |
{{ states('input_number.product1') | int }} units
condition: |
{% if states('input_number.product1') | int > 5 %}
false
{% else %}
true
{% endif %}
- type: custom:template-entity-row
entity: input_number.product2
secondary: 'Minimum: 10 units'
state: |
{{ states('input_number.product2') | int }} stuks
condition: |
{% if states('input_number.product2') | int > 10 %}
false
{% else %}
true
{% endif %}
type: entities
title: Sufficient Stock
entities:
- type: custom:template-entity-row
entity: input_number.product1
secondary: 'Minimum: 5 units'
state: |
{{ states('input_number.product1') | int }} units
condition: |
{% if states('input_number.product1') | int > 5 %}
true
{% else %}
false
{% endif %}
- type: custom:template-entity-row
entity: input_number.product2
secondary: 'Minimum: 10 units'
state: |
{{ states('input_number.product2') | int }} stuks
condition: |
{% if states('input_number.product2') | int > 10 %}
true
{% else %}
false
{% endif %}
As you can see, the ‘Low Stock’ and ‘Sufficient Stock’ cards are pretty similar, except that they have the ‘true’ and ‘false’ condition switched around.
Altogether, these two blocks should look like this once all the products are added. You can test their functionality by clicking on a product and reducing the amount until the set threshold, after which it should switch columns.
Registering the NFC tags
Now we need to register our NFC tags. I bought a pack of 50 blanc NFC cards from Amazon.nl. These are sturdy, plastic cards that won’t mind a little tattoo ink on them and can easily be stored in the product boxes. However, any writable NFC tag should be capable of doing the job – so pick any kind that fits your use case best!
In order to be able to tell the cards apart, I used a DYMO label writer to print plastic labels with the product names on them.
In order to register the NFC tags, we are going to need a smartphone with the Home Assistant application installed. Go to
Menu > Settings > Companion App > NFC Tags > Write NFC Tag
Leave the identifier as is, and hold the NFC tag against the NFC reader in the Smartphone. The empty card should now have an identifier written to it. You can double check this by going back to the NFC Tags page and picking ‘Read NFC Tag’.
If the write was successful, make sure to note down the identifier that was assigned to the tag. If nothing happens when writing or reading the tag, make sure NFC is enabled on the smartphone and nothing is blocking the sensor. Using a thick case or popsocket should be no issue, but make sure there are no other NFC cards or metal parts between the device and the NFC tag.
Creating the automation
After writing an identifier to the NFC tag, we can start on creating the automation. This automation will do two things:
- Reduce the inventory: It will decrease the current stock level of the scanned product by one unit
- Send a notification: It will send a notification to the user’s device, confirming that the scan was successful and providing the updated stock level for the scanned product
Important to note is that each item will need their own automation, so make sure to use the ‘Categories’ functionality in Home Assistant to keep things tidy!
You can find the YAML template for the automation below. Make sure to replace the following fields with your own data:
- Alias: Think of a creative name 🙂
- tag_id: insert the NFC tag id that you wrote to the NFC tag earlier
- entity_id: replace with the entity_id of the entity you want to track. Only replace under action > variables. The other fields are dynamic!
alias: NFC - Inked Fox Inventory - Product1
description: ""
trigger:
- platform: tag
tag_id: Product1_tag_id
condition: []
action:
- variables:
entity_id: input_number.product1
- service: input_number.decrement
target:
entity_id: "{{ entity_id }}"
data: {}
- service: notify.All_devices
data:
message: >
{% set quantity = states(entity_id) | float %} Kaart gescand! Voorraad
van {{ state_attr(entity_id, 'friendly_name') }} is {{ quantity | int
if quantity.is_integer() else quantity }} stuks.
mode: single
Results
After following all the steps above, scanning the NFC cards should result in the corresponding product’s stock being reduced by 1 unit, and a notification being sent to your phone confirming this.
Conclusion
My wife has been working with her new system for a week now, and she is stoked about it! Every time she uses a product, she tosses the card aside. After she’s done, she scans all those cards, and voila – inventory is magically updated.
Of course there are ways to improve this system. Introducing a new product still involves a fair bit of manual labor, because you need to:
- Map an NFC tag
- Create a Number helper
- Create an automation
- Add the item to both Stock list cards on the dashboard
But the most important thing is that the prototype is working fine and has irrefutably made my wife’s life a little bit easier – and I got to prove once again that there’s always room for a little more tech in your life!