Nowadays many houses in the Netherlands have a so-called Smart Energy meter. With this meter, energy companies can read your meter without anyone having to come by. But I want to be able to read that data myself with Python.

Data, it's gold for some companies. But I can't stand the fact that, for example, my energy company has data from me and I don't.

So I started tinkering with a Raspberry and Python code to read the data from a smart meter myself.

Building your own smart meter read-out setup

This DIY project is actually very simple and you only need a few things to read your meter yourself.

Mind you, you need to be a bit tech-savvy to build this. You don't need a soldering iron just some linux installation and Python code experience.

The necessities for building this yourself are:

1 Raspberry Pi from 40 bucks to 100 with case and cables (affiliate link)
1 P1 cable 16 bucks (affiliate link)

and some Python code.

I assume that you have a Raspberry and have bought a P1 cable. I also assume that you have installed your raspberry with the Rasp OS.

Raspberry Pi OS (previously called Raspbian) is the Foundation’s official supported operating system. You can install it with NOOBS or download the image below and follow our installation guide.

You can always use any linux OS you want or that you have. You do however need Python 3.8 minimum. Your system comes with 2.7.x and 3.5.x so you better upgrade. Read this if you want to upgrade to Python 3.8.x

Setting up the P1 cable

P1, what is a P1 cable? Well it goes into the P1 port :-) The P1 port is a serial port on your digital electricity meter, into which you can plug an RJ-11 (Registered Jack) plug (known from the telephone connections) to read the meter readings and consumption. It is not possible to send data to the port!

However, this serial port is not standard, despite the fact that it works at UART TTL level, the logical values ​​are reversed: 1 = 0 and 0 = 1, this can be solved by software, but does not always give the desired result, solution is to do this hardware-wise, for example with a chip to be placed in between. A MAX232 or 7404 is often used.

According to the specification, the port can handle max. 15v, so a real RS232 signal (+ 12v) from a “real” com port must be able to handle it.

The plug that has to be put in the P1 port is the type RJ-11, 4 or 6-pin (known from the telephone connections). The P1 cable has this RJ-11 type of plug on one side and USB on the other side.

So.. simple right, you put one end (RJ-11) of the cable in the smart meter.

The black cable looks like an land line phone plug

And the other end you put in one of the Raspberry USB ports.

Sorry, this is just a photo, usb is plugged in on the side

So as it is an USB port it works as a serial port.

# Seriele poort confguratie
ser = serial.Serial()
# DSMR 2.2 > 9600 7E1:
ser.baudrate = 9600
ser.bytesize = serial.SEVENBITS
ser.parity = serial.PARITY_EVEN
ser.stopbits = serial.STOPBITS_ONE

You also code your python script as a serial port reader. As you can see in above code you call upon the serial packaged (you will have to install) and it reads-out the data with a 9600 baudrate.

It could be that you don't have a 9600 baudrate smart meter but a 115200 baudrate, I guess that is a newer version (or maybe used on Gas Meters, I'm not sure.)

But don't worry it's all in my code.

So you can run my code headless by running it from a cronjob or by hand. It files some log files so you can take a look with tail if it still works.

Installing the right packages

For this script to work you will need some packages. If you put below text in a requirements.txt file and run this with pip install -r requirements.txt it will install all you need.


The most important package is the pyserial package that actually reads the data coming from your smart energy meter.

This package encapsulates the access for the serial port. It provides backends for Python running on Windows, OSX, Linux, BSD (possibly any POSIX compliant system) and IronPython. The module named “serial” automatically selects the appropriate backend.

So what more do you need?

Place below script in a folder. Make sure the folder contains a folder named:

  • logging
  • database

And try to run the script!

Questions? Let me know! Coffee? Yes Please!

Originally the initial code came from but I changed it to my needs