# Autoshutdown via button

**URL:** <https://klipper.discourse.group/t/autoshutdown-via-button/6864>\
**Category:** General Discussion\
**Created:** [February 24, 2023, 11:58am UTC](https://klipper.discourse.group/t/autoshutdown-via-button/6864 "2023-02-24T11:58:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![iLikeMilk3064](https://avatars.discourse-cdn.com/v4/letter/i/ed655f/32.png) [@iLikeMilk3064](https://klipper.discourse.group/u/iLikeMilk3064)\
**Post date:** [February 24, 2023, 11:58am UTC](https://klipper.discourse.group/t/autoshutdown-via-button/6864/1 "2023-02-24T11:58:20Z")

</div>

Hi guys,

is it possible to create a button query to shutdown the printer in the End-Gcode?  
So that the printer shuts down automatically if the latching button is pressed and if not the printer stays on.  
I know this is possible with the reprap firmware but I´m new to klipper and I didn´t find something similar to my problem.  
I hope you can help me.

Thank you and best regards  
Till

---

<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 24, 2023, 12:01pm UTC](https://klipper.discourse.group/t/autoshutdown-via-button/6864/2 "2023-02-24T12:01:32Z")

</div>

See [[FR] PSU ON/OFF trigger 🔌 · Issue #167 · Arksine/moonraker · GitHub](https://github.com/Arksine/moonraker/issues/167)

---

<div class="post-metadata">

**Author:** ![iLikeMilk3064](https://avatars.discourse-cdn.com/v4/letter/i/ed655f/32.png) [@iLikeMilk3064](https://klipper.discourse.group/u/iLikeMilk3064)\
**Post date:** [February 24, 2023, 1:19pm UTC](https://klipper.discourse.group/t/autoshutdown-via-button/6864/3 "2023-02-24T13:19:19Z")

</div>

Thanks that helped me to understand the PS\_On Pin, but how can I read the buttonstate in the gcode?

---

<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 24, 2023, 4:44pm UTC](https://klipper.discourse.group/t/autoshutdown-via-button/6864/4 "2023-02-24T16:44:46Z")

</div>

I’m not sure I understand you concept or what you want to do.  
One approach is:

In moonraker define:

```auto
[power printer]
type: gpio
pin: !gpiochip0/gpio14
off_when_shutdown: True
restart_klipper_when_powered: False
locked_while_printing: True
initial_state: off
on_when_job_queued: True

```

Or any other means to control the power, e.g. [Configuration - Moonraker](https://moonraker.readthedocs.io/en/latest/configuration/#tplink-smartplug-configuration)

In Klipper define:

```auto
[gcode_macro MY_GREAT_TURN_OFF_MACRO]
gcode:
    {action_call_remote_method('set_device_power',device='printer',state='off')}

```

In your end-print-gcode / macro then call:  
`MY_GREAT_TURN_OFF_MACRO`

Generally refer to [Moonraker](https://moonraker.readthedocs.io/en/latest/) for all available settings in moonraker and [Commands templates - Klipper documentation](https://www.klipper3d.org/Command_Templates.html) for an introduction to the Klipper macro system.

---

<div class="post-metadata">

**Author:** ![iLikeMilk3064](https://avatars.discourse-cdn.com/v4/letter/i/ed655f/32.png) [@iLikeMilk3064](https://klipper.discourse.group/u/iLikeMilk3064)\
**Post date:** [February 24, 2023, 5:48pm UTC](https://klipper.discourse.group/t/autoshutdown-via-button/6864/5 "2023-02-24T17:48:37Z")

</div>

Thanks for your help, I solved my problem.  
My plan was to shutdown my printer automatically if the blue button in the picture is pressed and if the button isn´t pressed the printer stays on after the print is finished.

 ![image](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/3/3a0f991d5a616ac99e50e17be0738038e196f207.jpeg)

I´m not sure if this is the best solution, but here is my code:

```auto
[gcode_macro _AUTOSHUTDOWN]
gcode:
 {% if printer["output_pin Autoshutdown"].value == 1 %}
 SET_PIN PIN=_RELAIS VALUE=1.00
 {% else %}
 SET_PIN PIN=_RELAIS VALUE=0.00
 {% endif %}

[gcode_button BUTTON_AUTOSHUTDOWN]
pin: ^!PE14
press_gcode: SET_PIN PIN=Autoshutdown VALUE=1.00
release_gcode: SET_PIN PIN=Autoshutdown VALUE=0.00

[output_pin Autoshutdown]
pin: PD15

[output_pin _RELAIS]
pin: pi:gpio23

```

After the print is finished I call the \_AUTOSHUTDOWN macro in my End-Gcode.  
I hope you understand my concept now.  
If you have a better idea to solve my concept let me know 😄

---

<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 25, 2026, 10:15am UTC](https://klipper.discourse.group/t/autoshutdown-via-button/6864/6 "2026-04-25T10:15:13Z")

</div>

Closed on April 25, 2026, 10:15am UTC


