Octoprint + Wemo

Ξ March 21st, 2016 | → | ∇ Uncategorized |

Since I setup Octoprint on my 3d printer I’ve wanted to find a way to turn the printer completely off (power stop) when a print had finished.  The scenario is when you’re on a long print and you’re not necessarily going to be in the same room when it finishes, but when it finishes you’d like it to turn off the printer when it’s done.  This keeps my mind at ease that nothing bad in the wiring should happen and the cooloff of the hotend is sure to occur when there’s no power to the printer.  It’s a Win-Win.  I’ve achieved just that and also have set up controls in the UI for turning the printer off and on.  I’ll tell you how to do it:

First of all, I’m assuming you’re using the amazing piece of software known as octoprint.  For my install I put it on a raspberry Pi 2, but it could be installed on any linux distro for this setup.  Next enters Wemo, the remote controlled outlet switch.  Belkin’s software for the mobile phone is terrible, but we’re only going to use that for a short while in order for it to get your wifi setup.  With a combination of the linux distro on your raspberry pi and a piece of software called “Ouimeaux,” we’ll get things automated.


It is pretty straight forward to setup your wemo.  Download the app, install, send the wifi credentials to the switch and you’re done.  That’s the easy part.  The next part is setting up the controller package on your raspberry pi.  First download the latest package of Ouimeaux on GitHub.  At the time or writing I installed 0.7.9.  It doesn’t take too much to setup and get it working correctly.  See this page for details.  To install you’ll untar/gzip the package on your pi and make sure you have python (required for octoprint anyway) and run the setup with elevated credentials.  Once you go through the setup process, check to see if you can find the switch by running the following commands in your shell:

//look for your device
wemo list
//check the status of your device
wemo status
//check the status of the specific device
wemo switch switchname status
//turn the switch on
wemo switch switchname on
//turn the switch off
wemo switch switchname off

If you’re not seeing the device, you might either need to connect up to it with the mobile app again or recycle the power.  It took a few times to be able to see it.  Also make sure you are connected to the same network with the wemo as your raspberry pi.

If all has gone well so far, there is only a bit left more which is the configuration in octoprint.  These changes will take place in the config.yaml file which is under the “.octoprint/” directory of the user that octoprint is running as (mine was  under /home/pi/.octoprint/).

We’re going to add new commands here so that we can tap into them via the GUI as well as a plugin.  Open your favorite editor and add in some new commands and actions like so:

    printerShutdownCommand: wemo switch printer off
    printerStartCommand: wemo switch printer on
    serverRestartCommand: sudo service octoprint restart
    systemRestartCommand: sudo shutdown -r now
    systemShutdownCommand: sudo shutdown -h now
  firstRun: false
  secretKey: REDACTED
  - action: shutdown
    async: true
    command: sudo shutdown -h now
    confirm: You are about to shutdown the system.
    ignore: true
    name: Shutdown
  - action: reboot
    async: true
    command: sudo shutdown -r now
    confirm: You are about to reboot the system
    ignore: true
    name: Reboot
  - action: restart
    async: true
    command: sudo service octoprint restart
    confirm: You are about to restart OctoPrint
    ignore: true
    name: Restart OctoPrint
  - action: printerShutdown
    async: true
    command: wemo switch printer off
    confirm: You are about to shutdown the printer.
    ignore: true
    name: Shutdown Printer
  - action: printerStart
    async: true
    command: wemo switch printer on
    confirm: You are about to start the printer.
    ignore: true
    name: Start Printer

Once we have that, let’s head on over to the octoprint plugin github and download the zip for the plugin “AutomaticShutdown“.  We’re going to tweak this plugin slightly in that we’re going to run a different system command when the print finishes.  Open up “octoprint_automaticshutdown\__init__.py” and change the following line:

def _shutdown_system(self):
		shutdown_command = self._settings.global_get(["server", "commands", "systemShutdownCommand"])

def _shutdown_system(self):
		shutdown_command = self._settings.global_get(["server", "commands", "printerShutdownCommand"])

You can also look in the other files to make edits to the labels if you want.  For instance I changed the js file included with the plugin to read out “shutdown printer” instead of system or the like.

That should be all you need in order to set this up.  Go ahead and reboot just the octoprint service and you should see the new sections in the UI:

3-21-2016 2-12-24 PM

3-21-2016 2-12-02 PM


Original post by m00ch


Leave a reply

  • Rumours and Lies