Autoshutdown via button

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

See [FR] PSU ON/OFF trigger 🔌 · Issue #167 · Arksine/moonraker · GitHub

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

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

In moonraker define:

[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

In Klipper define:

[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 for all available settings in moonraker and Commands templates - Klipper documentation for an introduction to the Klipper macro system.

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.

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

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