2026-10-10 14:24:37 +02:00
# Bed fans driven by the bed heater (based on Ellis' bed fan macros)
2026-11-06 16:18:38 +01:00
#
# During a print without a heated chamber the fans stay off while the bed heats,
# soaks and prints: with the chamber open they only blow room air past the bed.
# PRINT_WARMUP sets print_fans_off, _PRINT_CLEANUP clears it. The cooldown after
# the print and heating the bed outside a print are not affected.
2026-10-10 14:24:37 +02:00
2026-10-10 13:45:11 +02:00
############### Config options ##################
[gcode_macro _BEDFANVARS]
variable_threshold: 50 # If bed temp target is above this threshold, fans will be enabled. If temp is set to below this threshold, fans will be disabled.
variable_fast: 1.0 # Fan speed once bed temp is reached
variable_slow: 0.5 # Fan speed while bed is heating
variable_cooldown_temp: 40 # NEW: fans stop below this temp
2026-11-06 16:18:38 +01:00
variable_print_fans_off: False # set by PRINT_WARMUP for a print without a heated chamber
2026-10-10 13:45:11 +02:00
gcode:
########## Aliases #########
[gcode_macro BEDFANSSLOW]
gcode:
# Vars
{% set SLOW = printer["gcode_macro _BEDFANVARS"].slow|float %}
SET_FAN_SPEED FAN = BedFans SPEED={SLOW}
[gcode_macro BEDFANSFAST]
gcode:
# Vars
{% set FAST = printer["gcode_macro _BEDFANVARS"].fast|float %}
SET_FAN_SPEED FAN = BedFans SPEED={FAST}
[gcode_macro BEDFANSOFF]
gcode:
SET_FAN_SPEED FAN = BedFans SPEED=0
############ Command overrides ############
# Override, set fan speeds to low and start monitoring loop.
[gcode_macro SET_HEATER_TEMPERATURE]
rename_existing: _SET_HEATER_TEMPERATURE
gcode:
# Parameters
{% set HEATER = params.HEATER|default("None") %}
{% set TARGET = params.TARGET|default(0)|int %}
# Vars
{% set THRESHOLD = printer["gcode_macro _BEDFANVARS"].threshold|int %}
{% set COOLDOWN = printer["gcode_macro _BEDFANVARS"].cooldown_temp|int %}
2026-11-06 16:18:38 +01:00
{% set FANS_OFF = printer["gcode_macro _BEDFANVARS"].print_fans_off %}
2026-10-10 13:45:11 +02:00
{% if HEATER|lower = = "extruder" %}
M104 S{TARGET}
# {% elif HEATER|lower == "iHeater_H" %}
# _SET_HEATER_TEMPERATURE {rawparams}
{% elif HEATER|lower = = "heater_bed" %}
M99140 S{TARGET}
# Always cancel cooldown loop first (prevents overlap)
UPDATE_DELAYED_GCODE ID = bedfancooldown DURATION=0
# --- NEW LOGIC BLOCK ---
{% if TARGET = = 0 %}
# Bed turning off → start cooldown behavior
{% if printer.heater_bed.temperature|int > COOLDOWN %}
BEDFANSSLOW
UPDATE_DELAYED_GCODE ID=bedfancooldown DURATION=5
{% else %}
BEDFANSOFF
{% endif %}
# Stop normal heating loop if running
UPDATE_DELAYED_GCODE ID = bedfanloop DURATION=0
2026-11-06 16:18:38 +01:00
{% elif TARGET > = THRESHOLD and not FANS_OFF %}
2026-10-10 13:45:11 +02:00
# Heating above threshold
BEDFANSSLOW
UPDATE_DELAYED_GCODE ID=bedfanloop DURATION=1
{% else %}
2026-11-06 16:18:38 +01:00
# Low temp request, or a print without a heated chamber
2026-10-10 13:45:11 +02:00
BEDFANSOFF
UPDATE_DELAYED_GCODE ID = bedfanloop DURATION=0
{% endif %}
# --- END NEW LOGIC ---
{% else %}
# {action_respond_info("(Bedfans macro)Heater %s not supported (trying classic _SET_HEATER_TEMPERATURE)" % HEATER)}
_SET_HEATER_TEMPERATURE {rawparams}
{% endif %}
# Override M190 (Wait for Bed Temperature)
# As a bonus, use TEMPERATURE_WAIT so we don't have to wait for PID to level off.
[gcode_macro M190]
rename_existing: M99190
gcode:
# Parameters
{% set S = params.S|int %}
# Vars
{% set THRESHOLD = printer["gcode_macro _BEDFANVARS"].threshold|int %}
2026-11-06 16:18:38 +01:00
{% set FANS_ON = S >= THRESHOLD and not printer["gcode_macro _BEDFANVARS"].print_fans_off %}
{% if FANS_ON %}
BEDFANSSLOW # > = Threshold temp: Low speed fans while heating
2026-10-10 13:45:11 +02:00
{% else %}
BEDFANSOFF # < Threshold temp: Turn bed fans off
{% endif %}
M140 {% for p in params
%}{'%s%s' % (p, params[p])}{%
endfor %} # Set bed temp
{% if S ! = 0 %}
TEMPERATURE_WAIT SENSOR=heater_bed MINIMUM={S|int} MAXIMUM={S|int + 5} # Wait for bed temp within 5 degrees
{% endif %}
# Post-heating fan speeds
2026-11-06 16:18:38 +01:00
{% if FANS_ON %}
BEDFANSFAST # > = Threshold temp: Higher speed fans after heating finished
2026-10-10 13:45:11 +02:00
{% endif %}
# Replace M140 (Set Bed Temperature) to just be an alias of SET_HEATER_TEMPERATURE (which has associated bed fan logic if enabled)
[gcode_macro M140]
rename_existing: M99140
gcode:
# Parameters
{% set S = params.S|float %}
SET_HEATER_TEMPERATURE HEATER = heater_bed TARGET={S}
# Replace TURN_OFF_HEATERS
# [gcode_macro TURN_OFF_HEATERS]
# rename_existing: _TURN_OFF_HEATERS
# gcode:
# BEDFANSOFF
# _TURN_OFF_HEATERS
[gcode_macro TURN_OFF_HEATERS]
rename_existing: _TURN_OFF_HEATERS
gcode:
# Vars
{% set COOLDOWN = printer["gcode_macro _BEDFANVARS"].cooldown_temp|int %}
# Only keep fans running if bed is still hot
{% if printer.heater_bed.temperature|int > COOLDOWN %}
BEDFANSSLOW
UPDATE_DELAYED_GCODE ID = bedfancooldown DURATION=5
{% else %}
BEDFANSOFF
{% endif %}
_TURN_OFF_HEATERS
################ Monitoring loop #####################
# Turns bed fans to "fast" speed once target bed temp is reached.
[delayed_gcode bedfanloop]
gcode:
# Vars
{% set THRESHOLD = printer["gcode_macro _BEDFANVARS"].threshold|int %}
2026-11-06 16:18:38 +01:00
{% if printer.heater_bed.target > = THRESHOLD and not printer["gcode_macro _BEDFANVARS"].print_fans_off %} # Continue only if target temp greater than threshold.
2026-10-10 13:45:11 +02:00
{% if printer.heater_bed.temperature|int >= (printer.heater_bed.target|int - 1) %}
BEDFANSFAST # If within 1 degree of target temp: Higher speed fans
{% else %}
UPDATE_DELAYED_GCODE ID=bedfanloop DURATION=5 # If temp not reached yet: loop again
{% endif %}
{% endif %}
[delayed_gcode bedfancooldown]
gcode:
# Vars
{% set COOLDOWN = printer["gcode_macro _BEDFANVARS"].cooldown_temp|int %}
{% if printer.heater_bed.temperature|int > COOLDOWN %}
BEDFANSSLOW
UPDATE_DELAYED_GCODE ID = bedfancooldown DURATION=10
{% else %}
BEDFANSOFF
{% endif %}