TemperatureSwitch is an optional module that automatically controls an output (typically to control one of the small MOSFETs) through a Switch module, based on a configurable threshold temperature.
It is commonly used to turn on/off a cooling fan or water pump to cool a 3D printer extruder hot end’s cold zone.
Simply, TemperatureSwitch turns on/off the switch.xxx where xxx is the user-defined switch.xxx = fan or misc in the default configuration files.
If the printer has multiple hot ends, TemperatureSwitch will monitor all of them and if any one goes over the threshold, will turn on the switch. It will only turn the switch off if all of them are below the threshold temperature.
Since hot ends heat up relatively quickly and cool off slowly, the polling interval for heatup and cooldown are independently configurable in the configuration file. This is done to minimize processor load during printing.
Here’s a description of the configurable parameters:
Basic hotend cooling fan configuration (V1):
# automatically toggle a switch at a specified temperature
# useful to turn on a fan or water pump to cool the hotend
temperatureswitch.hotend.enable true # enable this module
temperatureswitch.hotend.switch fan2 # select which MOSFET to use, must match a switch configuration (fan2 below)
temperatureswitch.hotend.designator T # first character of the temperature control designator to use as the temperature sensor to monitor
temperatureswitch.hotend.threshold_temp 60.0 # temperature to turn on (if rising) or off the switch
temperatureswitch.hotend.heatup_poll 15 # poll heatup at 15 sec intervals
temperatureswitch.hotend.cooldown_poll 60 # poll cooldown at 60 sec intervals
switch.fan2.enable true # enable
switch.fan2.input_on_command M42 # gcode to turn on
switch.fan2.input_off_command M43 # gcode to turn off
switch.fan2.output_pin 2.4 # pin that controls the fan
Many temperatureswitch instances can be defined that monitor different temperatures and trigger different switches. For instance, one to turn a motor fan on and off. Also note that a readonly temperature control can be defined:
temperatureswitch.motor.enable true #
temperatureswitch.motor.switch motorfan #
temperatureswitch.motor.designator M #
switch.motorfan.enable true # enable
switch.motorfan.input_on_command M42 # gcode to turn on
switch.motorfan.input_off_command M43 # gcode to turn off
switch.motorfan.output_pin 2.4 # pin that controls the fan
# define a readonly temperaturecontrol for a motor
temperature_control.motor.enable true # Whether to activate this ( "hotend" ) module at all. All configuration is ignored if false.
temperature_control.motor.thermistor_pin 0.24 # Pin for the thermistor to read
temperature_control.motor.heater_pin nc # set to nc to make it a readonly temperature control
temperature_control.motor.thermistor EPCOS100K # thermistor name
temperature_control.motor.designator M # designator
Advanced example - PSU auto-shutdown:
Turn the PSU off when the hotend temp cools below 50°C, only after M1100 S1 has been executed to arm it:
temperatureswitch.psu_off.enable true #
temperatureswitch.psu_off.designator T # first character of the temperature control designator to use as the temperature sensor to monitor
temperatureswitch.psu_off.switch psu # select which switch to use, matches the name of the defined switch
temperatureswitch.psu_off.threshold_temp 50.0 # temperature to trigger at when falling
temperatureswitch.psu_off.heatup_poll 30 # poll heatup every 30 seconds
temperatureswitch.psu_off.cooldown_poll 30 # poll cooldown every 30 seconds
temperatureswitch.psu_off.arm_mcode 1100 # M1100 S1 will arm it
temperatureswitch.psu_off.trigger falling # only trigger when the temp falls below after being above
temperatureswitch.psu_off.inverted false # turn the switch off when we trigger (by default switches on when rising and off when falling)
Basic hotend cooling fan configuration (V2):
[temperature switch]
# automatically toggle a switch at a specified temperature
# useful to turn on a fan or water pump to cool the hotend
hotend.enable = true # enable this module
hotend.switch = fan2 # select which switch to use, must match a switch configuration (fan2 below)
hotend.designator = T # first character of the temperature control designator to use as the temperature sensor to monitor
hotend.threshold_temp = 60.0 # temperature to turn on (if rising) or off the switch
hotend.heatup_poll = 15 # poll heatup at 15 sec intervals
hotend.cooldown_poll = 60 # poll cooldown at 60 sec intervals
hotend.trigger = level # continuous control (on when above, off when below)
hotend.inverted = false # normal operation (fan on when hot)
[switch]
fan2.enable = true # enable
fan2.input_on_command = M42 # gcode to turn on
fan2.input_off_command = M43 # gcode to turn off
fan2.output_pin = 2.4 # pin that controls the fan
Many temperatureswitch instances can be defined that monitor different temperatures and trigger different switches. For instance, one to turn a motor fan on and off. Also note that a readonly temperature control can be defined:
[temperature switch]
motor.enable = true #
motor.switch = motorfan #
motor.designator = M #
[switch]
motorfan.enable = true # enable
motorfan.input_on_command = M42 # gcode to turn on
motorfan.input_off_command = M43 # gcode to turn off
motorfan.output_pin = 2.4 # pin that controls the fan
[temperature control]
# define a readonly temperaturecontrol for a motor
motor.enable = true # Whether to activate this ( "hotend" ) module at all. All configuration is ignored if false.
motor.thermistor_pin = 0.24 # Pin for the thermistor to read
motor.heater_pin = nc # set to nc to make it a readonly temperature control
motor.thermistor = EPCOS100K # thermistor name
motor.designator = M # designator
Advanced example - PSU auto-shutdown:
Turn the PSU off when the hotend temp cools below 50°C, only after M1100 S1 has been executed to arm it:
[temperature switch]
psu_off.enable = true #
psu_off.designator = T # first character of the temperature control designator to use as the temperature sensor to monitor
psu_off.switch = psu # select which switch to use, matches the name of the defined switch
psu_off.threshold_temp = 50.0 # temperature to trigger at when falling
psu_off.heatup_poll = 30 # poll heatup every 30 seconds
psu_off.cooldown_poll = 30 # poll cooldown every 30 seconds
psu_off.arm_mcode = 1100 # M1100 S1 will arm it
psu_off.trigger = falling # only trigger when the temp falls below after being above
psu_off.inverted = false # turn the switch off when we trigger (by default switches on when rising and off when falling)
psu_off.start_armed = false # NEW IN V2: starts disarmed, must be armed manually
start_armed parameter to control the initial armed state when using arm_mcode. Set to true to have the switch start armed on boot, or false to require manual arming.
| V1 Setting | V2 Setting | Description |
|---|---|---|
| Creates and enables a new TemperatureSwitch module instance. When set to true, this module will monitor temperature from a specified TemperatureControl module and automatically control a Switch module based on configured thresholds and trigger conditions. Multiple temperature switch instances can be configured simultaneously by using different instance names. Each instance requires a unique module name (e.g., hotend, bed, chamber). Module will not function unless enabled and must be accompanied by valid designator and switch configuration. | ||
Specifies which TemperatureControl module to monitor by matching its designator character. The temperature switch reads the current temperature from the temperature control module with this designator and uses it to determine when to trigger the switch. If multiple temperature control modules share the same designator, the highest temperature among them is used for comparison. For backward compatibility, temperatureswitch.hotend defaults to designator T if not specified (deprecated behavior). Empty designator string causes the temperature switch to be considered invalid and non-functional. Case-sensitive matching - T and t are different designators. The temperature reading is polled at intervals defined by heatup_poll and cooldown_poll settings. |
||
| Specifies the name of the Switch module to be controlled by this temperature switch. When temperature conditions are met, this switch will be toggled on or off according to the configured trigger mode and inversion settings. The switch must be configured and enabled in the switch module settings before it can be controlled. The specified switch must exist and be properly configured with output_pin and output_type. Typically controls one of the small MOSFETs on the Smoothieboard. Switch state is only changed when armed (either always armed if arm_mcode=0, or manually armed via M-code). | ||
Legacy parameter name for specifying the switch module to control. This parameter has been replaced by temperatureswitch.switch but is still supported for backward compatibility with older configurations. New configurations should use the switch parameter instead. Only used as fallback if temperatureswitch.{name}.switch is not defined. Maintained for backward compatibility with configurations from older Smoothieware versions. Functionally identical to temperatureswitch.{name}.switch parameter. Not recommended for new configurations - use switch parameter for clarity. |
||
Sets the temperature threshold in degrees Celsius at which the switch state changes. The exact behavior depends on the trigger mode: in "level" mode, the switch turns on above this temperature and off below it; in "rising" mode, the switch triggers when crossing upward through this threshold; in "falling" mode, the switch triggers when crossing downward through this threshold. Temperature comparison uses: current_temp >= threshold_temp for HIGH_TEMP state determination. For typical hotend cooling applications, set this 10-20°C below the hotend operating temperature. Inverted mode reverses the on/off logic but uses the same threshold comparison. Temperature is read from the highest value among all temperature controllers matching the configured designator. The threshold applies regardless of whether the switch is inverted or not - inversion only affects the final switch output state. |
||
| Defines the polling interval in seconds when the system is in the LOW_TEMP state (below threshold temperature). This controls how frequently the temperature is checked while heating up. A shorter interval provides faster response when temperature rises toward the threshold, but increases system overhead. The polling occurs on the second tick event, so actual timing may vary by ±1 second. Active when current temperature < threshold_temp (LOW_TEMP state). Faster polling during heatup ensures timely switch activation. After temperature crosses threshold, automatically switches to cooldown_poll interval. Initial state uses heatup_poll interval and performs first check immediately. Lower values (e.g., 5-10 seconds) provide quicker response but consume more processing time. Higher values (e.g., 20-30 seconds) reduce overhead but may delay switch activation. | ||
| Defines the polling interval in seconds when the system is in the HIGH_TEMP state (at or above threshold temperature). This controls how frequently the temperature is checked while at operating temperature or cooling down. A longer interval reduces system overhead during stable high-temperature operation, while still monitoring for temperature drops that should trigger switch state changes. Active when current temperature >= threshold_temp (HIGH_TEMP state). Slower polling during stable operation reduces system load. After temperature falls below threshold, automatically switches to heatup_poll interval. Suitable for applications where switch should remain on for extended periods. Polling occurs on the second tick event, so actual timing may vary by ±1 second. Higher values reduce processing overhead when temperature is stable above threshold. | ||
| Determines the triggering behavior mode of the temperature switch. This setting controls whether the switch responds to sustained temperature levels, rising temperature edges, or falling temperature edges. The mode fundamentally changes how temperature threshold crossings are interpreted and affects the arming behavior. Level mode: Switch follows temperature state continuously. When armed and temperature >= threshold, switch is on; when temperature < threshold, switch is off. Remains active as long as armed. Rising mode: Switch activates only when transitioning from LOW_TEMP to HIGH_TEMP (edge detection). Requires arming via M-code for each activation cycle. Falling mode: Switch deactivates only when transitioning from HIGH_TEMP to LOW_TEMP (edge detection). Requires arming via M-code for each activation cycle. Edge-triggered modes (rising/falling) automatically disarm after triggering, requiring re-arming for subsequent triggers. Invalid trigger values default to "level" mode. State changes only occur when temperature crosses the threshold boundary, not during stable states. Works in conjunction with inverted setting - inversion is applied after trigger logic determines switch state. | ||
| Reverses the normal switch control logic. When enabled, the switch turns off when temperature exceeds the threshold (instead of turning on), and turns on when temperature falls below the threshold. This is useful for heaters or devices that should activate during cooling rather than heating. The inversion occurs at the final switch control stage, after all trigger logic has been evaluated. Normal mode (false): Temperature >= threshold → switch on; temperature < threshold → switch off. Inverted mode (true): Temperature >= threshold → switch off; temperature < threshold → switch on. Inversion is applied in set_switch() function after trigger type determines the desired state. Works with all trigger modes (level, rising, falling). Temperature threshold comparison logic remains unchanged; only the final switch output is inverted. Useful for controlling heating elements that should turn off when target temperature is reached. Common use case: emergency cooling systems that activate when temperature drops too low. | ||
Defines a custom M-code command that must be executed to arm the temperature switch before it can trigger. This provides manual control over when the temperature switch is active, preventing unwanted switch activation. Setting to 0 disables the arming requirement, making the switch always armed and operating automatically based on temperature. When set to 0: Switch is always armed and operates automatically. When set to M-code: Switch starts disarmed and requires manual arming via G-code command. Arming command: M<code> S1 arms the switch (e.g., M1100 S1). Disarming command: M<code> S0 disarms the switch (e.g., M1100 S0). Level trigger mode: Switch remains armed and continues operating while armed. Edge trigger modes (rising/falling): Switch automatically disarms after triggering once, requiring re-arming for subsequent triggers. Provides safety mechanism for critical temperature-dependent operations. Disarmed switches do not control their associated switch modules. Module only registers for G-code events if arm_mcode != 0. |