Shelly power plug S with esphome

To monitor the power usage of many of my devices I started looking into smart plugs and came across the “Shelly plug S”

advantages of this model:

  • cheap (€20 a piece at the time of writing)
  • ESP8266 used allows for reflashing with your own code
  • power monitoring and switchable

disadvantages:

  • only 10A rated
  • Accuracy is quite bad, even after calibration the values jump around
  • low update speed to accurately measure low power (explained why below)
  • wifi instead of Zwave or Zigbee (been stable for me but this depends on your wifi network)
  • Wifi antenna is not great but not terrible

How to program?

Opening it is easy, there is a screw hidden inside the ground plug, unscrew this and the front pops loose.
Be aware there is a small thermal pad that can fall out.

I got the pinout from this post on the HA forum.
I was able to flash the ESP by pushing Dupont wires which are also used with breadboards through the holes and keeping a bit of sideways pressure while flashing.
But because that method would always work well I switched over to using pogo pins with a header soldered on.

The hardware

The power plug uses the eps8266 as its main IC, and because there is a header that exposes the pins needed for programming, reprograming it is really easy.

The antenna is a flex pcb with a trace, this does work but does not offer the best connection, I have noticed it is slightly worse than a normal pcb antena as some esp dev boards use.

The HLW8012 IC is used for the energy monitoring, this IC can measure active power,voltage and current but does not calculate energy used, this has to be done in software.

The active power value is sent to the esp via a variable frequency from the HLW8012, so when the measured active power is low the output frequency is low as well. 12w is already only 1HZ, so if we would want to measure 1.2w it would take us 10 seconds to know that..
Because of that the update speed of the measured power can get really slow when trying to measure low power devices.

The current sense resistor used in the shelly plug is 1mΩ with an accuracy of 10-20%, if you want to be somewhat accurate I should suggest calibrating the plug before putting them to use.

The internal temperature is monitored with a NTC, this is really important for the safety of the device. when drawing large loads for longer duration the temperature can get dangerously high. I have experienced overtemperature when drawing a load of 2000W for 15 min.
The 2300W power rating of the plug cannot be sustained for long..

The software

Most of my code is based on the config found on the esphome devices forum, I made some adjustments to make it safer and adjust it to my liking.

One important change I made was adding an overcurrent protection before the esp devices forum had some code that did not have that present. When a large load is connected with a bad power factor the current can go well above the rated 10A while staying below the 2300w limit. The temperature protection might not trip fast enough if the overcurrent is large enough.

Each shelly plug has their own config that contains the name and some config and calibration data.

This is the base config for the plugs containing all the sensor configuration.

1 thought on “Shelly power plug S with esphome

  1. Jurgen says:

    Great manual!

    With this clear guidelines and code I had my shelly plug working on the 1st go.

    Thanks!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *