Guide · Intermediate · Raspberry Pi
Klipper Macros You Actually Use Every Print
Start/end gcode, filament change, and fail-safe shutdown macros.
Project template
- Goal & materials
- Steps / firmware
- Troubleshooting
- AI assist notes
- Related gear & books
Klipper macros can do almost anything, which is why many configs end up with dozens nobody remembers. A small set covers most daily printing: a start macro, an end macro, a filament change, and sensible safety settings. This guide shows each one with an explanation, so you can adapt them to your printer instead of pasting blindly.
Before you start
- Back up
printer.cfgand any included files before editing. - Macros go in
printer.cfgor a file you include, such as. - After saving, run
FIRMWARE_RESTART(orRESTART) and check the console for errors. - Mainsail and Fluidd ship client macro files with
PAUSE,RESUME, andCANCEL_PRINT. If you use those, do not redefine the same macro names.
1. PRINT_START: let the slicer pass temperatures
Instead of long start G-code in every slicer profile, call one macro and pass the temperatures in:
gcode:
{% set BED_TEMP = params.BED_TEMP|default(60)|float %}
{% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(200)|float %}
M140 S{BED_TEMP} ; start heating bed
M104 S150 ; warm nozzle without oozing
G28 ; home all axes
M190 S{BED_TEMP} ; wait for bed
BED_MESH_PROFILE LOAD=default ; or BED_MESH_CALIBRATE
M109 S{EXTRUDER_TEMP} ; wait for nozzle
G92 E0
G1 Z2 F3000
Then set the slicer's start G-code to a single line. In PrusaSlicer, SuperSlicer, and OrcaSlicer:
PRINT_START BED_TEMP= EXTRUDER_TEMP=
In Cura, the variables are written as {material_bed_temperature_layer_0} and {material_print_temperature_layer_0}. Check your slicer's documentation for the exact variable names it supports.
Notes:
- Home before loading a mesh so the mesh lines up with the bed.
- Whether you probe a fresh mesh each print or load a saved one depends on your bed and probe. Newer Klipper versions support adaptive meshing that only probes the print area; check your version's documentation.
- If your printer has a purge line or a probe that needs a cold nozzle, adjust the order.
2. PRINT_END: park safely and shut down heat
gcode:
{% set max_z = printer.toolhead.axis_maximum.z|float %}
{% set cur_z = printer.toolhead.position.z|float %}
{% set safe_z = |min %}
G91
G1 E-2 F2700 ; small retract
G90
G1 Z{safe_z} F3000 ; lift without exceeding max Z
TURN_OFF_HEATERS
M107 ; part fan off
M84 ; motors off
The lift is capped at the machine's maximum Z so a tall print does not crash into the top of the frame. Add an XY park move if you want the bed presented forward, using coordinates that are valid for your printer.
3. Filament change (M600)
Many slicers insert M600 for color changes. Klipper does not implement it natively, so map it to a pause:
gcode:
PAUSE
The PAUSE macro from Mainsail or Fluidd parks the head and keeps the nozzle hot. Swap filament, purge by hand, then RESUME. If you do not use those client macros, write your own PAUSE that saves state with SAVE_GCODE_STATE, lifts, and parks, plus a RESUME that restores it.
4. Safety settings that work while you are away
Klipper already includes heater verification for each heater ( defaults) and enforces max_temp. Leave those protections on and avoid loosening them to silence an error; the error usually points at a real wiring or thermistor problem.
Add an idle timeout so heaters do not stay on if a print is abandoned:
timeout: 600
gcode:
TURN_OFF_HEATERS
M84
If you power the printer through a Moonraker device, you can also switch it off after cool-down from a delayed macro. Make sure the hotend fan keeps running until the hotend has cooled before cutting power.
Common mistakes
- Start G-code in the slicer and in PRINT_START, so the printer heats and homes twice or waits on the wrong temperature.
- Wrong slicer variable names, which send literal text instead of numbers. Check the first lines of the exported G-code.
- Redefining PAUSE or RESUME on top of the client macros and getting a duplicate macro error.
- Unbounded Z lifts in end macros that hit the frame on tall prints.
- Jinja typos. Klipper reports template errors on restart or when the macro runs; read the console message.
Summary
Four pieces cover most printing: a PRINT_START that takes temperatures from the slicer, a PRINT_END that lifts safely and turns heat off, an M600 that maps to PAUSE, and an idle timeout on top of Klipper's built-in heater checks. Keep them in one included file, comment what each line does, and test after every change.
Related
- Projects hub
- Newsletter
- Books for deeper reading