Octoprint has a plugin to toggle a GPIO pin in order to power the 3D Printer on/off. The Alunar printer that I have is powered by a 12V power supply and will be powered on/off by interrupting that 12V power.
I have now finally got around to actually installing my little mod. It seems to function just fine! The relay gets a little warm, I measured it with the thermocouple on my multimeter and it got to around 40C but it seems to be working just fine. Currently running a test print to see if anything goes wrong but so far so good!
Now that I have a circuit board for the project, what better to do than use the 3D printer to print an enclosure for its own accessory? I designed a box with cutouts for wiring and a lid in solidworks and 3D printed it.
I will probably end up gluing the board down to the box. Solidworks parts files will be available to download. Please note that some changes might need to be made to get everything to fit together. I designed assuming ideal conditions and ended up having to make the box a little larger (by 0.4mm at the most) in order for the lid to fit on. In its current state, the lid friction fits very firmly in place. Depending on how you construct your board, you might also need to change the spacing of the wiring cutouts.
Now that I've verified that the circuit works on a breadboard, I assembled it on a more permanent protoboard. The soldering isn't the dick, but they're solid joints and it works as intended. I made a mistake when planning and purchasing parts and didn't think about the fact that the board will need to connect to both the Raspberry Pi's GPIO ground as well as the ground from the printer's power supply. This means I would have needed a 3-pin terminal block instead of a 2-pin. I just used 2x2-pin terminal blocks and left one pin unconnected.
Quickly mocked up the circuit on a breadboard to verify its operation. Octoprint's PSU Control plugin is set to toggle Pin 8 (Physical pin, not GPIO 8) for power control. The circuit did perform as intended. The coil draws 15mA when energized which leaves our little TO-92 transistor only dissipating 18mW, well within its 350mW limit.
Everything is currently designed schematic-wise and all the parts are purchased/available. The only worry I have is that if the printer draws more than 5A of current, the relays I have are woefully inadequate. I'm using Omron 12V 5A relays for switching. I guess I'll find out depending on if the relay contacts get welded together or not!