Semi automating filament usage tracking with Bambu Labs Printers and Spoolman

Background
I absolutely love Home Assistant and have been looking for a way to track my new hobby of 3D Printing useless things and occasionally something kind of useful :-). I am one of those people who doesn't really design much and mostly looks for prints that other much more talented people have created, therefore when I went hunting for a 3D printer I wanted something that just worked and didn't really require much if any tinkering, as such I landed on Bambu Labs. I know that there is a lot of animosity towards them and i completely understand that especially from the communities around Home Assistant and 3d printing as it really goes against the spirit of these communities, but alas here we are.
Most of my house runs on Home Assistant which I got into before I delved into 3D printing, therefore this guide will be specific to that.
Prerequisites
- Home Assistant
- Mushroom Cards HACS addon
- Spoolman Instance (I have mine on a docker host behind a reverse proxy, but you don't have to do all that as long as communication with Home Assistant works)
- Spoolman HACS Integration
- Bambu Labs Integration for Home Assistant
Limitations
- If its a failed print....... just guess how much was used i guess?
- When you add a new filament to Spoolman, you will need to manually add a new card to your dashboard.
"My Goal"
Since I use all different filaments from different brands I don't have a good way to have the Bambu Labs integration automatically tell me which filament was used and have it be actual useful information, luckily I'm not using this in a print farm and i'm just a hobbyist so remembering when a print finished which filament was used isn't too hard. So here is what i want to happen.
- When a print finished notify my phone that it has finished as well as how much filament was used in "g" (I supposed you could use mm as well if you want)
- Have that nofication take me to a custom dashboard when i click it
- Have a dashboard with all my filaments listed and a place to say how much filament was used and then have it communicate with spoolman and update it!
Steps
To get this working we are going to go a bit out of order, but i promise it will make sense.
1. Create an Input Helper
We need a place to type in the amount of filament we want to consume. We will use a global input_number helper for this.
Add the following to your configuration.yaml file. We set the mode tobox so we can type exact numbers instead of using a slider.
input_number:
filament_usage:
name: Filament usage (g)
min: 0
max: 1000
step: 1
unit_of_measurement: "g"
mode: box
Restart Home Assistant
2. Create the Logic Script
Because the Spoolman API "sets" the total weight rather than "adding" to it, we need a script to do the math for us.
The script does 4 things:
- Calculates the new total (Current Used Weight + Input Box Weight).
- Sends the new value to Spoolman.
- Pauses for 2 seconds so the database can save
- Forces an update in Home Assistant so the dashboard will immediately update and reflect the changes
Add this to your scripts.yaml file.
consume_filament:
alias: Consume Filament
description: "Add to filament usage using Spoolman Integration"
fields:
spool_entity_id:
description: "The Entity ID of the spool (e.g., sensor.spoolman_spool_4)"
example: "sensor.spoolman_spool_4"
sequence:
# 1. Send the command to Spoolman
- service: spoolman.patch_spool
data:
id: "{{ state_attr(spool_entity_id, 'id') }}"
used_weight: >
{% set current = state_attr(spool_entity_id, 'used_weight') | float(0) %}
{% set add = states('input_number.filament_usage') | float(0) %}
{{ current + add }}
# 2. Wait 2 seconds to ensure Spoolman backend has processed the save
- delay: "00:00:02"
# 3. FORCE an immediate update of the spool sensor
- service: homeassistant.update_entity
target:
entity_id: "{{ spool_entity_id }}"
# 4. Reset the input slider to 0
- service: input_number.set_value
target:
entity_id: input_number.filament_usage
data:
value: 0
Note: the configuration.yaml file MUST have the script: !include scripts.yaml line in it.
3. Dashboard Card
I tried for many......many hours to get auto-entities to work in order to auto generate these cards but I just couldn't get there, as such you will manually have to create these for each filament, however, its copy and paste only requiring you to edit 2 lines to update the spool number according to spoolman. Specifically you need to make sure the id matches the filament you are trying to control.
- Go to a dashboard of your choosing, I would recommend creating one from scratch using the default
sectionslayout.
Make note of the url of the dashboard as we will need it later mine isspool-updater - Add a new card and select
manual. - Paste the following code into the yaml configuration screen
Remember to edit the two lines
type: horizontal-stack
cards:
# --- LEFT COLUMN: SPOOL INFO ---
- type: custom:mushroom-template-card
# [EDIT 1] CHANGE THIS LINE to your specific spool sensor
entity: sensor.spoolman_spool_10
primary: "{{ state_attr(entity, 'friendly_name') }}"
secondary: "{{ states(entity) }}g left"
picture: "{{ state_attr(entity, 'entity_picture') }}"
layout: horizontal
fill_container: true
tap_action:
action: more-info
# --- RIGHT COLUMN: ACTIONS ---
- type: vertical-stack
cards:
# 1. Input Box (Global - No edits needed)
- type: entities
entities:
- entity: input_number.filament_usage
name: " "
icon: mdi:weight-gram
# 2. Confirm Button
- type: custom:mushroom-template-card
primary: Confirm
icon: mdi:check-bold
icon_color: green
layout: horizontal
tap_action:
action: call-service
service: script.consume_filament
service_data:
# [EDIT 2] CHANGE THIS LINE to your specific spool sensor
spool_entity_id: sensor.spoolman_spool_10
Repeat this for as many filaments as you need, i opted for two collumns since i use it on a computer and my phone. Here is what it will look like when you have finished all of them.

All you have to do now is to type in how much filament was used in the correct tile and select confirm. The script we created will update the spoolman container via the API and refresh the integration.
4. Creating the phone automation
When your printer finishes a print it will send your phone a notification with a link to your new dashboard it will also contain how much filament was used during the print.
First we will need to get some information about your printer, go to the devices section and select your Bambu Labs printer in the Bambu Labs integration.
- Select your printer Note: Make sure you don't select your AMS or External Spool
- At the top right select the pencil and make note of the name in my case its
h2d_0*48a**70200**9
Next we will create the automation we need
- Go to automations and create a new automation
- Click the top right hotdog and select
edit in yaml
Paste and edit the following information as needed:
alias: 3D Print Finished - Log Filament
description: "Notify with weight and tray info when print finishes"
trigger:
- platform: state
# update this to your printer name
entity_id: sensor.h2d_0*48a**70200**9_print_status
from: "running"
to: "finish"
action:
# update this to your mobile device name it can be found in the devices section
- service: notify.mobile_app_pixel_10_pro_xl
data:
title: "Print Complete"
# update this to your printer name (appears twice below)
message: >-
Success! Used {{ states('sensor.h2d_0*48a**70200**9_print_weight') }}g
from Tray {{ states('sensor.h2d_0*48a**70200**9_active_tray') }}.
Tap to log this usage.
data:
# update this to your dashboard url it can be found in the address bar when viewing your dashboard (appears twice below)
clickAction: "/dashboard-test/spool-updater"
url: "/dashboard-test/spool-updater"
tag: "print_finished"
When updating the sensors only change the printer name so for example sensor.h2d_0*48a**70200**9_print_status should be changed to sensor.yourprintername_print_status retaining the sensor and _print_status
This will send your mobile device a notification with how much filament was used and when you click on it, it should take you to the dashboard you created so you can do your updates!