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:
[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: