Wall plug (passthrough) or socket monitors?

I’ve been trialling the Energenie Mi|Home line of monitoring and control devices, but haven’t been particularly happy with their extensibility, dependability nor support.

As such, I’m strongly considering swapping to an emonTx and emonBase as I’ve been wowed by the openness, capabilities, responsiveness and extensibility.

However! There currently isn’t a 1st party way to monitor specific devices (like the washing machine). Has anybody integrated something similar to the Energenie ‘monitor’ range of plug-in (or socket replacement) devices into their OpenEnergy Monitor setup?

This is a subject that pops up from time to time in various guises, usually in the form of “I want a plug-sized emonTx”.

I think the major difficulty is in regard to safety requirements and certification. The emonTx gets around this by using a certified a.c. adaptor and a c.t. Incorporating those into something of a similar size to the usual plug-in monitor would be problematical. There are other ways of course, but certification is a long and expensive process, and would imply a factory-sealed unit to prevent users from coming into contact with something not isolated from the mains.

There’s nothing stopping you from using a much lower rated c.t. with an emonTx - it’s not restricted to the whole-house 100 A one stocked by the shop, but I agree it doesn’t have the convenience of a plug-in monitor.

To finally answer the question - I can’t recollect anyone reporting that they have integrated a commercial monitoring unit into the OEM system. The stumbling block is usually that either the data is encrypted, or it’s not been possible to pick it apart to determine the protocol. But there might be hope - I think radiator valves have been controlled.

This post below came up in the “Suggested Topics” section below while I was reading your post:

@WebAsh about a year ago we released a smartphone app for energy monitoring but it was very, very complex. It included video streaming and GPS based control of sockets etc. It was designed to work with OpenEnergyMonitor (OEM) hardware and off the shelf hardware from other suppliers.

We recently removed all the video streaming and GPS stuff as most users simply weren’t using it.

It still updates EmonCMS and Thingspeak with data but currently it doesn’t include the code for OEM. It wouldn’t be difficult to reintroduce OEM if there was a demand for it.

Below is the latest screenshot of an electric heater being monitored in my office. As well as providing the data the app can also turn the socket on and off remotely via the internet.

I use tp-link hs-110’s

They are WiFi (so no physical hub required beyond your usual broadband router) and the protocol is widely discussed on the web and easy enough to code. I have a simple python script running on a Pi that polls each one and posts the data to emonhub via a socket interfacer, from there you can post to multiple emoncms’s etc.

1 Like

Personally I have found the WiFi reliability of these to be suspect - mine continually drops out and it is in the same room as the router! I also do not like that I cannot force an IP address (yes I know I can reserve the mac address).

I remember you saying about this before - did you post a link to the code? If not, could you?

What (hardware) are you using to collect that data to display in that app?

Yeah basically a plug-sized emonTx would be perfect haha. I did figure that the limiting factor would be mains certification. Although you did touch on a way it could work: a passthrough AC adapter and a CT to a single-input emonTx would work well for what I intend. If I was better set up at the moment to be able to put together my own electronics then I’d probably find a way to construct such a smaller 1-input emonTx.

In lieu of my time/capability or general availability of such a device, I think sometime off the shelf would have to meet my needs. I saw a post about someone integrating the Energenie mi|home plugs into emonCMS by adding the OOK-based radio chip they use, which is open regarding protocol and even some code samples in python. It would mean not entirely replacing what I have as I’d hoped, but at least I’d get the granularity and control that their own software doesn’t give.

Currently I’m using a $3 ESP8266 hooked up to a Pzem-004T.

Previously we have had the ESP8266 hooked up to an emonTX.

Not something I’ve had any trouble with. I have 3, one of which is in the garage where sometimes Pi3’s struggle to establish a wifi connection, let alone maintain one without dropouts.

No there’s no where to manually enter an IP, but I rarely use that method, reserved IP’s work just as well as static IP’s in most instances.

