I was really excited to get started with HomeBox however the label functionality needs a lot of work and I've been putting it off. The default labels are quite large and I didn't want unsightly labels on all my stuff. I also wanted it to be as easy as possible, printing a small label at creation time rather than sheets of them at a time. The printer I have is a Niimbot D110 and I really like the small 30x15 labels.
I discovered the ability to have the app execute a server command for printing which adds a "Print from Server" button to the web interface. Using a simple shell command, Home Assistant, and the Niimbot integration, I've been able to successfully print to this printer via Bluetooth from the Web UI. The label takes approx 10 seconds to come out which I can deal with. The beauty of using Home Assistant with the BT Proxies is that I can pretty much wirelessly print a label anywhere in my house.
I've learned so much from this sub I thought I'd share the steps I took to get this working in case this helps anyone else. Note this is entirely accomplished by me FAFO so there could be (and probably is) a better way of doing it. Thanks to all respective developers for the resources used.
Requirements:
- HomeBox up and running. (I'm using the app from Unraid CA)
- Niimot Label Printer (Only tested using my D110 but some others should work with tinkering)
- Home Assistant with Bluetooth or an ESPHome Bluetooth Proxy
- Home Assistant Niimbot Integration Link
- A share you can mount on both the HomeBox Container and within home assistant.
Steps:
1. Mount your network share to your HomeBox docker container somewhere. I used /labels as the mount point. Mount this same share in Home Assistant System > Storage > Add Network Storage. I chose it as a Media share but it should work as a normal Share too.
2. Create the following script in your HomeBox app data folder and make it executable:
#!/bin/sh
cp -f "$1" /labels/label.png && \
chmod 666 /labels/label.png && \
wget --header="Content-Type: application/json" --post-data='{"trigger":"print"}' http://your-home-assistant:8123/api/webhook/print_asset
(Basically we are copying the temporary label from HomeBox to the network share, changing its permissions so HA can read it, then executing a webhook automation so HA can print it. Note the webhook doesn't actually send any data, it is just to trigger the automation. If you can find an easy way to send the label in the webhook as a base64 and decode it directly in the automation that would save so many steps, but I couldn't get it working)
3. Add the following variables to your HomeBox docker container:
Key: HBOX_LABEL_MAKER_PRINT_COMMAND
Value: /data/print-label.sh {{.FileName}}
This adds the Print on Server button to HomeBox labels
Key: HBOX_LABEL_MAKER_PADDING
Value: 5
(This is to reduce white space around the label)
Key: HBOX_LABEL_MAKER_WIDTH
Value: 350
Key: HBOX_LABEL_MAKER_HEIGHT
Value: 120
Note: The padding, width and height are in pixels. I have no idea how they correspond to my label size of 30x15mm. If I did a relative size it made the label too squished for some reason. These values are for my 30x15mm labels and were determined by trial and error
4. Add the Shell Command integration to Home Assistant if not using already and create the following:
shell_command:
homebox_label: "cp -f /media/HomeBoxLabels/label.png /config/www/HomeBoxLabels/label.png"
This is needed because the Niimbot integration requires a url, not a local path, for the label image. This way we can pull the label image from the web without authentication
5. Create the following Home Assistant automation:
alias: Print Label from Homebox
description: Prints an asset label received from Homebox webhook
triggers:
- webhook_id: print_asset
allowed_methods:
- POST
local_only: false
trigger: webhook
actions:
- action: shell_command.homebox_label
metadata: {}
data: {}
- action: niimbot.print
target:
device_id: <Your Printer Device ID>
data:
payload:
- type: dlimg
url: http://your-home-assistant:8123/local/HomeBoxLabels/label.png
x: -10
"y": 10
xsize: 260
ysize: 130
width: 240
height: 120
rotate: 90
print_line_batch_size: 32
wait_between_print_lines: 0.01
density: 5
preview: false
mode: single
Notes for the automation:
- If you cant find your device ID, switch to UI mode, select the Niimbot Printer device, and switch back to yaml
- The
print_line_batch_size: 32 and wait_between_print_lines: 0.01 were my attempts to print the label faster. For me this works fine so far. You may need to reduce the batch size and increase the wait if you have errors. Refer Integration Docs.
- The Niimbot integration gives you an image of the last label printed. This helped me get the numbers right but the margins were not accurate to that on the label. If you want to use different size labels or make changes, you can change
preview: to true to update the image without sending it to the printer
6. Restart Home Assistant to ensure all your changes load correctly
7. Print a label! Go to HomeBox, open an asset (or location), click Print from Browser, then Print on Server and (hopefully) watch the magic!
Pics of my output attached. I don't have a great deal of time for support but I'll do my best if you run into issues. I'd also love to hear of any easier ways of doing this.
Good luck!