IDEX Parts cooling fan turned off

I have an IDEX printer, and I want to activate the fan of the second extruder when the tool is activated, I saw a Macro here, so I just copied, but still not working. So, basically something is sending the SET_FAN_SPEED FAN=extruder1_partfan SPEED=0 when the tool changes.
klippy.log (931.1 KB)
Should I write something on the GCode of the Tool Change? I tried but did’t worked. Appreciated

[fan_generic extruder0_partfan]
pin: PB0

[fan_generic extruder1_partfan]
pin: PB1

[gcode_macro M106]
gcode:
{% if params.P is defined %}
{% if params.S is defined %}
{% if params.S|int == 255 %}
{% set realspeed = 1 %}
{% else %}
{% if params.S|int == 0 %}
{% set realspeed = 0 %}
{% else %}
{% set realspeed = 0.003921params.S|int %}
{% endif %}
{% endif %}
SET_FAN_SPEED FAN=extruder{params.P|int}_partfan SPEED={realspeed}
{% else %}
SET_FAN_SPEED FAN=extruder{params.P|int}_partfan SPEED=1
{% endif %}
{% else %}
{% if params.S is defined %}
{% if params.S|int == 255 %}
{% set realspeed = 1 %}
{% else %}
{% if params.S|int == 0 %}
{% set realspeed = 0 %}
{% else %}
{% set realspeed = 0.003921params.S|int %}
{% endif %}
{% endif %}
SET_FAN_SPEED FAN=extruder0_partfan SPEED={realspeed}
{% else %}
SET_FAN_SPEED FAN=extruder0_partfan SPEED=1
{% endif %}
{% endif %}

[gcode_macro M107]
gcode:
{% if params.P is defined %}
SET_FAN_SPEED FAN=extruder{params.P|int}_partfan SPEED=0
{% else %}
SET_FAN_SPEED FAN=extruder0_partfan SPEED=0
SET_FAN_SPEED FAN=extruder1_partfan SPEED=0
{% endif %}

Hi @SiC_FPV try this

## add to T0 macro
SET_GCODE_VARIABLE MACRO=FAN_VARIABLE VARIABLE=active_fan VALUE=0
CARRIAGE_PRINT_FAN 

## add to T1 macro
SET_GCODE_VARIABLE MACRO=FAN_VARIABLE VARIABLE=active_fan VALUE=1
CARRIAGE_PRINT_FAN

HW config


# X1 print cooling fan
[fan_generic fan]
pin: PC9
cycle_time: 0.0100
kick_start_time: 1.00

# X2 print cooling fan
[fan_generic fan1]
pin: PA8
cycle_time: 0.0100
kick_start_time: 1.000

Macro M106 / M107


[gcode_macro FAN_VARIABLE]
gcode:

variable_active_fan: 0

#--- Carriages print cooling FANs ---
variable_fan: 'fan'    # carriage X1
variable_fan1: 'fan1'   # carriage X2
#--- Other user define FANs ---
variable_fan2: 'fan2'     
variable_fan3: 'fan3'
variable_fan4: 'fan4'  
variable_fan5: 'fan5'


##########################################################
# PRINTER FANS MANAGEMENT
# Redefine G-code command M106 and M107 
##########################################################

[gcode_macro M106]
description: Override "M106" to allow multiple extruders.
gcode:

    {% set fan_vars = printer["gcode_macro FAN_VARIABLE"] %}
    {% set raw_speed = params.S|default(0)|float %}
    {% set fan_speed = (raw_speed / 255.0)|round(2) %}     
        
    {% set target_fan = params.P|default(fan_vars.active_fan)|int %}
    {% set default_fan = ('fan', 'fan1', 'fan2', 'fan3', 'fan4', 'fan5')[target_fan] %}     
    
    {% if target_fan in [0,1] %}
       ### carriages print cooling FAN   
        CARRIAGE_PRINT_FAN SPEED={fan_speed}
    {% else %}
       ### other user define FAN
        SET_FAN_SPEED FAN={default_fan} SPEED={fan_speed}
    {% endif %}
 

[gcode_macro M107]
description: Override "M107" to allow multiple extruders.
gcode:
    M106 S0
     
 
