# TMC2240 use temp for fan control

**URL:** <https://klipper.discourse.group/t/tmc2240-use-temp-for-fan-control/25703>\
**Category:** Macros\
**Created:** [March 4, 2026, 9:29pm UTC](https://klipper.discourse.group/t/tmc2240-use-temp-for-fan-control/25703 "2026-03-04T21:29:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nefelim4ag](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/nefelim4ag/32/2387_2.png) [@nefelim4ag](https://klipper.discourse.group/u/nefelim4ag)\
**Post date:** [March 4, 2026, 9:29pm UTC](https://klipper.discourse.group/t/tmc2240-use-temp-for-fan-control/25703/1 "2026-03-04T21:29:09Z")

</div>

TMC2240 is special.  
TMC2240 only reports temperature if driver is enabled.  
Here is an example, based on my setup, where I have glued a thermistor to the X(A) and data from TMC2240:

```auto
[display_template drivers_fan]
param_min_temp: 60
param_max_temp: 85
text:
    {% set a_driver_temp = printer["temperature_sensor XA_Driver"].temperature %}
    {% set z_driver_temp = printer["tmc2240 stepper stepper_z"].temperature %}
    {% set delta = param_max_temp - param_min_temp %}
    {% if z_driver_temp is none %}
    # Overwrite empty/missing z temp value
    {% set z_driver_temp = a_driver_temp %}
    {% endif %}
    {((a_driver_temp + z_driver_temp)/2 - param_min_temp) / delta}
    
# Start the electronics bay fan control
[delayed_gcode _START_DRIVERS_FAN]
initial_duration: 1.
gcode:
  SET_FAN_SPEED FAN=drivers TEMPLATE=drivers_fan

[fan_generic drivers]
...

```

This is simple proportional control.  
Where the target minimal activation temp is 60 degrees, and the fan speed will scale based on the temperature overshoot.  
25 is a scaling factor.  
So, 60 + 25 = 85.  
At 85C template would produce 100% PWM for the fan.

_Template evaluation errors are printed into the log_

Hope that helps someone,  
-Timofey

* * *

Cross-linking section:

- [Temperature\_fan depending on the TMC2240 temperature?](https://klipper.discourse.group/t/temperature-fan-depending-on-the-tmc2240-temperature/15198)
