TemperatureSwitch

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
New in V2: start_armed Setting
Smoothieware V2 introduces the 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.

All options

V1 Setting V2 Setting Description

Creates and enables a new TemperatureSwitch module instance. When set to true, this module monitors temperature from a specified TemperatureControl module and automatically controls 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).

The 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. Matching is case-sensitive — T and t are different designators.

  • For backward compatibility, temperatureswitch.hotend defaults to designator T if not specified (deprecated behavior)
  • An empty designator string causes the temperature switch to be considered invalid and non-functional

The temperature reading is polled at intervals defined by the 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 is 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. It 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. Functionally identical to the parameter, and only used as a fallback if that parameter is not defined.

This parameter has been replaced by , but is still supported for backward compatibility with older Smoothieware configurations. Not recommended for new configurations — use the switch parameter instead, for clarity.

Sets the temperature threshold in degrees Celsius at which the switch state changes. The exact behavior depends on the trigger mode:

  • level mode: switch turns on above this temperature and off below it
  • rising mode: switch triggers when crossing upward through this threshold
  • falling mode: switch triggers when crossing downward through this threshold

Temperature comparison uses current_temp >= threshold_temp for HIGH_TEMP state determination. Temperature is read from the highest value among all temperature controllers matching the configured designator.

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 — the threshold applies regardless of whether the switch is inverted or not, since inversion only affects the final switch output state.

Defines the polling interval in seconds when the system is in the LOW_TEMP state (current temperature < threshold_temp) — i.e. while heating up. A shorter interval gives faster response when temperature rises toward the threshold, but increases system overhead.

The initial state uses the heatup_poll interval and performs its first check immediately. Once temperature crosses the threshold, polling automatically switches to the cooldown_poll interval. Polling occurs on the second tick event, so actual timing may vary by ±1 second.

  • Lower values (e.g., 5-10 seconds): quicker response, more processing time consumed
  • Higher values (e.g., 20-30 seconds): less overhead, may delay switch activation

Defines the polling interval in seconds when the system is in the HIGH_TEMP state (current temperature >= threshold_temp) — at or above 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.

Slower polling during stable operation reduces system load, and is suitable for applications where the switch should remain on for extended periods. Once temperature falls below the threshold, polling automatically switches to the heatup_poll interval.

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 — whether it 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 the 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.

  • Normal mode (false): temperature >= threshold → switch on; temperature < threshold → switch off
  • Inverted mode (true): temperature >= threshold → switch off; temperature < threshold → switch on

The inversion occurs at the final switch control stage, applied in the set_switch() function after trigger logic has determined the desired state — it works with all trigger modes (level, rising, falling). Temperature threshold comparison logic is 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. It also acts as a safety mechanism for critical temperature-dependent operations — disarmed switches do not control their associated switch modules.

  • When set to 0: the arming requirement is disabled; the switch is always armed and operates automatically based on temperature (module does not register for G-code events)
  • When set to an M-code: the 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: the switch remains armed and continues operating while armed
  • Edge trigger modes (rising/falling): the switch automatically disarms after triggering once, requiring re-arming for subsequent triggers
If you want to learn more about this module, or are curious how it works, Smoothie is Open-Source and you can simply go look at the code, here.
This is a wiki! If you'd like to improve this page, you can edit it on GitHub.