Controlling printer power from within OctoPrint

Good afternoon all.

I can't find an answer to this and I suspect it may not be easily achievable.

Being retired most of the time my printer is printing I am at home. There are occasions when after starting a lengthy print we decide to go out (or even get some sleep). At those times I am a bit reluctant to leave the printer operating unattended, particularly if it is likely to have finished printing and remain powered up for a long time before being attended again.

I have perused the plugins list and can't find what I'm looking for. I need a "power down" not "shutdown" plugin. I have bought some SonOff WiFi power switches that allow me to power down the printer using my mobile (cell) phone from within my home or across the internet. This works fine but I have to remember to keep checking on progress.


I would like to be able to tell OctoPrint to power down the printer when the current print finishes (or fails). I have seen @jneilliii's OctoPrint-Tasmota plugin that looks to do some of what I need but installing Tasmota to the device looks rather complicated.

It would be good to be able to select "Power down when print ends" after a print has started rather than having to remember to do it before starting the print.

Take a look at the PSU Control plugin:

Installed the PSU Control plugin and gave it a try. I can see the PSU icon on the menu bar and it is initially greyed out (off). On clicking the icon it goes green (on) but the printer remains in whatever state it was. I've tried having the printer initially powered on and the icon remains greyed out. Clicking "on" does nothing, clicking "off" prompts the "are you sure?" dialog but nothing happens.

The power can now only be toggled via the cell phone app when the printer's physical switch is on.

Flashing tasmota was not as difficult as you may think, but does require some additional tools like a USB programmer and soldering a header onto the board now since they removed the over the air hack that used to work, which was really simple.

Too much for me. I've just installed TPLink-SmartPlug plugin as that supports a device with an IP address. This was in the hope that it MIGHT work with SonOff. Unfortunately it doesn't. I've just order a TP-Link from Amazon as it was available on "Prime Day" so will try that tomorrow.

1 Like

Yeah, I was going to suggest that one.

If you're in retirement, Norman, why don't you clone another plugin and make it work with your new SonOff's?

Anyway, they're pictured next to an Amazon Echo so they may be compatible with the Kasa app as well as the Alexa app. (Look in Settings -> Smart Home -> Add Device.

If you can add it there, then you can power off the printer remotely with your cellphone.

It's good form, though, to shutdown OctoPrint/Raspbian first. If not, then backup your Raspberry once a month.

A little outside my sphere of competence unless you can point me to a simple guide. :grinning:

Yes they can be controlled with an Alexa skill but I couldn't see them when I tried the Kasa app.

Why would switching off the printer adversely affect the RasPi? After my other recent problem though I will be doing periodic SD card copies.

Yeah, that's a good approach too. There have been users from Australia if I remember correctly that even the TPLink plugin didn't work for. If you run into any issues with it let me know and I'd be happy to help.

Trust me, I worked for a 3D printer manufacturer and out of the 4,000 printers (OctoPi under the covers) I'm sure I generated 100 microSD images from trashed Raspbian partitions. That's a pretty good fail rate, if you ask me.

Doing the OctoPrint -> System -> Shutdown does exactly that behind-the-scenes, it kills the OctoPrint service (presumably shuts down the mjpg-streamer that's doing timelapse videos) and then does a sudo poweroff or similar. It's all good for the journaled ext4-formatted rootfs partition's health.

I don't think @Norman is looking to power off the pi abruptly, just the printer itself if I'm not mistaken. Powering off the printer remotely wouldn't adversely effect the pi at all. @Norman just needs to make sure that the pi isn't plugged into the same smart plug that the printer is.

Oh... my bad. My own Raspi is powered by the controller board in my printer so... I badly assumed there.

Yeah, totally. See if the Alexa app can see it under Settings -> Smart Home.

You may come to regret offering that. :grin:

I had forgotten that some people obtain the power for their Raspis from the printer's power supply. You mentioned the command sudo poweroff. I wasn't aware of that, I usually do a sudo shutdown now then pull the power lead. I often wondered if there was a more elegant solution.

The TPLink hasn't arrived yet so I haven't started my testing but I'm guessing that I will still need to find a way to activate the plugin when the print ends or fails. It would be nice to have the option to have a toggle that could be selected at some point after starting a lengthy print. In other words - "I'm off to be now - turn yourself off when you're finished". :sunglasses:

My plugin in combination with OctoPrint-ShutdownPrinter plugin will meet your needs. In all honesty, if someone reverse engineered the communication between the Sonoff/Kasa then you could use the ShutdownPrinter plugin and it's custom api methods.

@jneilliii many thanks. My TP-Link plug only just arrived and I've added it to Kasa which works as expected. I then add the IP address to your TP-Link plugin and to the ShutdownPrinter plugin and that combination does work with one caveat. I can switch the power on to the printer with the power button on the top bar. That turns the icon from red to green but quickly goes red again. If I press the button when the icon is red nothing happens except the icon goes green. It's only if I press the button when the icon is green will the printer power down after a warning.

I'm not able to test the "Shutdown after print finishes" as I'm waiting for a few parts for the printer. I'm wondering whether I can check the box at some stage after a print has started and have the printer shut down at the end. I note that you can "remember" the last setting of the control.

Sometimes there is a timing issue on the color swap and the status gets out of sync from what's stored in settings. If you restart octoprint and wait until everything is loaded up and then press the button that usually helps. There's also the polling option, which also helps with getting everything in sync.

Now tested and works as I'd hoped. Put a check in the box some time after I started a print and the printer powered down when it finished.


All the Sonoff relays work. Just solder on the headers and flash with ESpurna firmware. You can then write a simple python script to call a HTTP command which the ESpurna firmware can accept. I use PSU control addon in octoprint to access the python script.

The Sonoff relays are ridiculously cheap and very well built as a few electrical engineer youtubers have done some teardowns and commented.

For using this plug, without Tasmota, but "just" adding Octoprint awareness to the plug's firmware see: The exmaple is for a Sonoff S26, but other Sonoff work fine as well, just define the correct pin numbers for relay / LED and switch.

A neat way of doing it is something I'm going to do on my home-build printer when I get the mechanics working properly. The Pi and screen are powered from the 12V supply using a 3Amp 5V BEC (battery eliminator circuit) usually used for radio control models, and which can be found for about Β£3 on ebay.

I'm using a 12V ATX power supply from a Fujitsu business PC which can be found for peanuts from PC recyclers (or, in my case, the scrap bin at work). On an ATX supply, there's a green wire which turns the supply on when connected to 0V.

If you put a switch between that green wire and 0V, the switch will turn the supply on and off.

If you put a normally-open relay in parallel with the switch, if EITHER the switch or the relay is closed, the power supply will fire up.

So for this purpose, I'll be picking up a 5V pin on the Pi's GPIO and a 0v pin >> to the energise pins of the relay so that when the Pi is on, the relay is always closed and the power supply is kept live.

The manual switch will be a momentary push switch, so that you hold that switch closed for a second or two, the power supply fires up, the Pi fires up and energises the relay and then you can let go of the switch.

When the Pi powers down, the relay opens and the supply powers down automatically.

This was the original purpose of the PSU Control plugin. It's designed to work with ATX power supply and that green line..