Use TPLink smart plug with Mainsail.

DEPRECATED
see link below:

Old tutorial below:

This is the one piece that I was really missing form Octoprint. The plugin that handled the TPLink wifi smart plug that my printer is connected to. In order to make this work, we need to use two GitHub Repos.

Get the IP of your smart plug

First, we are going to need to find the IP of your TP Link smart plug. The easiest way is to use the Fing app​
Before you plug your smart plug to the wall, do a first scan of your network with Fing. Then plug it into the wall, wait for it to turn on and connect and scan again. the extra IP that pops up is your plug! Note that IP for later...
The first one is https://github.com/softScheck/tplink-smartplug copy it to your Raspberry pi via SSH with:
cd ~
git clone https://github.com/softScheck/tplink-smartplug
(make sure you already have git installed otherwise do: sudo apt-get install git -y )

powermanager

Now let's install powermanager from https://github.com/Raabi91/powermanager​
cd ~
git clone https://github.com/Raabi91/powermanager
open the moonraker.config and put the power devices in it
cd
sudo nano /home/pi/moonraker.conf
put this at the end of the file.
[power Printername]
type: gpio
pin: gpio4
​
[power autoshutdown]
type: gpio
pin: gpio5
Old code from previous Moonraker version below
#[power]
#devices: printer, led
#printer_name: My Printer Name here
#printer_pin: 4
#printer_active_low: false
#led_name: Auto Shutdown
#led_pin: 5
#led_active_low: false
Rename the printer to whatever you want. Then Ctrl-X then Y then Enter to save.
Time to install powermanager
cd powermanager
sh ./scripts/install.sh
and edit powermanager's config.
sudo nano /home/pi/powermanager/config.sh
In the config change the two lines for printer_off and printer_on (line 5 and 7) to :
printer_off="/home/pi/tplink-smartplug/tplink_smartplug.py -t 192.168.1.XXX -c off"
...
printer_on="/home/pi/tplink-smartplug/tplink_smartplug.py -t 192.168.1.XXX -c on"
use your plug's IP that we noted earlier. Then Ctrl-X then Y then Enter to save.

Restart your Pi

Now you need to restart your Pi. You can do that in Mainsail by clicking HOST REBOOT in settings or via SSH with:
sudo reboot
You're done! You can now setup Klipper to reconnect when it detects the MCU being powered on by following my other tutorial:
​
​