# Variables for \[save\_z\_home\]

**URL:** <https://klipper.discourse.group/t/variables-for-save-z-home/6706>\
**Category:** General Discussion\
**Created:** [February 16, 2023, 8:46pm UTC](https://klipper.discourse.group/t/variables-for-save-z-home/6706 "2023-02-16T20:46:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SNX](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@SNX](https://klipper.discourse.group/u/SNX)\
**Post date:** [February 16, 2023, 8:46pm UTC](https://klipper.discourse.group/t/variables-for-save-z-home/6706/1 "2023-02-16T20:46:27Z")

</div>

### Basic Information:

Printer Model: Ender 5 Plus  
 MCU / Printerboard: BTT Mini e3 V3

### Describe your issue:

Does anyone know if it is possible to take values from (exp. [stepper\_x]…) and calculate a coordinate?  
I tried the following:

[safe\_z\_home]

#{% set save\_x = printer.configfile.settings[“stepper\_x”].position\_max %}  
#{% set save\_y = printer.configfile.settings[“stepper\_y”].position\_max %}

#{% set save\_x = printer.configfile.config[“stepper\_x”][“position\_max”]|float / 2 %}  
#{% set save\_y = printer.configfile.config[“stepper\_y”][“position\_max”]|float / 2 %}

#{% set save\_x = printer.configfile.settings[“stepper\_x”][“position\_max”]|float / 2 %}  
#{% set save\_y = printer.configfile.settings[“stepper\_y”][“position\_max”]|float / 2 %}

home\_xy\_position: 177.5,177.5 #{save\_x},{save\_y}  
speed: 200  
z\_hop: 10  
z\_hop\_speed: 100

(all commented out because actually i had to print something)

Thx in advance…

---

<div class="post-metadata">

**Author:** ![Sineos](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/sineos/32/18_2.png) [@Sineos](https://klipper.discourse.group/u/Sineos)\
**Post date:** [February 17, 2023, 9:24am UTC](https://klipper.discourse.group/t/variables-for-save-z-home/6706/2 "2023-02-17T09:24:44Z")

</div>

You need to use:

```auto
    {% set bed_x_max = printer.configfile.settings.stepper_x.position_max %}

```

`[safe_z_home]` is not the right place for such. Use `[homing_override]` for such.

---

<div class="post-metadata">

**Author:** ![SNX](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@SNX](https://klipper.discourse.group/u/SNX)\
**Post date:** [February 17, 2023, 9:47am UTC](https://klipper.discourse.group/t/variables-for-save-z-home/6706/3 "2023-02-17T09:47:43Z")

</div>

> [@Sineos](#):
>
> `{% set bed_x_max = printer.configfile.settings.stepper_x.position_max %}`

Thanks for your Help.  
But i think i dont really understand. Why cant (or shouldnt) i use it in this section?  
I tried to use it in save\_z\_home and the setting of the variable now seems to work, but there seems to be an error when reading this value.  
Error:  
Unable to parse option ‘home\_xy\_position’ in section ‘safe\_z\_home’

I tried bed\_x\_max,bed\_y\_max and {bed\_x\_max},{bed\_y\_max}

---

<div class="post-metadata">

**Author:** ![Sineos](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/sineos/32/18_2.png) [@Sineos](https://klipper.discourse.group/u/Sineos)\
**Post date:** [February 17, 2023, 9:52am UTC](https://klipper.discourse.group/t/variables-for-save-z-home/6706/4 "2023-02-17T09:52:01Z")

</div>

> [@SNX](#):
>
> Why cant (or shouldnt) i use it in this section?

Because `[safe_z_home]` is an internal definition that is not meant to extended via macros. For this flexibility `[homing_override]` offers the needed means.

---

<div class="post-metadata">

**Author:** ![SNX](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@SNX](https://klipper.discourse.group/u/SNX)\
**Post date:** [February 17, 2023, 10:24am UTC](https://klipper.discourse.group/t/variables-for-save-z-home/6706/5 "2023-02-17T10:24:07Z")

</div>

> [@Sineos](#):
>
> is not meant to extended via macros

means you CAN or SHOULD not?

I think i should tell you the Reason for this…  
I often change the complete Toolhead. So everytime the Size and Positions do change.  
I try to use only one variable at start of the printer.cfg for all the pendencies, so that everything will be calculated over this variable.  
the savehome section was just the beginning.  
Also i would use it in  
[screws\_tilt\_adjust]  
[bed\_mesh]  
[stepper\_x] position\_endstop: 338  
[stepper\_y] position\_endstop: 330  
and as i said  
[safe\_z\_home]…

---

<div class="post-metadata">

**Author:** ![Sineos](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/sineos/32/18_2.png) [@Sineos](https://klipper.discourse.group/u/Sineos)\
**Post date:** [February 17, 2023, 12:16pm UTC](https://klipper.discourse.group/t/variables-for-save-z-home/6706/6 "2023-02-17T12:16:10Z")

</div>

> [@SNX](#):
>
> means you CAN or SHOULD not?

Cannot. Only settings that offer a `gcode` block can be amended with macros.

---

<div class="post-metadata">

**Author:** ![SNX](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@SNX](https://klipper.discourse.group/u/SNX)\
**Post date:** [February 17, 2023, 1:36pm UTC](https://klipper.discourse.group/t/variables-for-save-z-home/6706/7 "2023-02-17T13:36:37Z")

</div>

Ich sehe grade in deinem Profil das du aus D kommst…  
Ich bin mal so frei die Sprache zu wechseln da mir das englisch recht schwer fällt.

Ok, also geht nicht weil geht nicht. Soweit ok…  
Das mit dem Homing Override ist mir nicht ganz klar… was ist das und wie wende ich das an? Bzw könnte das u.U. eine Gesamtlösung werden?

Ok, ich habe mir das mit dem Override mal zu Gemüte geführt.  
Das scheint nicht der Weg zu meinem Ziel zu sein.

Trotzdem erstmal vielen Dank für deine Hilfe.

---

<div class="post-metadata">

**Author:** ![Sineos](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/sineos/32/18_2.png) [@Sineos](https://klipper.discourse.group/u/Sineos)\
**Post date:** [February 17, 2023, 3:08pm UTC](https://klipper.discourse.group/t/variables-for-save-z-home/6706/8 "2023-02-17T15:08:02Z")

</div>

> [@SNX](#):
>
> Ich sehe grade in deinem Profil das du aus D kommst…

Sorry, but this an English speaking forum and other readers shall have the chance to participate as well.

Effectively you can do a lot with macros and as far as my understanding of your concept goes, this should be possible but requires quite some macro understanding and work.

You might want to have a look at various existing macros and at the macro tutorial to get an idea how to work with variables etc.  
See especially the [Macros - Klipper](https://klipper.discourse.group/c/macros/8) category and the excellent macro tutorial [Macro Creation Tutorial - #22 by Mard0](https://klipper.discourse.group/t/macro-creation-tutorial/30/22)  
Also a lot of inspiration can be obtained from [GitHub - zellneralex/klipper\_config: This is the config of my Voron 2.4 350mm3 Serial:V2.660](https://github.com/zellneralex/klipper_config)

`homing_override` is described here [Configuration reference - Klipper documentation](https://www.klipper3d.org/Config_Reference.html#homing_override)  
In the `gcode` block you can customize homing with macros
