Controlling printer power from within OctoPrint


#1

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.

SL500

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.


#2

Take a look at the PSU Control plugin:


#3

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.


#4

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.


#5

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.


#6

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.


#7

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.


#8

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.


#9

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.


#10

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.


#11

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.


#12

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:


#13

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.


#14

@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.


#15

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.


#16

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.


#17

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.