Run gcode before shutdown

What is the problem?

I need to be able to run cool down gcode commands before shutdown is initiated.
M140 20 Bed cool down
M109 R50 Wait until hotend cools down to 50

run these before

Specifically, hitting shutdown from Octoprint, wait to cool before shutdown.

What did you already try to solve it?

Tried a couple of different event manager settings to no avail.

Have you tried running in safe mode?


Did running in safe mode solve the problem?


Systeminfo Bundle


Additional information about your setup

Highly modded Anet A6, with pc ps - RPi control, SONOFF S31 Lite Smart Plug wired to gpio, modified Marlin firmware, 2 cams, Text and email notification, custom fans and lighting, solid state x,y,z stop and runout switch.

cmd exec
Gcode system commands
GPIO control
Marlin Slider plugin

Most simple way is to put these lines

either at the end of the end gcode in your slicer or in the
After print job completes slot in the OctoPrint GCODEscripts

That's if I am running a print, I have that already.

I need it before I shutdown via octoprint.

Note: I did try in the "Before serial connection to printer is closed".

1 Like

Does your printers firmware support action commands?

I found what I am looking for thanks to our fearless developer;


1 Like

I don't know... lol But thank you for your input. That's how I found the answer.

I would think that shutdown event in event manager would work, but I suppose that the serial connection is killed prior to the commands being sent. Which makes me think the GCODE Scripts for "Before serial connection to printer is closed" would have worked, but that might only be triggered if you click disconnect from the UI.

You are correct. That's what I thought too...


Glad you found a solution

My idea was a small gcode file with you commands and then the shot down host action command.

If you print this file it would send the commands to the printer and shut the pi down afterwards.

Obviously that's just a workaround and it's better to have a correct solution