Sure I’ll look out some code, I’ll start another thread when I do.

TBH Brian I half expected you to suggest using a sonoff (and tasmota?) as I know you are a fan.

I have a couple of their early wifi switches but no experience of this particular device.

I started to (:laughing:) but realised none of their plug in ones do energy monitoring (bound to come, about the only gap in the range).

1 Like

There’s an interesting article about the TP-Link device at

it includes command details

1 Like

another option are XTM18S or DDS238 and connect an esp to its pulse counter

here the code for it it not mine but it works fine

   /**
   * This script is based on these sources:
   *
   * To count pulses using interruptions:  https://github.com/mysensors/MySensors  /blob/master/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino
    * To connect to Wifi and publish MQTT messages:  https://github.com/knolleary  /pubsubclient/blob/master/examples/mqtt_esp8266/mqtt_esp8266.ino
    *
    * This program is free software; you can redistribute it and/or
    * modify it under the terms of the GNU General Public License
    * version 2 as published by the Free Software Foundation.
*
 *******************************
*
* DESCRIPTION
* Use this sensor to measure kWh and Watt of your house meter.
* You need to set the correct pulsefactor of your meter (pulses per kWh).
* Reports every SEND_FREQUENCY miliseconds: pulses counting, kWh and Watt to    different MQTT topics.
 *
 */

#include <ESP8266WiFi.h>
#include <PubSubClient.h>

// Update these with values suitable for your network.

/************************* WiFi Access Point *********************************/

const char* ssid = "yourssid";
const char* password = "yourpassword";

/**************************** MQTT Broker ************************************/

const char* mqtt_server = "mqttserverip"; // example: "192.168.0.8"
const char* mqtt_username = "yourmqttuser";
const char* mqtt_password = "yourmqttpass";
const char* mqtt_topic_watt = "ESP-energy-01/watt";
const char* mqtt_topic_kwh = "ESP-energy-01/kwh";
const char* mqtt_topic_pulse = "ESP-energy-01/pulse";

#define DIGITAL_INPUT_SENSOR 12 // The digital input you attached S0+ D6 in Wemos D1 mini
#define PULSE_FACTOR 1000       // Nummber of pulses per kWh of your meeter
#define MAX_WATT 10000          // Max watt value to report. This filters outliers.

unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in    milliseconds)
double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour
 volatile unsigned long pulseCount = 0;
 volatile unsigned long lastBlink = 0;
 volatile unsigned long watt = 0;
 unsigned long oldWatt = 0;
 double oldKwh;
unsigned long lastSend;

WiFiClient espClient;
PubSubClient client(espClient);

long lastMsg = 0;
char msg[50];
char wattString[6];
char kwhString[6];
char pulseCountString[6];

void setup_wifi() {
  delay(10);
  // We start by connecting to a WiFi network
 Serial.println();
 Serial.print("Connecting to ");
 Serial.println(ssid);

 WiFi.begin(ssid, password);

 while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.print(".");
}

 Serial.println("");
 Serial.println("WiFi connected");
 Serial.println("IP address: ");
 Serial.println(WiFi.localIP());
}

// Setup a MQTT subscription
void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
 Serial.print(topic);
 Serial.print("] ");
  for (int i = 0; i < length; i++) {
  Serial.print((char)payload[i]);
 }
 Serial.println();
}

void reconnect() {
 // Loop until we're reconnected
 while (!client.connected()) {
   Serial.print("Attempting MQTT connection...");
// Attempt to connect
   if (client.connect("ESP8266Client", mqtt_username, mqtt_password)) {
     Serial.println("connected");
   } else {
  Serial.print("failed, rc=");
  Serial.print(client.state());
  Serial.println(" try again in 5 seconds");
  // Wait 5 seconds before retrying
  delay(5000);
   }
 }
}

