I'm making a graduation project where I need to connect a smart plug to a web server through WAN (obviously the smart plug and the server aren't on the same network).

In other words, I want to be able to turn the smart plug on/off through my website and have the smart plug send power readings to my server's API.

Most smart plugs out there connect to their manufacturer's API. I want to buy a smart plug that I can configure/program to connect to my own API.

Are there any smart plugs out there that support that?

I would appreciate any more suggestions or information because I'm kinda lost.

EDIT: I did an extensive google searching, most methods out there :

  1. reverse engineering the API between the android app and the manufacturer's server and calling the manufacturer's server to control the smart plug, or using IFFT which also calls the manufacturer's server.

  2. Creating a script on the local network that receives commands from WAN and sends commands to the smartplug through it's LAN API , but obviously this is not what I need as it requires that you run the script on a device (raspberry pie) 24 hours.

  3. There are also upnp and port forwarding methods that allow you to use the local network API on WAN but that's also not an option for security reasons.

I need a smart plug that has power monitoring capabilities that I can make it connect to my own server.

  1. I read about flashing a custom firmware (tasmota) on a smartplug (sonoff) to make it connect to an MQTT broker on WAN. I think this satisfies what I need, I can install an MQTT brocker on my server and make the smartplug connect to it, but this method is kinda hacky and I don't wanna risk. I also don't know if it supports power monitoring or not.

there's a smart plug called MOKO SMART MK112 that supports MQTT and power monitoring out of the box, but the problem is that I couldn't get it from china due to COVID19.

If you know any good resources to do that or any smartplug that supports MQTT as well as power monitoring I or any other suggestions would really appreciate it.

  • yes, there are some that can be customized by replacing the firmware .... so keep searching ... try a search for hack smartplug
    – jsotola
    Commented Apr 19, 2021 at 16:50
  • It's been asked before. My favorite is to try IFTTT. But see these questions here and here. Commented Apr 19, 2021 at 19:39
  • You can make your own smart plug using esp8266 or esp32
    – Lakshay184
    Commented Apr 20, 2021 at 4:50
  • Why do you think flashing custom firmware to a Tasmota/Sonoff to be "hacky". If you want custom behaviour from a device, you are going to have to change the firmware.
    – hardillb
    Commented Apr 20, 2021 at 10:53

2 Answers 2


Thank you for helping, I've found what I needed and that is the Shelly SmartPlug

Shelly SmartPlug supports both, a documented Cloud API (Through shelly servers) so you don't need to intercept or reverse Engineer anything.
as well as support for MQTT protocol.
you will need to enable it first through its web interface, enter your MQTT broker IP and port and you're good to go.

It uses an ESP8266 chip, running Mongoose OS, You can also flash tasmota on it on the air without soldering.

It has three ways of communications
1.Local HTTP API
3.Cloud API

Here's my plan :
first I will press the power button on the shelly smart plug
it will open a wifi network with a local HTTP server that you can use to configure it.
through my custom Android app, I will call that server API, pass my Wifi credentials to it, enable MQTT, Add my MQTT Server IP and port to it and that's it!

I can then use its local HTTP server to communicate with it through LAN or use MQTT to communicate with it through WAN.


Local API: https://shelly-api-docs.shelly.cloud/_review/mqtt/#shelly-plug

Cloud API: https://shelly.cloud/documents/developers/shelly_cloud_api_access.pdf

Tasmota profile: https://templates.blakadder.com/shelly_plug_S.html

Flashing: https://youtu.be/_TSJB_IzxG0


The Sonoff S31 running the Tasmota firmware is probably the best solution that will let you customise where it connects to.

The S31 supports power monitoring and using the Tasmota firmware lets you control where it sends the data. So meets all the requirements you have listed.

------ BIG Edit Now I'm not on my phone -------

But to put in a vote for another solution that you have discarded. Using a device with a local API and having a Raspberry Pi on the same LAN to collect the data and then send this to the cloud.

I have actually deployed systems like this because it solves a bunch of problems. The trick is to set the Pi up as a WiFi Access point and have the sockets connect to the Pi. The Pi is then plugged into the local router via it's Ethernet socket.

This setup works well because the sockets can be shipped out pre-configured to connect to the WiFi network provided by the Pi and all the remote user needs to do is plug the Pi into power and a spare Ethernet socket on their local router. This basically removes the need for any technical expertise at the site the monitoring will take place. It also means that the pi can buffer data if there is a network outage so you don't loose data.

This setup was used to monitor a large number of devices at a large number of locations in multiple countries and works well.

The pi ended up using the Balina.io platform so it could be easily remotely managed and updated with out the need to return it or for somebody to visit the site if an update was needed.

  • Thank you for replying, really appreciate it, but as I mentioned above in my question, the sonof hack and the raspberry pie aren't really feasible options for me.
    – MM.Linuxer
    Commented Apr 21, 2021 at 6:30
  • You haven't said why the sonoff is not feasible, you've just said it feels hacky with no justification. You've explicitly said you want to be able to program the plug which is what the tasmota firmware is doing and since it is open source you can make further modifications if needed. Also the tasmota firmware has a huge user base so it's well tested
    – hardillb
    Commented Apr 21, 2021 at 6:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.