Introduction: Power On/Off 3D Priner W/ OctoPrint and SmartSwitch
This is a simple guide which well help you setup a WEMO Insight Switch, $50 on Amazon http://amzn.to/26qdS91, (or any other WEMO Switch) controlled via OctoPrint's system menu to power your plugged in printer on or off.
The benefit of using the Wemo Insight switch is you get power usage reporting and direct control (more on this later)
Although this guide's for power cycling a printer, it could also be for LEDs or anything else you can plug into a smart switch. (I'm going to setup an LED switch in the future)
If you have something like the Samsung SmartThings SmartSwitch, http://amzn.to/1Wn7FGd, they don't allow direct API calls, easily that is, so the easy setup is using the IFTTT maker channel, https://ifttt.com/maker. In this case, you'd setup SystemEditor's command to CURL the maker channel a particular event. That event, would in turn signal your SmartThings Switch. Note that there is a delay here since IFTTT doesn't check every second. Hence the reason I went with the WEMO, for that immediate access.
Even simpler, but not covered here as it involves connecting to the PI's GPIOs is an enclosed Relay: http://amzn.to/1SKOSVU. This would allow you immediate power switching with a direct signal from the PI's GPIO using the GPIO cmd line tool. (I may do this later to simplify the setup. Downside is it requires the PI to be on, and offers no other software way other than in the PI to power off the machine.
Step 1: SSH to OctoPrint
Start off by SSH'ing to your octoprint host. You can try the default firstname.lastname@example.org. If this doesn't work, substitute the octopi.local for IP address.
Step 2: Create/Edit the Script
use nano to create/edit the file we're calling wemocontrol.sh
Step 3: Copy the Script
Copy the Wemo Control script from http://wemo.forumatic.com/viewtopic.php?t=5&p=5 and paste it into nano.
You could use just the CURL command here directly, but it's may more complicated and using this script makes interfacing with the wemo much easier!
Press ctrl+x to exit, then y to save and hit enter.
Now run: chmod a+x wemo_control.sh to make the script executable.
Before moving on to the next part. You need to find your WEMO's IP on your network. I did this by going to my routers attached devices list. Then one by one issuing the on command noted below to each IP, till I saw the printer turn on.
Now you can test the script with: ./wemo_control.sh [IP] GETSTATE
If that works you should see an ON/OFF state. Then replace the GETSTATE above with ON or OFF to test via command line.
Step 4: Download System Editor Plugin
Download the System Editor plugin from the OctoPi repo: http://plugins.octoprint.org/plugins/systemcomman... Optionally install Editor Collection for a cleaner admin interface: http://plugins.octoprint.org/plugins/systemcomman...
Note that you can add/and should add the plugin directly from OctoPrint's plugin manager. You will likely have to restart OctoPrint for the plugin to show. SO DON'T DO THIS DURING A PRINT!
Step 5: Create the OctoPrint System Command
Take the command from step 3 and enter it here for a "Printer On" and "Printer Off" commands. You can use the confirmation message on the off command as a safety measure so you don't accidentally power off the printer.
Step 6: Test Via OctoPrint
You should now see the power on and off options in octoprint's system menu. Give them a try and you should see a confirmation like the screenshots.