# Variables for heating to a temperature

**URL:** <https://klipper.discourse.group/t/variables-for-heating-to-a-temperature/11784>\
**Category:** General Discussion\
**Created:** [November 22, 2023, 5:19pm UTC](https://klipper.discourse.group/t/variables-for-heating-to-a-temperature/11784 "2023-11-22T17:19:43Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktb1228](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@ktb1228](https://klipper.discourse.group/u/ktb1228)\
**Post date:** [November 22, 2023, 5:19pm UTC](https://klipper.discourse.group/t/variables-for-heating-to-a-temperature/11784/1 "2023-11-22T17:19:43Z")

</div>

I have been manually editing my start gcode macro every time I change filament to change the temperature. I know there is a way to automate this process but I have had trouble understanding how to use variable. I would like to know how to set up variables in the start macro and change those variables in Cura slicer using my existing filament profiles.

here is my existing start gcode:

```auto
      M190 S100 #heat bed

      G28 #home
      BED_MESH_CALIBRATE PROFILE="default" #auto bed level
      
      G0 X110 Y110 Z10
      G1 X0 Y0 Z10 F4000.0 #move to start position
   
     M109 S240 #heat nozzle

```

---

<div class="post-metadata">

**Author:** ![andora1968](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@andora1968](https://klipper.discourse.group/u/andora1968)\
**Post date:** [November 22, 2023, 6:38pm UTC](https://klipper.discourse.group/t/variables-for-heating-to-a-temperature/11784/2 "2023-11-22T18:38:59Z")

</div>

[gcode\_macro START\_PRINT]  
gcode:  
{% set BED\_TEMP = params.BED\_TEMP|default(60)|float %}  
{% set EXTRUDER\_TEMP = params.EXTRUDER\_TEMP|default(200)|float %}  
M190 S{BED\_TEMP}  
M109 S{EXTRUDER\_TEMP}  
G28 ;Home  
BED\_MESH\_PROFILE LOAD=default  
G92 E0 ;Reset Extruder  
G1 Z2.0 F3000 ;Move Z Axis up  
G1 X10.1 Y20 Z0.28 F5000.0 ;Move to start position  
G1 X10.1 Y200.0 Z0.28 F1500.0 E15 ;Draw the first line  
G1 X10.4 Y200.0 Z0.28 F5000.0 ;Move to side a little  
G1 X10.4 Y20 Z0.28 F1500.0 E30 ;Draw the second line  
G92 E0 ;Reset Extruder  
G1 Z2.0 F3000 ;Move Z Axis up

CURA

 ![001](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/7/734a4dd5ec33c9c91a956c6df6645cbb3e0d3bed.jpeg)

Add this code  
START\_PRINT EXTRUDER\_TEMP={first\_layer\_temperature[0]} BED\_TEMP={first\_layer\_bed\_temperature[0]}

---

<div class="post-metadata">

**Author:** ![EddyMI3D](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/eddymi3d/32/1981_2.png) [@EddyMI3D](https://klipper.discourse.group/u/EddyMI3D)\
**Post date:** [November 22, 2023, 6:55pm UTC](https://klipper.discourse.group/t/variables-for-heating-to-a-temperature/11784/3 "2023-11-22T18:55:07Z")

</div>

> [@ktb1228](#):
>
> every time I change filament to change the temperature.

That is a task for the slicer

---

<div class="post-metadata">

**Author:** ![ktb1228](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@ktb1228](https://klipper.discourse.group/u/ktb1228)\
**Post date:** [November 22, 2023, 10:54pm UTC](https://klipper.discourse.group/t/variables-for-heating-to-a-temperature/11784/4 "2023-11-22T22:54:46Z")

</div>

alright thanks, I am currently running a print but I will try this code after it finishes. This should save me a lot of time.

---

<div class="post-metadata">

**Author:** ![ktb1228](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@ktb1228](https://klipper.discourse.group/u/ktb1228)\
**Post date:** [November 22, 2023, 10:59pm UTC](https://klipper.discourse.group/t/variables-for-heating-to-a-temperature/11784/5 "2023-11-22T22:59:13Z")

</div>

Ideally the slicer should be able to do it but I have my start gcode in Klipper, if I try to put the exact same gcode into the slicer I run into weird errors and can’t start a print.

---

<div class="post-metadata">

**Author:** ![EddyMI3D](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/eddymi3d/32/1981_2.png) [@EddyMI3D](https://klipper.discourse.group/u/EddyMI3D)\
**Post date:** [November 23, 2023, 7:33am UTC](https://klipper.discourse.group/t/variables-for-heating-to-a-temperature/11784/6 "2023-11-23T07:33:26Z")

</div>

Usually you have temperature values for your filaments in the slicer (the good ones 😉 ).

Like here in OrcsSlicer:

 ![grafik](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/c/cb519b2d1e5c426d40c579863bf6d94f295979fb.png)

These values are passed on to the printer via the gcode file.

You don’t have to fiddle around in the printer.cfg for that.

And copying the start code from the slicer into Klipper is usually not a good idea. Changes have to be made.

And always keep in mind: Klipper macros can’t be interrupted/cancelled.

---

<div class="post-metadata">

**Author:** ![ktb1228](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@ktb1228](https://klipper.discourse.group/u/ktb1228)\
**Post date:** [November 23, 2023, 3:16pm UTC](https://klipper.discourse.group/t/variables-for-heating-to-a-temperature/11784/8 "2023-11-23T15:16:25Z")

</div>

this worked to correctly set the temperature but the heater immediately turns off after reaching the correct temperature

---

<div class="post-metadata">

**Author:** ![LifeOfBrian](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/lifeofbrian/32/2380_2.png) [@LifeOfBrian](https://klipper.discourse.group/u/LifeOfBrian)\
**Post date:** [November 23, 2023, 3:59pm UTC](https://klipper.discourse.group/t/variables-for-heating-to-a-temperature/11784/9 "2023-11-23T15:59:54Z")

</div>

Just slice a small model and upload the gcode file here.  
And paste the PRINT\_START macro as it is in your config and use Preformatted Text tags!

---

<div class="post-metadata">

**Author:** ![jfj39](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@jfj39](https://klipper.discourse.group/u/jfj39)\
**Post date:** [November 28, 2023, 10:21pm UTC](https://klipper.discourse.group/t/variables-for-heating-to-a-temperature/11784/10 "2023-11-28T22:21:16Z")

</div>

Same problem. the value of print temperature for filament in Cura 5.5.0 is not used. the temperature used is the temperature given in begining of printer.cfg for variable\_defaultTempNozzle  
So i must edit printer.cfg each time i change filament.  
Any idea ?  
Thanks in advance for any help

---

<div class="post-metadata">

**Author:** ![theophile](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/theophile/32/31_2.png) [@theophile](https://klipper.discourse.group/u/theophile)\
**Post date:** [November 29, 2023, 1:22am UTC](https://klipper.discourse.group/t/variables-for-heating-to-a-temperature/11784/11 "2023-11-29T01:22:23Z")

</div>

The answer is above. You need to configure your slicer correctly to make use of the custom macros you’re using.

---

<div class="post-metadata">

**Author:** ![ktb1228](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@ktb1228](https://klipper.discourse.group/u/ktb1228)\
**Post date:** [December 2, 2023, 3:16pm UTC](https://klipper.discourse.group/t/variables-for-heating-to-a-temperature/11784/12 "2023-12-02T15:16:05Z")

</div>

start gcode:

```auto
# Use absolute coordinates 
      G90 

      # Reset extruder 
      G92 E0

    {% set BED_TEMP = params.BED_TEMP|default(60)|float %}
  {% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(200)|float %}
  M190 S{BED_TEMP}
  
  G28 ;Home
  BED_MESH_CALIBRATE PROFILE="default"
  M109 S{EXTRUDER_TEMP}

    # Move Z axis up 
    G1 Z2.0 F3000 
    # Move to start position 
    G1 X10.1 Y20 Z0.28 F5000.0 
    # Draw the first line
    G1 X10.1 Y200.0 Z0.28 F1500.0 E15 
    # Move to the side
    G1 X10.4 Y200.0 Z0.28 F5000.0 
    # Draw the second line 
    G1 X10.4 Y20 Z0.28 F1500.0 E30 
    # Reset extruder 
    G92 E0
    G1 Z20

```

gcode file  
[cube.gcode](https://klipper.discourse.group/uploads/short-url/uvT7aYYTzNt7SKStjbc1GSHdMYp.gcode) (961.3 KB)

---

<div class="post-metadata">

**Author:** ![EddyMI3D](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/eddymi3d/32/1981_2.png) [@EddyMI3D](https://klipper.discourse.group/u/EddyMI3D)\
**Post date:** [April 15, 2024, 12:01pm UTC](https://klipper.discourse.group/t/variables-for-heating-to-a-temperature/11784/14 "2024-04-15T12:01:23Z")

</div>


