Safely shutting down / power off the printer and Octoprint itself

My Pi is powered from the PSU of the printer, with a step-down convertor. Flipping the printer switch means power-off from the Octoprint server as well.

I was looking for a safe and convenient way to accomplish power-off. We have plugins that use Tasmota / ESPhome Sonoff plugs to shutdown the Printer/Octoprint safely. I went a different route: I built all the logic straight into the ESP8266 in the plug!

This means that no plugins, special GCODE or configuration is needed in Octoprint. The plug monitors print state, temperature and initiates a shutdown of Octoprint with delayed power-off, when you press the plug button, or when you tell it to do so after a print.

Becuase it is not a plugin, I called it a "plugout"... So OctoPlugout was born.

It is described here: https://github.com/ruedli/OctoPlugout

5 Likes

Hi, I just tried your 'OctoPlugOut' under platformIO, it needed a bit of tweaking to get it to compile but with those tweaks it compiled and loaded onto an ESP8266 just fine. I haven't had time to try it with Octoprint / OctoPi but I have no doubt it will work and be a very useful addon.
I congratulate you on on an innovative project. I don't know if there is a suitable Sonoff plug for UK 13A socket outlets but it would probably be as easy, if not easier, to build a Wemos mini controlled relay for the power side in a small box. I'll try it when I get change and let you know how I get on.

2 Likes

@bobcroft Thanks for your kind words and positive feedback!

Indeed it does not need to be a Sonoff, any ESP8266 works, and my first development was on a ESP32. The Sonoff S26 is what I used and also comes in a UK plug variant, however it is rated for 10A / 2200W. Not 13A, like you required, allthough 10A might also be enough for your printing needs? In fact, if you really need to power more then 2200W, you could perhaps use 2 for the different power users?

The reason I like the Sonoff, but also Wemos, is that there is minimal tinkering needed with 220V. Further with the wireless connection there is no soldering to the Pi needed.

Can you share the platform.io file you used for the ESP8266? I assume it is a oneliner with the correct chip? EPS8266EX?

The term 13A is the normal way to describe 240 VAC power outlet sockets in the UK, I didn't mean to imply that all controls applications require the maximum current. My personal view is that Sonoff frequently over rate their products and often the numbers do not add up either if one considers the relationship of amps, volts and watts. When asked I frequently suggest people should down rate the stated amps of the Sonoff. However, I doubt a 3D printer draws anywhere near 10A.
I completely agree about tinkering with mains voltages and not soldering to the RPi so wireless is an excellent solution. For my part I am electrically qualified so I can do the mains voltage part safely.
I will share the platformIO set up once I have clarified a point with the API designer because at present there is an issue with that library. I resolved it but I would prefer to use the stock platformIO library installation process. I also need to do some work on the OTA as it wasn't playing nicely and I have used OTA extensively. OTA is probably easier to use under platformIO then the Arduino IDE.

1 Like

Yes, I noticed that Stephen's API is updated in his github (he implemented my pull request for the shutdown that I needed and wrote), but e.g. the Arduino IDE is not yet reflecting that update. So is it similar for the Platformio framework?

And yes, my meanwell PSU is rated 350W, so I even doubt is goes over 5A. The relays in these plugs are tiny, so 10A might be overdoing it. We are lucky with 220 / 240 V, the US 'people have to take care of switching bigger currents!

And yes: electrical engineer as well on this side :wink:

On the good side: when I switch it off the relay, the heatbed and extruder are not drawing any current and the Pi is shutdown, so the current you switch is tiny, compared to what you use while heating up everything (and printing, to a lesser degree).

Hi Ruud,

Just an update, today I have spoken to Stephen the author of the octoPrintAPI and hopefully he can update the library as necessary. Unfortunately I do not know how to do that myself and so I can’t help him. If nothing is sorted in a few days I’ll share with you how I got it working. It isn’t difficult just not as clean as using the PIO library install.

Bob

That is excellent news, thanks for looking into this, I did not have these problems because I was using the IDE with a directly from github installed plugin and not platformio.

I understood that the library that the Arduino IDE provides for download has the same issue. This needs some cleanup as well.

In the meantime I made the integration even more seamless and intuitive. Currently it will no longer trigger a "shutdown/poweroff" if the print job is very short, or when the extruder never got to extruding temperature. You configure what is hot and what is short.

Further I send messages from the plug, that are shown on your printer LCD. The "blinking" LEDS now make even more sense...

Hi Ruud, Stephen has updated the octoPrintApi library and it now loads perfectly into platformIO and octoPlugOut compiles with a few tweaks. It loads onto a Wemos D1 mini by OTA and runs perfectly. I tested it with Octoprint on a RPi 3B and it worked correctly.
It you wish I can can put your latest version onto a platformIO file for you.
how can I sent the platformIO files to you!

I have just sent email with zipped files for v2.1

If you have platformIO installed there should be a folder under documents called platformIO, under that is a folder called projects, put the unzipped folder I sent you called 'plugout' under projects. Open platform IO and under files click 'open workspace', browse to documents/platformIO/projects/plugout/src and there you will see the workspace file, double click on it and it should open up the project workspace with all the required directories.

Just completing the discussion on this thread: With the help of Bob, I have updated the directory structure for OctoPlugout in v2.3. If you download the files from github, you can choose whether you use platformIO or just open the sketch in the Arduino IDE. Both compile and allow updates OTA as well as over the serial interface.