Skip to content

Instantly share code, notes, and snippets.

@NameOfTheDragon
Last active June 24, 2024 17:26
Show Gist options
  • Save NameOfTheDragon/e579295549aaa19b3f41ae07b8f3cbd6 to your computer and use it in GitHub Desktop.
Save NameOfTheDragon/e579295549aaa19b3f41ae07b8f3cbd6 to your computer and use it in GitHub Desktop.
Klipper macros for drying filament using the heated build plate of a 3D printer
; An idea for using the heated bed of a 3D printer as a filament dryer.
; Adds GCODE command: START_DRYER TIME=T TEMPERATURE=C
; (T is time in seconds, C is bed temperature in Celsuis)
; To stop drying early, use STOP_DRYER.
; Also defined some utility macros: DRY_PLA, DRY_PETG and DRY_ABS.
; Edit these with your own preferred defaults.
[gcode_macro START_DRYER]
description: Start the heated bed filament dryer.
gcode:
{% set ChamberTemperature = params.CHAMBER | default(25.0) | float %}
{% set BedTemperature = params.TEMPERATURE | default(50.0) | float %}
{% set DryTime = params.TIME | default(14400) | int %}
; turn the heaters on, however you do that.
M140 S{BedTemperature} ; Sets the print bed temperature without waiting.
M141 S{ChamberTemperature} ; [OPTIONAL] Sets the enclosure temperature.
; then finally,
SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=time_remaining VALUE={DryTime}
SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=bed_temperature VALUE={BedTemperature}
SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=chamber_temperature VALUE={ChamberTemperature}
UPDATE_DELAYED_GCODE ID=DRYER_TIMER DURATION=1
[gcode_macro STOP_DRYER]
gcode:
; Turn off heaters etc. here
M140 S0 ; Disable bed heater
M141 S0 ; [OPTIONAL] Disable enclosure heater/fan
SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=time_remaining VALUE=0
UPDATE_DELAYED_GCODE ID=DRYER_TIMER DURATION=0 ; Stop the timer.
M117 Drying Stopped
[gcode_macro DRYER_STATUS]
variable_time_remaining: 0
variable_bed_temperature: 0
variable_chamber_temperature: 0
gcode:
{% if time_remaining > 0 %}
M140 S{bed_temperature} ; Reset bed temperature (prevents timeout)
SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=time_remaining VALUE={time_remaining - 1}
M117 Drying {time_remaining}
{% else %}
STOP_DRYER
{% endif %}
[delayed_gcode DRYER_TIMER]
gcode:
UPDATE_DELAYED_GCODE ID=DRYER_TIMER DURATION=1
DRYER_STATUS
[gcode_macro DRY_PLA]
gcode:
START_DRYER TEMPERATURE=50 CHAMBER=25 TIME=14400
[gcode_macro DRY_PETG]
gcode:
START_DRYER TEMPERATURE=55 CHAMBER=30 TIME=18000
[gcode_macro DRY_ABS]
gcode:
START_DRYER TEMPERATURE=65 CHAMBER=40 TIME=14400
@brbe1562
Copy link

I am getting an error and this is what it is reading

Option 'default_parameter_time' is not valid in section 'gcode_macro start_dryer'

Once the underlying issue is corrected, use the "RESTART"
command to reload the config and restart the host software.
Printer is halted

Please advice how to continue thanks :)

@cron410
Copy link

cron410 commented Mar 18, 2022

@brbe1562 I copied it all as listed above and had no issues with the actual function of the macros. I did have to comment out the lines with M141 to prevent console messages that M141 doesn't work on my setup.

@Fuckingnameless
Copy link

I am getting an error and this is what it is reading

Option 'default_parameter_time' is not valid in section 'gcode_macro start_dryer'

Once the underlying issue is corrected, use the "RESTART" command to reload the config and restart the host software. Printer is halted

Please advice how to continue thanks :)

same issue here

@Fuckingnameless
Copy link

this fixed the syntax error, i added 2 beeps and a telegram notification at 1/2 the time to remember you to turn the spool on the other side:

; An idea for using the heated bed of a 3D printer as a filament dryer.
; Adds GCODE command START_DRYER TIME T TEMPERATURE C CHAMBER C
; (T is time in seconds, C is temperature in Celsuis)
; To stop drying early, use STOP_DRYER.
; Also defined some utility macros DRY_PLA, DRY_PETG and DRY_ABS.
; Edit these with your own preferred defaults.

