Setting up DSMR Meter Readings via a Raspberry Pi

badgerbadgerbadgerbadger

Shaun

Posted on May 23, 2024

Setting up DSMR Meter Readings via a Raspberry Pi

Originally published at https://badgerbadgerbadgerbadger.dev/posts/automation/2024-05-23-setting-up-dsmr-readings-via-raspberry-pi/

The internet is probably full of tutorials on how to do this right, but I had to struggle a bit to figure it out for myself. My Pi randomly crashed, the other day, and I'm having to do some of the setup again and having done this for the first time months ago (and having now mostly forgotten what I did), I decided I should blog about it as I retread my steps and recreate my setup.

Aside: The internet tells me that the C shell was the first to introduce the history command. It would not be hyperbolic to say that without history my task of recreating my setup would be significantly more difficult. I used it extensively to figure out what I ran when I needed to do this all those months ago. I should probably containerise or chefise or ansibilise or something.

I live in a country that uses DSMR meters and have one in my home. My girlfriend wanted a closer look at our electricity consumption, so I decided to hook up a raspberry Pi to the meter's P1 port and send those readings to my home lab server using the Pi as a relay.

I bought a RJ12 --> USB cable off of Amazon and tried to read from my Pi's USB port by using first cu and then pyserial (which is a much friendlier interface).

# Using cu
cu -l /dev/ttyUSB0 -s 115200 --parity=none

# Using pyserial
python3 -m serial.tools.miniterm /dev/ttyUSB0 115200 --xonxoff
Enter fullscreen mode Exit fullscreen mode

Initially neither tool gave me any readings and I nearly tore my luscious hair out before finally realising that it was a bad cable I was using. I returned it and bought a more respectable cable from robbshop.nl.

And that gave me results!

image

I had a few different ways of turning the meter readings into useful insights:

  1. Run HomeAssistant on my Pi with direct access to the port: Not an option since my HA instance was already running on my home lab server. The Pi was meant to be a relay only.
  2. DSMR to MQTT: I could run something that would read the DSMR telegrams and send them to an MQTT broker to which I could subscribe my HA integration. Definitely an option.
  3. Serial to Network Proxy: The option I ended up going with since it felt the simplest to me. I would run a program that would expose the DSMR telegrams over a TCP connection.

The program I landed on for doing this is ser2net With a little help from ChatGPT I figured out this ser2net config. Comments describe what the various fields do.

# defines an alias confver, I'm not entirely sure if this does anything
define: &confver 1.0

# begins a new connection definition and assigns it an alias `con00`.
connection: &con00
  # specifies how incoming network connections will be accepted, in this case the Telnet protocol with RFC 2217 support (I no clue what that means), and the connection will be over TCP and listen on port 2013c (this part I understand)
  accepter: telnet(rfc2217),tcp,2013
  # specifies how the serial device will be connected, includes path to the serial device file and port settings, and it is to be configured in local mode (not sure what local mode means)
  connector: serialdev,/dev/ttyUSB0,115200n81,local
Enter fullscreen mode Exit fullscreen mode

I paired this with HA's DSMR Slimme Meter integration with it set to listen on the network, pointed at my Pi on port 2013.

And we have lift-off!

image

Note: Solar readings are coming in via a different integrations and configured together with the DSMR readings using HomeAssistant's Energy Dashboard.

💖 💪 🙅 🚩
badgerbadgerbadgerbadger
Shaun

Posted on May 23, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related