void setup()
{
 Serial.begin(115200);
 setup_wifi();
 client.setServer(mqtt_server, 1883);
 client.setCallback(callback);
  // Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output
  // If no pullup is used, the reported usage will be too high because of the floating pin
pinMode(DIGITAL_INPUT_SENSOR,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, RISING);
 lastSend=millis();
}

 void loop()
 {
if (!client.connected()) {
    reconnect();
}
client.loop();

unsigned long now = millis();
// Only send values at a maximum frequency
bool sendTime = now - lastSend > SEND_FREQUENCY;
if (sendTime) {
    // New watt value has been calculated
    if (watt != oldWatt) {
        // Check that we dont get unresonable large watt value.
        // could hapen when long wraps or false interrupt triggered
        if (watt<((unsigned long)MAX_WATT)) {
            // convert to a string with 2 digits before the comma and 2 digits for precision
            dtostrf(watt, 4, 1, wattString);
            client.publish(mqtt_topic_watt,wattString);  // Publish watt to MQTT topic
        }
        Serial.print("Watt:");
        Serial.println(wattString);
        oldWatt = watt;
        dtostrf(pulseCount, 4, 1, pulseCountString); // To Do: convert int to str, but not like this
        client.publish(mqtt_topic_pulse,pulseCountString);  // Publish pulses to MQTT topic
        double kwh = ((double)pulseCount/((double)PULSE_FACTOR));
        // convert to a string with 2 digits before the comma and 2 digits for precision
        dtostrf(kwh, 2, 2, kwhString);
        client.publish(mqtt_topic_kwh,kwhString);  // Publish kwh to MQTT topic
        oldKwh = kwh;
        lastSend = now;  // once every thing is published we update the send time
    }
  }

  }

 void onPulse()
{
  unsigned long newBlink = micros();
  unsigned long interval = newBlink-lastBlink;
  if (interval<10000L) { // Sometimes we get interrupt on RISING
        return;
   }
  watt = (3600000000.0 /interval) / ppwh;
   lastBlink = newBlink;
   pulseCount++;
}

you can get them here in wide variety of of voltages amperage and power types

https://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20190117104340&SearchText=dds238

Done! See Python code to read TP-Link HS110

1 Like

here something that might work for you and many other devices–
https://koenkk.github.io/zigbee2mqtt/information/supported_devices.html

seams to support:
this Xiaomi wall socket

xiaomi wall adapter

and other wall adapters but they are lower watt 300 - 600 watts not enough for a fridge - the xoiami ones are both 10amp

here a howto

1 Like

Thanks all for some great suggestions. It js great to see such activity here. I think after all this I might try get the mi|home devices going with the Pi module and their Python library.

I use the Sonoff Pow2 running Tasmota which outputs using MQTT. I then use NodeRED to send to emoncms. I have one on a dehumidifier. I have a NodeMCU with an SHT21 and BMP280 measuring temp and humidity (in and out). These go to OpenHAB via MQTT. I have a control in OpenHAB which looks at the average humidity over the last hour and when that gets too high it turns on the dehumidifier and when the average drops it turns off the dehumidifier off. This works great and keeps the efficiency up. I have a tipping bucket rain gauge connected to the NodeMCU which keeps track of the water coming out. I have a block in NodeRED that measures the efficiency (buckets/KWh) and sends that to emoncms. Even with all of this the actual efficiency is way less than specified. But, that is expected as they are specified at the point where they are really efficient, hot and really, really, really humid. Mine is in a cool area that is relatively dry. There is a seasonal difference, as outside temperature/humidity really impacts what is going on inside.

In the US the Sonoff S31 is my new favorite, as it is much smaller. Tasmota is a really great open source program on GitHub.

1 Like

4 posts were split to a new topic: Using a tipping bucket rain gauge

I’ve finally done something here. Please excuse my terrible Python (it’s my first time writing it), but I’ve created a ‘middleware’ between pyenergenie and MQTT:

Would like to know if it is useful for others, but essentially I can now ingest energenie monitoring information into emonCMS via MQTT.