[gcode_macro START_DRYER]
gcode:
{% set time = params.TIME|default(14400)|float %}
{% set temperature = params.TEMPERATURE|default(50)|float %}
{% set chamber = params.CHAMBER|default(25)|float %}
{% set turntime = params.TURNTIME|default(time * 0.5)|float %} # reminding you to turn the spool :)
; turn the heaters on, however you do that.
M140 S{temperature} ; Sets the print bed temperature without waiting.
;M141 S{CHAMBER} ; [OPTIONAL] Sets the enclosure temperature.
; then finally,
SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=time_remaining VALUE={time}
SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=bed_temperature VALUE={temperature}
SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=chamber_temperature VALUE={chamber}
UPDATE_DELAYED_GCODE ID=DRYER_TIMER DURATION=1
UPDATE_DELAYED_GCODE ID=TURN_TIMER DURATION={turntime}
SET_IDLE_TIMEOUT

[gcode_macro STOP_DRYER]
gcode:
; Turn off heaters etc. here
M140 S0 ; Disable bed heater
;M141 S0 ; [OPTIONAL] Disable enclosure heater/fan
SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=time_remaining VALUE=0
UPDATE_DELAYED_GCODE ID=DRYER_TIMER DURATION=0 ; Stop the timer.
M117 Drying Stopped

[gcode_macro DRYER_STATUS]
variable_time_remaining: 0
variable_bed_temperature: 0
variable_chamber_temperature: 0
gcode:
{% if time_remaining > 0 %}
M140 S{bed_temperature} ; Reset bed temperature (prevents timeout)
;M141 S{chamber_temperature} ; [OPTIONAL] reset chamber temperature
SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=time_remaining VALUE={time_remaining - 1}
M117 Drying {time_remaining}
{% else %}
STOP_DRYER
{% endif %}

[delayed_gcode DRYER_TIMER]
gcode:
UPDATE_DELAYED_GCODE ID=DRYER_TIMER DURATION=1
DRYER_STATUS
[delayed_gcode TURN_TIMER]
gcode:
M300
M300
RESPOND PREFIX=tgalarm MSG="turn the spool :)"
[gcode_macro DRY_PLA]
gcode:
START_DRYER TEMPERATURE=50 CHAMBER=25 TIME=14400

[gcode_macro DRY_PETG]
gcode:
START_DRYER TEMPERATURE=55 CHAMBER=30 TIME=18000

[gcode_macro DRY_ABS]
gcode:
START_DRYER TEMPERATURE=65 CHAMBER=40 TIME=14400

@RealSpyKitty
Copy link

this fixed the syntax error, i added 2 beeps and a telegram notification at 1/2 the time to remember you to turn the spool on the other side:

; An idea for using the heated bed of a 3D printer as a filament dryer. ; Adds GCODE command START_DRYER TIME T TEMPERATURE C CHAMBER C ; (T is time in seconds, C is temperature in Celsuis) ; To stop drying early, use STOP_DRYER. ; Also defined some utility macros DRY_PLA, DRY_PETG and DRY_ABS. ; Edit these with your own preferred defaults.

[gcode_macro START_DRYER] gcode: {% set time = params.TIME|default(14400)|float %} {% set temperature = params.TEMPERATURE|default(50)|float %} {% set chamber = params.CHAMBER|default(25)|float %} {% set turntime = params.TURNTIME|default(time * 0.5)|float %} # reminding you to turn the spool :) ; turn the heaters on, however you do that. M140 S{temperature} ; Sets the print bed temperature without waiting. ;M141 S{CHAMBER} ; [OPTIONAL] Sets the enclosure temperature. ; then finally, SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=time_remaining VALUE={time} SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=bed_temperature VALUE={temperature} SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=chamber_temperature VALUE={chamber} UPDATE_DELAYED_GCODE ID=DRYER_TIMER DURATION=1 UPDATE_DELAYED_GCODE ID=TURN_TIMER DURATION={turntime} SET_IDLE_TIMEOUT

[gcode_macro STOP_DRYER] gcode: ; Turn off heaters etc. here M140 S0 ; Disable bed heater ;M141 S0 ; [OPTIONAL] Disable enclosure heater/fan SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=time_remaining VALUE=0 UPDATE_DELAYED_GCODE ID=DRYER_TIMER DURATION=0 ; Stop the timer. M117 Drying Stopped

