Support for Smart Plug commands like TP-LINK (either directly or via HTTP POST request)


I have my printer setup hooked up to a TP-LINK smartplug which i use to power of the printer after successfull prints. As the current repetier-server does not support sending event based commands (or HTTP requests) i have it working but its a bit fussy and ideally i would love to have a more direct solution out of the repetier-server if possible.

Basically atm it works like this: If a print is completed i get a notification on the repetier infoermer app on android. I then use Automagic app to trigger a HTTP POST request to my TP-LINK smartplug to switch it off.

Ideally i would love to have such a feature (either TP-LINK support or HTTP requests) from within Repetier-Server to issue this command directly without having to resort to my above method which is prone to possible issues (if the phone is off etc).

Octoprint for instance has a dedicated plugin for the TP-LINK smartplug ( which has the option to issue the on/off command triggered by GCODE M80 ip address / M81 ip address. 

Either solution would be fine for me if possible.



  • That would only make sense for us if we can support all smart links and own them for testing.

    None th eless, it is not impossible. That is what the extcommands.xml file is for, please read manual for details. This allows you to add menu entries in printer menu to execute on your pc. It also allows starting a script with @execute server command. So you can even add it in your end event script. Only thing you need to consider is that printer might not be finished when this command gets executed. Typical solution is to add 30 M400 before the @execute line then so printer is finished with everything before that line. The called script should none the less add a 5s pause before turning off power so server can cleanly finish job before printer disconnects.
  • Yes i understand that such a development would only make sense if it would be more widely applicable.

    I also though about the extcommands.xml solution but honestly the documentation on how exactly that works is a bit sparse for me. I am not a linux or python guru so writing a script that creates json or http post commands from scratch is a bit beyond my knowledg. I usually reverse engineer such things if they have been developed for similar purposes and make my own adjustments but i don't know how to write something like this from scratch.
  • If you know the http post command the script is quite easy if you use curl to send it.

    sleep 5
    curl .....

    thats it. Just needs to check curl syntax. Extcommands is just calling the script file then. Only make sure the user repetierserver is allowed to execute it.
  • Hi,

    I have managed to get a script ( that works if i run it manually from ssh. I have added the following command to extcommands but it does not trigger the script no matter if i use it with @execute TPLINKOFF in the event based gcode tab or if i try to run it directly from the menu. What am i missing?

    <execute>sudo /home/pi/ 9999 off</execute>
  • I have also tryed with following format:

    <execute>./ 9999 off</execute>
  • I did some more experimenting. So executing from menu now works however it does not seem to work from event based GCODE (@execute TPLINKOFF).

    <confirm>Really turn off TP Link Plug?</confirm>
    <execute>/home/pi/ 9999 off</execute>
  • Try to make a script without parameter. That might help with the @execute command. Also note that for execute there is a separate section in extcommands. <command> is only for the menu.
  • Thanks for the tip. I didn't even notice the seperate section in extcommands for execute :P Now that you mentioned it i set it up and it works from GCODE command.
  • Everything works fine now. I have added a 5 minute sleep into the script so that the printer has sufficient time to finish enything and everything like converting the timelapses etc before being shut down. It all works flawlessly now.

    Thanks again for your support and tips!
  • Everything works fine now. I have added a 5 minute sleep into the script so that the printer has sufficient time to finish enything and everything like converting the timelapses etc before being shut down. It all works flawlessly now.

    Thanks again for your support and tips!
    hi there,
    plz tell me more about your work. i would like to switch off my printer also with a hs100.
  • Yeah me too :) Freakadude can you explain how you did that? Thanks in advance
  • Right. So i found the script to this online (don't remember where anymore) so i am not taking any credit for that.
    But in essence with setting a few parameters with that script you can tell your switch to turn on or off. You then build it into repetier server either as a switch or to be triggered with an @execute command using the event dependant g-code settings.

    So what you need to do is following:

    1. Download the script ( i put it up on dropbox here: ). Check the script as it has some instructions in it on how to use it. Basically you run it with passing 3 parameters and then it does its thing.

    2. Copy the script onto your RPI or whatever you are running your repetier server on into a folder.

    3. Open and edit your extcommands.xml file on your repetier server. 
    4. Add following line at the very end just before the </config>: <execute name="TPLINKOFF" allowParams="true">/pathtoyourscript/ ipofyourTPLinkswitch 9999 off</execute>

    You can name your command whatever you want. I named mine TPLINKOFF as seen above.

    5. In the repetier server webgui go to Printer Settings->G-Codes->Event Dependent and in the Run after job section add: @execute TPLINKOFF

    Now whenever repetier server has finished your print it will trigger this script as entered with the parameters in the extcommands.xml file. So in this case it will tell the switch to turn itself off.

    Now since i usually also make timelapses of my prints and repetier server does some compiling still even after the print is finished i personally also added a timer into the script to wait for 180 seconds after being activated before it turns off the switch. This gives repetier enough time to finish up the timelapse. If you want to do a similar delay then you need to edit the script. Open it up in notepad++ and search for the line: cmd_switch_off(){
    I added command sleep 180 (this tells the script to wait for 180 seconds at this point before proceeding with the next command which is the actual command it sends to the TP LINK switch to turn itself off) which takes care of the delay.

    And thats it.

  • Thanks a lot Freakadude! :smile: I will give it a try.
  • Hello Freakadude :) In the script I just have to change the first three parameters (ip, port and cmd)? Thanks 
  • You don't need to edit anything inside the script. You need to add your own ip, port and cmd to repetier servers own extcommands.xml file as menitoned in my post above in point 4. This will trigger the script on your device and pass on the relevant ip, port and command to trigger.
  • edited February 14
    Thank you very much for your help  Freakadude but I still couldn't solve it :( And sorry
    Can you confirm that the steps are all correctly executed?
    1-Download script - ok
    2-Copy the script onto my RPI. The folder can be "/home/pi/"?
    3, 4 an 5- Does the attached images seems correct?

  • You need to change "pathtoyourscript" to actually be the path where you store the hs100B.SH named script on your machine. So if you have stored the script under: /home/pi/ then you need to replace "pathtoyourscript" with "/home/pi/". Same goes for "ipofyourTPLinkswitch".  You need to change it the actuall ip address of your tp link switch that you want to control on your network. So if your switch would have i.e. IP of then you would put that in the line instead of "ipofyourTPLinkswitch".
  • Ahh OK :) 

    But like that? anything incorrect because it didn't work
  • You have 2 backslashes too many. Use the command like this: <execute name="TPLINKOFF" allowParams="true">/home/pi/ 9999 off</execute>
  • Sorry Freakadude but it didn't work :( 

  • can you post some images of your configuration? to compare and check what's wrong.
    Many thanks for your help
  • Just a side node - next release will natively support web requests as commands to e.g. call IFTTT maker webhooks to disable a plug. These commands will also be available in menus then. That makes it very easy to switch any plug with IFTTT support.
Sign In or Register to comment.