A Swedish version of this document is here
A PCB to interface the smartmeter is available here
This is how the new electricity meter look slike that was installed here this week. Apparently, 5.4 million new meters will be out before 2025 (Swedish). Yes, I have been collecting data from its predecessor (which was only installed here for two years) for quite some time. S0 pulse was not available to ordinary people like me but the flashing IR diode was. So power and energy I have logged. I have another meter in my office too. Reads S0 and IR there and can thus distinguish between the house’s total electricity consumption and the office’s electricity consumption.
But the new electricity meter promised more. A serial interface for customers. A HAN gate. Yep, definitely something that definitely start a guy like me up. A few minutes after it was installed, the customer interface was activated. Just go to Ellevio’s “my pages” and activate. Smooth.
Unfortunately I did not go ahead with building the interface logic required to be able to read out values from the interface the day it got installed. Had to (impatiently) wait to the next day because I had other things to do. But it was very simple. A transistor, some resistors and a USB to series converter are all that is needed. After it is built a Raspberry Pi could read the information that the meter sends out. You could just as easily use an ESP32’a or an ESP8266, Arduino, or a PC of course. Nothing strange, expensive or advanced here.
The new meter provides current and voltage and active and reactive load on all phases separately. Add summed energy to that. Yes, both in and out. If you are someone who has a wind turbine or solar panels in the yard the in readings is for you. Goddies for those of us that like data. All data is sent out every ten seconds from the meter.
So what does the meter send?
As far as I understand, the protocol is called “P1 Companion Standard” which is based on IEC 62056-21 Mode D. The energy companies have issued an Industry Recommendation for local customer interface for electricity meters that describes function and protocol.
The serial format is unencrypted with speed and format 115200, N, 8.1. Just standard. However, it is sent inverted and with TTL levels so you have to take care of that.
The contact on the electricity meter is an RJ12 as below
The meter sends data on pin 5 when D_Rqst (RTS) is high. I have tested the circuit below with both 5V and 3.3V and both work great so interfacing most hardware should be no problem as long as it has a serial port or can emulate one.
If you look at what the interface on the meter looks like, you understand that both 3.3V and 5V work.
A simple circuit is all that is needed to adapt this to a USB TTL serial adapter I used or to the serial channels on a Raspberry Pi, Arduino or other device.
Select 5V for VCC if rx is to be connected to a 5V input (Arduino etc), otherwise select 3.3V (ESP32 / ESP8266 / Raspberry Pi etc). In my case, I use a USB to series adapter that can handle TTL levels. Remember to also connect the earth to the device that will read the data.
If you use a USB to series adapter like me and Raspberry Pi, it will be available as /dev/ttyUSB0, /dev/ttyUSB1, etc when connected. With the Minicom program you can look at the raw data. Install Minicom with
sudo apt install minicom
If you want to be able to open the port without “sudo”, you should add the user you are running under (usually “pi“) to dialout in the file /dev/group
Use the nano or vim editor or your own favorite editor to do this.
Now run Minicom with
minicom -b115200 -D/dev/ttyUSB0
Change the serial port to the port you use and add sudo if you did not do the change in /dev/group.
The command line switches speak for themselves. But for safety’s sake, we take them. -b sets the baud rate. -D indicates the port you want to communicate on. Of course you change to the port you use. If all goes well, the following is printed on the screen every ten seconds.
In the linked document above, there is an appendix 3 that tells what the type of data is for each line. Easy to parse with our code.
To exit Minicom, type
ctrl-A Z X
and select “yes” when asked “Leave Minicom?” Best to write it because the sequence is not the first one you come up with. Trivial if you know it, not so if you don’t.
It is not more than that. Now just write a program that reads these values and lists them in charts and tables. node-red is a great tool to use for this. node-red can read from a serial port directly or you can write a script like this in Python
sio = serial.Serial(
print("connected to: " + sio.portstr)
line = sio.readline().decode('ascii')
if (-1 != line.find("1-0:31.7.0")):
print("[" + line + "]")
print("Fas L1:"+line[11:-5]+ " " + line[-4])
Preferably, you then send the data to an MQTT broker or similar instead of printing it. A little fun coding for a boring evening maybe.
I have put together the project vscp-python-p1-power-meter which sends sensor values to any MQTT broker. If you do not like VSCP, the code can be easily adapted for other formats. I think the code is pretty easy to understand. Configuration takes place in the config.ini file and you have documentation on the code page. Below is a screenshot from MQTT explorer showing MQTT VSCP data for voltage, phase 1 delivered in real time
And below the current data for the same phase
Note the diagram at the bottom right. A smooth feature in MQTT explorer to quickly visualize data.
This is what it can look like when data is presented in node-red
But it is very easy to create your own website and present live data there if you first send it to an MQTT broker taht havae websockets enabled. If you send VSCP events over that interface instead of some other random data, you have a solution that is both scaleable and reusable at all levels. I may do a howto on that to later.
This is how it looks in node-red
For a live demo check here
A driver for the VSCP daemon is here