[gcode_macro DRYER_STATUS] variable_time_remaining: 0 variable_bed_temperature: 0 variable_chamber_temperature: 0 gcode: {% if time_remaining > 0 %} M140 S{bed_temperature} ; Reset bed temperature (prevents timeout) ;M141 S{chamber_temperature} ; [OPTIONAL] reset chamber temperature SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=time_remaining VALUE={time_remaining - 1} M117 Drying {time_remaining} {% else %} STOP_DRYER {% endif %}

[delayed_gcode DRYER_TIMER] gcode: UPDATE_DELAYED_GCODE ID=DRYER_TIMER DURATION=1 DRYER_STATUS [delayed_gcode TURN_TIMER] gcode: M300 M300 RESPOND PREFIX=tgalarm MSG="turn the spool :)" [gcode_macro DRY_PLA] gcode: START_DRYER TEMPERATURE=50 CHAMBER=25 TIME=14400

[gcode_macro DRY_PETG] gcode: START_DRYER TEMPERATURE=55 CHAMBER=30 TIME=18000

[gcode_macro DRY_ABS] gcode: START_DRYER TEMPERATURE=65 CHAMBER=40 TIME=14400

I tried the first code and got:

Option 'default_parameter_time' is not valid in section 'gcode_macro start_dryer'

Once the underlying issue is corrected, use the "RESTART" command to reload the config and restart the host software. Printer is halted

Then I used your code but it spat at me even more issues then before:

File contains parsing errors: /home/pi/klipper_config/macros.cfg
[line 96]: 'M140 S{temperature} ; Sets the print bed temperature without waiting.\n'
[line 104]: 'SET_IDLE_TIMEOUT\n'
[line 109]: 'M140 S0 ; Disable bed heater\n'
[line 113]: 'M117 Drying Stopped\n'
[line 120]: '{% if time_remaining > 0 %}\n'
[line 121]: 'M140 S{bed_temperature} ; Reset bed temperature (prevents timeout)\n'
[line 124]: 'M117 Drying {time_remaining}\n'
[line 125]: '{% else %}\n'
[line 126]: 'STOP_DRYER\n'
[line 127]: '{% endif %}\n'
[line 132]: 'DRYER_STATUS\n'
[line 135]: 'M300\n'
[line 136]: 'M300\n'

I don't know how to fix this..

@ogabriel
Copy link

Another addition, to avoid too "many" logs if you're using a modified M117 that logs on klipper console, it's possible to add a "if" to only log in certain scenarios

    {% if time_remaining > 0 %}
        M140 S{bed_temperature} ; Reset bed temperature (prevents timeout)
        M141 S{chamber_temperature} ; [OPTIONAL] reset chamber temperature
        SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=time_remaining VALUE={time_remaining - 1}

        {% if (time_remaining % 600 == 0) or (300 <= time_remaining <= 1800 and time_remaining % 300 == 0) or time_remaining < 60 %}
            M117 Remaining drying time {time_remaining|int}
        {% endif %}
    {% else %}
        STOP_DRYER
    {% endif %}
  

@pietersmartijn
Copy link

@RealSpyKitty indent the lines beneath gcode:

@IBICO74
Copy link

IBICO74 commented Jan 7, 2023

Parameters changed with new updates. The two under are ok, but anyone got one for TIME?

{% set bed_temp = params.BED_TEMP|default(60) %}
{% set extruder_temp = params.EXTRUDER_TEMP|default(200) %}

@akash191095
Copy link

This is working for me:

; An idea for using the heated bed of a 3D printer as a filament dryer.
; Adds GCODE command: START_DRYER TIME=T TEMPERATURE=C CHAMBER=C
; (T is time in seconds, C is temperature in Celsuis)
; To stop drying early, use STOP_DRYER.
; Also defined some utility macros: DRY_PLA, DRY_PETG and DRY_ABS.
; Edit these with your own preferred defaults.

[gcode_macro START_DRYER]
variable_time: 14400
variable_temprature: 50.0
variable_chamber: 25.0
gcode:
    ; turn the heaters on, however you do that.
    M140 S{temprature} ; Sets the print bed temperature without waiting.
    #M141 S{CHAMBER}     ; [OPTIONAL] Sets the enclosure temperature.
    ; then finally,
    SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=time_remaining VALUE={time}
    SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=bed_temperature VALUE={temprature}
    #SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=chamber_temperature VALUE={CHAMBER}
    UPDATE_DELAYED_GCODE ID=DRYER_TIMER DURATION=1
    SET_IDLE_TIMEOUT 

