Providing Macrofile: Optionally shutdown after printing

Hi *,

I have written some macro code that allows to shut down the printer after a print is completed. It can be dynamical set while printing. It’s rarely tested but what tested did work.
Follow the instructions at the end of the file.
If you want that the printer shutdowns after the print is complete run SET_COMPLETE_SHUTDOWN. If you want to unset it again run SET_COMPLETE_SHUTDOWN ENABLE=0

[gcode_macro SHUTDOWN]
variable_printer_active: 0
variable_wants_shutdown: 0
gcode:
  {action_call_remote_method("shutdown_machine")}

[gcode_macro CONDITIONAL_SHUTDOWN]
gcode:
  {% if printer["gcode_macro SHUTDOWN"].wants_shutdown == 1 %}
    SHOW_MSG MSG="Conditional shutdown wants shutdown, waiting for cooling down then i will shutdown"
    M140 S0 ; start heating the bed to what is set in Cura
    M104 S0 T0 ; start heating T0 to what is set in Cura
    TEMPERATURE_WAIT SENSOR="extruder" MAXIMUM=60
    SHUTDOWN
  {% endif %}

[gcode_macro GET_COMPLETE_SHUTDOWN]
gcode:
  {% set shutdown_wanted = printer["gcode_macro SHUTDOWN"].wants_shutdown %}
  SHOW_MSG MSG="Cmpl shutd: {shutdown_wanted}"

[gcode_macro SET_COMPLETE_SHUTDOWN]
gcode:
  {% set wants_shutdown = params.ENABLE|default(1)|int %}
  {% if wants_shutdown >= 1 %}
    {% set wants_shutdown = 1 %}
    SHOW_MSG MSG="print cmpl->shutdown"
  {% else %}
    SHOW_MSG MSG="print cmpl->stay on"
  {% endif %}
  SET_GCODE_VARIABLE MACRO=SHUTDOWN VARIABLE=wants_shutdown VALUE={wants_shutdown}

[gcode_macro SAFE_SHUTDOWN]
gcode:
  {% if printer_active == 0 %}
  SHOW_MSG MSG="Performing safe shutdown"
  SHUTDOWN
  {% else %}
  SHOW_MSG MSG="Job is active. No shutdown!"
  {% endif %}

[gcode_macro SHUTDOWN_HANDLER_START_PRINT]
gcode:
  SET_GCODE_VARIABLE MACRO=SHUTDOWN VARIABLE=printer_active VALUE=1

[gcode_macro SHUTDOWN_HANDLER_STOP_PRINT]
gcode:
  ; This needs to be at the end of your stop_gcode!!!!!!!
  SET_GCODE_VARIABLE MACRO=SHUTDOWN VARIABLE=printer_active VALUE=0
  CONDITIONAL_SHUTDOWN

[gcode_macro SHUTDOWN_HANDLER_CANCEL_PRINT]
gcode:
  SHUTDOWN_HANDLER_STOP_PRINT

[gcode_macro SHOW_MSG]
gcode:
  {% set MSG = params.MSG|default("No msg")|string %}
  M117 {MSG}
  RESPOND MSG={'"%s"' % MSG}

#TODO: AUTO SHUTDOWN POSSIBLY NOT WORK ON ERRORS!

#place the file shutdown.cfg into you config dir
#include this on the top of your printer.cfg
# [include shutdown.cfg]

#Call this in your start_gcode:
# SHUTDOWN_HANDLER_START_PRINT

#Call this AT THE END OF YOUR stop_gcode:
# SHUTDOWN_HANDLER_STOP_PRINT

#Call this in your cancel_gcode:
# SHUTDOWN_HANDLER_CANCEL_PRINT

#if non exists you can allways set one:
#[gcode_macro CANCEL_PRINT]
#rename_existing: CANCEL_PRINT_BASE
#gcode:
#  SHUTDOWN_HANDLER_CANCEL_PRINT
#  CANCEL_PRINT_BASE

Have fun!

1 Like

Added a menu:
This allows to turn on/off the “shutdown on complete” function. Additionally, you can see the current status on the display.
Until now everything works fine.

Follow the instructions at the end of the file.

Remember: I have a presetup system. And there are possibly missing some user instructions/dependencies for setup this functionality. If your have trouble or find some missing instructions, please post here. I will add it to these instructions, so other users will not have this trouble!

[menu __main __adv_shutdown]
type: list
name: Adv.Shutdown


[menu __main __adv_shutdown]
type: list
name: "Adv. Shutdown"

[menu __main __adv_shutdown __status_complete_shutdown]
type: command
name: "Autoshutd. {'off' if (printer["gcode_macro SHUTDOWN"].wants_shutdown == 0) else 'on'}"
gcode:


[menu __main __adv_shutdown __activate_complete_shutdown]
type: command
enable: {printer["gcode_macro SHUTDOWN"].wants_shutdown == 0}
name: "Shutd on cmpl"
gcode:
  SET_COMPLETE_SHUTDOWN
  {menu.back(True,True)}

[menu __main __adv_shutdown __deactivate_complete_shutdown]
type: command
enable: {printer["gcode_macro SHUTDOWN"].wants_shutdown == 1}
name: "Awake on cmpl"
gcode:
  SET_COMPLETE_SHUTDOWN ENABLE=0
  {menu.back(True,True)}

# name this file shutdown_menu.cfg and add it to your printer config dir.
# add this line to your printer.cfg:
#
# [include shutdown_menu.cfg]
# 
# Have fun