[gcode_macro CARRIAGE_PRINT_FAN]
description: Set automatically the print fan speed for dual carriages modes 
gcode:
    {% set fan_vars = printer["gcode_macro FAN_VARIABLE"] %}      
    
    {% if params.SPEED is defined %}
        {% set fan_speed = params.SPEED|float %}
    {% else %}
        ### read print fan speed from active carriage/extruder
        {% set fan_speed = printer["fan_generic " + fan_vars.fan].speed|float %}
        {% set fan1_speed = printer["fan_generic " + fan_vars.fan1].speed|float %}
        {% set fan_speed = [fan_speed, fan1_speed]|max %}
    {% endif %}
        
    {% if fan_vars.active_fan == 0 %}
        ### FAN on carriage X1
        SET_FAN_SPEED FAN={fan_vars.fan} SPEED={fan_speed}
        SET_FAN_SPEED FAN={fan_vars.fan1} SPEED=0
    {% elif fan_vars.active_fan == 1 %}
        ### FAN on carriage X2
        SET_FAN_SPEED FAN={fan_vars.fan} SPEED=0
        SET_FAN_SPEED FAN={fan_vars.fan1} SPEED={fan_speed}
    {% endif %}
    
1 Like

Thanks mate! I’ll try it, but seems it’s working!!! :smiley:

1 Like

of course it works, I have tested it :slight_smile:

1 Like

Hi @SiC_FPV
Version 2 - for multiple extruders on one carriages
eg my printer … Test(2) - YouTube

Add to macro Txx

## add to T0 macro
#  
#  CARRIAGE_PRINT_FAN 
#
## add to T1 macro
# 
#  CARRIAGE_PRINT_FAN

HW config FANs

# X1 print cooling fan
# [fan_generic fan]
# pin: PC9
# cycle_time: 0.0100
# kick_start_time: 1.00

# X2 print cooling fan
# [fan_generic fan1]
# pin: PA8
# cycle_time: 0.0100
# kick_start_time: 1.000

# Other define FANs
# [fan_generic fan2]
# pin:
# [fan_generic fan3]
# pin:
# [fan_generic fan4]
# pin:
# [fan_generic fan5]
# pin:

Macros M160 / M107



##########################################################
# PRINTER FANS MANAGEMENT
# Redefine G-code command M106 and M107 
##########################################################

[gcode_macro M106]
description: Override "M106" to allow multiple extruders.
gcode:

    
    {% set raw_speed = params.S|default(255)|float %}
    {% set fan_speed = (raw_speed / 255.0)|round(2) %} 

    {% if (params.P) is defined %}  
      {% set target_fan = params.P|int %}     
      {% set default_fan = ('fan', 'fan1', 'fan2', 'fan3', 'fan4', 'fan5')[target_fan] %}  
       SET_FAN_SPEED FAN={default_fan} SPEED={fan_speed}
    {% else %}
        ### carriages print cooling FAN   
        CARRIAGE_PRINT_FAN SPEED={fan_speed}       
    {% endif %}

#=============================================================== 


[gcode_macro M107]
description: Override "M107" to allow multiple extruders.
gcode:

    {% if (params.P) is defined %} 
      M106 S0 P{params.P}
    {% else %}
      M106 S0
    {% endif %}

#===============================================================
 
[gcode_macro CARRIAGE_PRINT_FAN]
description: Set automatically the print fan speed for dual carriages modes 

#--- Carriages print cooling FANs ---
variable_fan: 'fan'    # carriage X1
variable_fan1: 'fan1'   # carriage X2