[gcode_macro STOP_DRYER]
gcode:
    ; Turn off heaters etc. here
    M140 S0 ; Disable bed heater
    #M141 S0 ; [OPTIONAL] Disable enclosure heater/fan
    SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=time_remaining VALUE=0
    UPDATE_DELAYED_GCODE ID=DRYER_TIMER DURATION=0    ; Stop the timer.
    M117 Drying Stopped

[gcode_macro DRYER_STATUS]
variable_time_remaining: 0
variable_bed_temperature: 0
variable_chamber_temperature: 0
gcode:
    {% if time_remaining > 0 %}
        M140 S{bed_temperature} ; Reset bed temperature (prevents timeout)
        #M141 S{chamber_temperature} ; [OPTIONAL] reset chamber temperature
        SET_GCODE_VARIABLE MACRO=DRYER_STATUS VARIABLE=time_remaining VALUE={time_remaining - 1}
        M117 Drying {time_remaining}
    {% else %}
        STOP_DRYER
    {% endif %}

[delayed_gcode DRYER_TIMER]
gcode:
    UPDATE_DELAYED_GCODE ID=DRYER_TIMER DURATION=1
    DRYER_STATUS

[gcode_macro DRY_PLA]
gcode:
    START_DRYER TEMPERATURE=50 CHAMBER=25 TIME=14400

[gcode_macro DRY_PETG]
gcode:
    START_DRYER TEMPERATURE=55  CHAMBER=30 TIME=18000

[gcode_macro DRY_ABS]
gcode:
    START_DRYER TEMPERATURE=65 CHAMBER=40 TIME=14400

@LeHungryBoi
Copy link

LeHungryBoi commented Mar 3, 2024

the one above doesn't have working parameter, this one's fixed.
also, add [respond] to your printer.cfg, or M118 isn't gonna work.

[respond]
#default_type: echo
# Sets the default prefix of the "M118" and "RESPOND" output to one
# of the following:
# echo: "echo: " (This is the default)
# command: "// "
# error: "!! "
#default_prefix: echo:
# Directly sets the default prefix. If present, this value will
# override the "default_type".

[gcode_macro START_DRYER]
gcode:
{% set TIME_PARAM = params.TIME|default(3)|float %}
{% set TEMP_PARAM = params.TEMP|default(50)|float %}
M140 S{TEMP_PARAM} ; non blocking bed temp
SET_GCODE_VARIABLE MACRO=DRYER_STATE VARIABLE=time_remain_var VALUE={TIME_PARAM}
SET_GCODE_VARIABLE MACRO=DRYER_STATE VARIABLE=bed_temp_var VALUE={TEMP_PARAM}
UPDATE_DELAYED_GCODE ID=DRYER_TIMER DURATION=1
;SET_IDLE_TIMEOUT ;called w/o param and dont even need? cause timer tick reset temp anyway?

[gcode_macro STOP_DRYER]
gcode:
; Turn off heaters etc. here
M140 S0 ; Disable bed heater
SET_GCODE_VARIABLE MACRO=DRYER_STATE VARIABLE=time_remain_var VALUE=0
UPDATE_DELAYED_GCODE ID=DRYER_TIMER DURATION=0 ; Stop the timer.
M118 Drying Stopped

[gcode_macro DRYER_STATE]
variable_time_remain_var: 0
variable_bed_temp_var: 0
gcode:
{% if time_remain_var > 0 %}
M140 S{bed_temp_var} ; Reset bed temp (prevents timeout)
SET_GCODE_VARIABLE MACRO=DRYER_STATE VARIABLE=time_remain_var VALUE={time_remain_var - 1}
M118 Drying {time_remain_var}
{% else %}
STOP_DRYER
{% endif %}

[delayed_gcode DRYER_TIMER]
gcode:
UPDATE_DELAYED_GCODE ID=DRYER_TIMER DURATION=1
DRYER_STATE

;flip filament every 6h
[gcode_macro DRY_PLA]
gcode:
START_DRYER temp=55 time=43200
[gcode_macro DRY_PETG]
gcode:
START_DRYER temp=65 time=43200
[gcode_macro DRY_ABS]
gcode:
START_DRYER temp=80 time=43200
[gcode_macro DRY_WarmRoom]
gcode:
START_DRYER temp=100 time=43200

@NameOfTheDragon
Copy link
Author

Thanks for posting the update. I think Klipper changed the syntax for accessing parameter values some time back, which accounts for the errors. I've just updated the Gist with my current working version which should work now. It's interesting to see other people's variations and additions though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment