Shutdown command to the raspberry

Hello!
It is possible to send a shutdown command to the raspberry via printer LCD menu?

Due to security concerns, Klipper is not able to execute shell commands.

This limitation makes perfect sense but you can work around it with Octoprints Action Commands plugin.

  1. Enable Respond: klipper/Config_Reference.md at master · KevinOConnor/klipper · GitHub
  2. Create a menu with something like
[menu __octoprint __poweroff]
type: command
enable: !toolhead.is_printing
name: Turn off Pi
gcode:
    {action_respond_info('action:poweroff')}
  1. Enable sudo without password in Ubuntu/Debian | PHPraxis - PHP and more → limit to /sbin/shutdown or any other command you might want to call
  2. Catch the poweroff in the Octoprint plugin and have it invoke sudo /sbin/shutdown

In case of Moonraker cooperation (instead of Octoprint), it is possible to make something like:

[menu __main __poweroff]
type: command
enable: {printer.idle_timeout.state != "Printing"}
name: Turn off Pi
gcode:
        {action_call_remote_method("shutdown_machine")}

Because Moonraker registers remote methods “shutdown_machine” and “reboot_machine”.

It works, although I am not able to replace content of display by e.g. “Shutdown” (original menu stays there).

1 Like

Maybe

[delayed_gcode shutdown_machine]
gcode:
     {action_call_remote_method("shutdown_machine")}
initial_duration: 0.0
[menu __main __poweroff]
type: command
enable: {printer.idle_timeout.state != "Printing"}
name: Turn off Pi
gcode:
     M117 Shutdown_RPI
     M118 Shutdown_RPI
     { menu.exit() }    
     UPDATE_DELAYED_GCODE ID=shutdown_machine DURATION=1 
2 Likes

This was the missing line which I needed, thank you :-).

Works flawlessly, Thanks Master.

I have two question tho.

  • Is the delayed_gcode a macro
  • Why send M117 and M118

M117 send message “Shutdown_RPI” to the LCD screen.
M118 Send message “Shutdown_RPI” (respond) to host.
Delayed gcode macro gives time output message to the LCD screen.

This is really great to know! I went looking, and it wasn’t obvious what remote methods moonraker registers with Klipper. Is there some documentation for these things that I missed?

I have no idea. I found it in klippy.log:

pi@ratos:~/Logs $ grep webhooks: klippy.log
webhooks: registering remote method 'shutdown_machine' for connection id: 3042581960
webhooks: registering remote method 'reboot_machine' for connection id: 3042581960
webhooks: registering remote method 'pause_job_queue' for connection id: 3042581960
webhooks: registering remote method 'start_job_queue' for connection id: 3042581960

Moonrakers “readthedocs.io” found nothing (quite typical, I’ve never had success with searching in this type of Docs) : https://moonraker.readthedocs.io/en/latest/search.html?q=shutdown_machine