gcode:
     
    ### FAN speed  
    {% if params.SPEED is defined %}
        {% set fan_speed = params.SPEED|float %}
    {% else %}
        ### read print fan speed from active carriage/extruder        
        {% set fan_speed = printer["fan_generic " + fan].speed|float %}
        {% set fan1_speed = printer["fan_generic " + fan1].speed|float %}
        {% set fan_speed = [fan_speed, fan1_speed]|max %}
    {% endif %}


    ### Active FAN for carriage
    {% set active_toolhead =({'extruder':0,'extruder1':1,'extruder2':2,'extruder3':3})[printer['toolhead'].extruder] %}    
    
     {% if active_toolhead in [0,1] %}   
        ### FAN on carriage X1       
        SET_FAN_SPEED FAN={fan} SPEED={fan_speed}
        SET_FAN_SPEED FAN={fan1} SPEED=0

     {% elif active_toolhead in [2,3] %}   
        ### FAN on carriage X2        
        SET_FAN_SPEED FAN={fan} SPEED=0
        SET_FAN_SPEED FAN={fan1} SPEED={fan_speed}
    {% endif %}
    ```
3 Likes

Damn bro! :pray: You’re the best!!! The first one worked perfect. And this one will do it as well!!! Klipper community is the best :pray: much appreciated!

I’m not the best … these are others who help learn Klipper :slight_smile:

Do you use hybrid_corexy or hybrid_corexz kinematics?

it could work this:

### Active FAN for carriage
    
    
     {% if printer.dual_carriage.active_carriage == "CARRIAGE_0" %}  
        ### FAN on carriage X1       
        SET_FAN_SPEED FAN={fan} SPEED={fan_speed}
        SET_FAN_SPEED FAN={fan1} SPEED=0

     {% elif printer.dual_carriage.active_carriage == "CARRIAGE_1" %} 
        ### FAN on carriage X2        
        SET_FAN_SPEED FAN={fan} SPEED=0
        SET_FAN_SPEED FAN={fan1} SPEED={fan_speed}
    {% endif %}```

Hi I’ve tried to use your macros but I receive this error:
!! Error evaluating 'gcode_macro M106:gcode': jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'active_fan'
Any suggestion? (please)

Hi, send me your current gcode_macro M106.

Here it is, thank you

[gcode_macro FAN_VARIABLE]
gcode:
    variable_active_fan: 1
    #--- Carriages print cooling FANs ---
    variable_fan: 'fan'    # carriage X1
    variable_fan1: 'fan1'   # carriage X2
    #--- Other user define FANs ---
    variable_fan2: 'fan2'     
    variable_fan3: 'fan3'
    variable_fan4: 'fan4'  
    variable_fan5: 'fan5'
    
    
[gcode_macro M106]
description: Override "M106" to allow multiple extruders.
gcode:
    {% set fan_vars = printer["gcode_macro FAN_VARIABLE"] %}
    {% set raw_speed = params.S|default(0)|float %}
    {% set fan_speed = (raw_speed / 255.0)|round(2) %}     
        
    {% set target_fan = params.P|default(fan_vars.active_fan)|int %}
    {% set default_fan = ('fan', 'fan1', 'fan2', 'fan3', 'fan4', 'fan5')[target_fan] %}     
    
    {% if target_fan in [0,1] %}
       ### carriages print cooling FAN   
        CARRIAGE_PRINT_FAN SPEED={fan_speed}
    {% else %}
       ### other user define FAN
        SET_FAN_SPEED FAN={default_fan} SPEED={fan_speed}
    {% endif %}


[gcode_macro M107]
description: Override "M107" to allow multiple extruders.
gcode:
    M106 S0


[gcode_macro CARRIAGE_PRINT_FAN]
description: Set automatically the print fan speed for dual carriages modes 
gcode:
    {% set fan_vars = printer["gcode_macro FAN_VARIABLE"] %}      
    
    {% if params.SPEED is defined %}
        {% set fan_speed = params.SPEED|float %}
    {% else %}
        ### read print fan speed from active carriage/extruder
        {% set fan_speed = printer["fan_generic " + fan_vars.fan].speed|float %}
        {% set fan1_speed = printer["fan_generic " + fan_vars.fan1].speed|float %}
        {% set fan_speed = [fan_speed, fan1_speed]|max %}
    {% endif %}
        
    {% if fan_vars.active_fan == 0 %}
        ### FAN on carriage X1
        SET_FAN_SPEED FAN={fan_vars.fan} SPEED={fan_speed}
        SET_FAN_SPEED FAN={fan_vars.fan1} SPEED=0
    {% elif fan_vars.active_fan == 1 %}
        ### FAN on carriage X2
        SET_FAN_SPEED FAN={fan_vars.fan} SPEED=0
        SET_FAN_SPEED FAN={fan_vars.fan1} SPEED={fan_speed}
    {% endif %}

Hi, this is probably my first macro.
I am currently using universal macros for various printer cfgs.
Info here: GitHub - DrumClock/my_config

The advantage is that the names of the fans are loaded from printer.cfg and also the switching logic for IDEX, which is dependent on the type of kinematics, is redesigned.

Try new macros, otherwise you’ll have to find the problem yourself because it doesn’t have your complete cfg.

-Petr

1 Like

It simply works :money_mouth_face: