Home Assistant Filament Tracking: Spool Weight & Print Hours
With our API integration, you can fully automate tracking your filament usage and printer operating hours. When you start a print, Home Assistant notifies 3D Print Manager and the planned grams come off the mounted spool; when it finishes, the job closes and the hours are logged, and a stopped or failed print gives the unprinted part back.
Note: This guide uses the popular Home Assistant Bambu Lab integration syntax, but the logic can be adapted for Prusa, Creality, etc. Bambu Lab printer not in Home Assistant yet? Start with the Bambu Lab Home Assistant setup guide. 3D Print Manager does not control your printer. It never starts, stops or sends print jobs — it only records the filament usage and operating hours that Home Assistant reports. Your slicer and printer apps stay in charge of printing. Easier without Home Assistant: on a PRO or FARM plan, 3DPM Agent for Windows (Microsoft Store) books Bambu Lab, Prusa (PrusaLink) and Klipper (Moonraker) prints without Home Assistant. Setup: chapter 7b of the user manual. This guide is for printers you already run through Home Assistant and for other brands.1. Generate your API Key PRO
Before connecting Home Assistant, you need a secret key for communication.
- Log into 3D Print Manager.
- Open Settings (gear icon in the menu).
- Find the API Access section and click Generate New API Key.
- Copy the generated key (you will need it in Step 3).
2. Copy your Printer ID
The app needs to know exactly which printer the data is coming from.
- In 3D Print Manager, open the Manage Printers tool.
- Next to your printer's name, click the fingerprint icon ().
- You have now copied the unique Printer ID to your clipboard. Save it for later.
3. Add commands to configuration.yaml
Open your Home Assistant configuration.yaml file and add the following rest_command block.
Important: Replace <YOUR_API_KEY> with the key you generated in Step 1!
rest_command:
# Command to start the print
3dpm_start_print:
url: "https://3dprintmanager.eu/api.php?key=<YOUR_API_KEY>&action=start_print"
method: POST
headers:
content_type: 'application/json'
payload: >-
{
"printer_id": "{{ printer_id }}",
"job_name": "{{ job_name | replace('\"', '\\\"') }}",
"duration_minutes": {{ duration | int(0) }},
"mapping": {{ mapping | default('[]') }}
}
# Command to finish the print
3dpm_finish_print:
url: "https://3dprintmanager.eu/api.php?key=<YOUR_API_KEY>&action=finish_print"
method: POST
headers:
content_type: 'application/json'
payload: >-
{
"printer_id": "{{ printer_id }}",
"slot": {{ slot | int(-1) }},
"amount_used": {{ amount | float(0) }},
"hours": {{ hours | float(0) }}
}
3dpm_fail_print:
url: "https://3dprintmanager.eu/api.php?key=<YOUR_API_KEY>&action=fail_print"
method: POST
headers:
content_type: 'application/json'
payload: >-
{
"printer_id": "{{ printer_id }}",
"progress": {{ progress | float(-1) }}
}
Save the file and restart Home Assistant (or Reload REST entities).
4. Add Automations
Now you need to tell Home Assistant when to call these commands. Create two new automations in YAML mode.
Adjust 2 things:
1. Replace your_printer_name with the actual entity ID of your printer.
2. Replace <YOUR_PRINTER_ID> with the ID from Step 2.
Automation 1: Start Print
alias: "3DPM: Start Print"
description: Sends the exact time and filament mapping to 3D Print Manager
triggers:
- entity_id: sensor.your_printer_name_print_status
to: running
trigger: state
actions:
- wait_template: >-
{{ state_attr('sensor.your_printer_name_active_tray', 'tray_index') | int(-1) >= 0 }}
timeout: "00:05:00"
continue_on_timeout: true
- delay: "00:00:05"
- data:
printer_id: "<YOUR_PRINTER_ID>"
job_name: "{{ states('sensor.your_printer_name_gcode_file') }}"
duration: >-
{{ (states('sensor.your_printer_name_remaining_time') | float(0) * 60) | round(0) }}
mapping: >-
{% set tray = state_attr('sensor.your_printer_name_active_tray', 'tray_index') | int(-1) %}
{% set slot = 0 if tray in [254, -1] else tray + 1 %}
{% set weight = states('sensor.your_printer_name_print_weight') | replace('g', '') | trim | float(0) | round(2) %}
[{"slot": {{ slot }}, "weight": {{ weight }}}]
action: rest_command.3dpm_start_print
mode: single
Automation 2: Finish Print
alias: "3DPM: Finish Print"
description: Deducts grams from the spool and logs operating hours
triggers:
- entity_id: sensor.your_printer_name_print_status
to: finish
trigger: state
actions:
- data:
printer_id: "<YOUR_PRINTER_ID>"
slot: >-
{% set tray = state_attr('sensor.your_printer_name_active_tray', 'tray_index') | int(-1) %}
{{ 0 if tray in [254, -1] else tray + 1 }}
amount: >-
{{ states('sensor.your_printer_name_print_weight') | replace('g', '') | trim | float(0) | round(2) }}
hours: 0
action: rest_command.3dpm_finish_print
mode: single
Automation 2b: Failed or Cancelled Print
A print you stop on the printer, or one that fails, arrives as failed. 3D Print Manager gives back the filament that was not printed, using the progress the printer reported.
alias: "3DPM: Failed or Cancelled Print"
description: Returns unused filament to the spool when a print is cancelled or fails
triggers:
- entity_id: sensor.your_printer_name_print_status
to: failed
trigger: state
actions:
- data:
printer_id: "<YOUR_PRINTER_ID>"
progress: "{{ states('sensor.your_printer_name_print_progress') | float(-1) }}"
action: rest_command.3dpm_fail_print
mode: single
How to handle Multi-Color prints?
Bambu Lab printers: use 3DPM Agent (PRO or FARM).
The Agent books multi-colour prints per AMS slot: each spool is charged the grams the slicer planned for it. A printer fed by the Agent is ignored by the Home Assistant integration, so nothing is deducted twice.
With Home Assistant only:
Home Assistant cannot read the gram breakdown for each color from the G-code via MQTT, so it deducts the weight only from the spool that was active when the print started. For multi-color prints, turn off the HA automation and use Drag & Drop G-code inside 3D Print Manager to subtract each color.