Trick #26: How to control the TP Link plugin

A lot of users requested me the support of the TP Link Smartplug plugin in Printoid.

That’s possible natively with Printoid since the v9.09 (02/14/2018).

1/ With Printoid PREMIUM

There is a direct integration of the TP Link Smartplug plugin for the PREMIUM users only.

If the TP Link plugin is installed on your OctoPrint server, you will get a new entry in the left side menu. But first, you need to provide the TP Link device LAN IP address to Printoid is the app settings (in the plugin category).

Please note that it is mandatory to provide the IP address of your TP Link device because the plugin needs to know which TP Link device should be controlled over the API call.

The TP Link Smartplug plugin support is not compatible with the PSU Control plugin. If you wanna use the TP Link Smartplug plugin in Printoid, you need to uninstall the PSU Control plugin from OctoPrint first.

The actual TP Link state is indicated in the icon and the label. Simply click on this entry to toggle the TP Link state.

Of course, a warning dialog will protect this feature.

2/ With Printoid PRO

You can control the PSU plugin from Printoid PRO by using the custom HTTP commands from the Commands Panel.

According to the code of the TP Link Smartplug plugin, here are the helpful APIs. Please note that each command need the IP address.

turnOn
Turn the TP Link power supply on.

turnOff
Turn the TP Link power supply off.

checkStatus
Get the current on/off state of the TP Link. Returns currentState (string) to “on”, “off” or “unknown”.

cURL Examples

curl -s -H "Content-Type: application/json" -H "X-Api-Key:
YOUR_API_KEY" -X POST -d '{ "command":"turnOn", "ip":"xxx.xxx.xx.xx" }'
http://YOUR_OCTOPRINT_SERVER/api/plugin/tplinksmartplug

curl -s -H "Content-Type: application/json" -H "X-Api-Key:
YOUR_API_KEY" -X POST -d '{ "command":"turnOff", "ip":"xxx.xxx.xx.xx" }'
http://YOUR_OCTOPRINT_SERVER/api/plugin/tplinksmartplug

curl -s -H "Content-Type: application/json" -H "X-Api-Key:
YOUR_API_KEY" -X POST -d '{ "command":"checkStatus", "ip":"xxx.xxx.xx.xx" }'
http://YOUR_OCTOPRINT_SERVER/api/plugin/tplinksmartplug

For example, if you wanna create a new command “Switch TP Link On” in Printoid:

curl -s -H "Content-Type: application/json" -H "X-Api-Key:
YOUR_API_KEY" -X POST -d '{ "command":"turnOn", "ip":"xxx.xxx.xx.xx" }'
http://YOUR_OCTOPRINT_SERVER/api/plugin/tplinksmartplug

Then, in Printoid:

  1. Create a new command and select “HTTP (cURL-like)”
  2. /api/plugin/tplinksmartplug should be add to the command as the “command”
  3. POST should be selected as the HTTP method
  4. '{ "command":"turnOn", "ip":"xxx.xxx.xx.xx" }' should be added to the command as the “argument” (don’t forget to replace  the IP by your own TP Link device LAN IP address, of course!)

3/ Special thanks

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s