How to read gas and electricity measurements from your smart meter?
In this blogpost I would like to share my results in reading a dutch smart meter. In case you would like to start reading measurements from your own smart meter (the only prerequisite is that you have one), here is how I did it.
The first thing you need is a P1 smart meter USB cable, which can be bought online. You can find multiple online sellers by searching for e.g. ‘P1 cable’. And you need a computer system to connect the P1 cable to and which will process the incoming P1 telegrams. In this case I used a Raspberry Pi. You can see my setup here:
Serial communication settings
One of the most important things to know is which type and version of smart meter you have. This determines the settings for the serial communication to use. In my case I have a Landis + Gyr E350 (ZCF110), check e.g.: http://domoticx.com/p1-poort-slimme-meter-hardware/. My smart meter supports DSMR 4.2 and then the serial settings to use are: a baudrate of 115200, an eight bit bytesize without a parity bit. These settings are critical to get right for proper serial communication and some experimentation might be needed. Especially when your particular smart meter is not mentioned in the list.
Now it’s time to setup the Raspberry Pi. First thing I did was install Raspbian on a SD card and after some basic setup get it connected to wifi. Then I git cloned dsmr-forwarder, which is a Python application. This application reads and parses DSMR telegrams from the P1 port and publishes parsed measurements on MQTT topics. I adjusted the serial communication settings to match my smart meter. And set the serial port to the mounted USB port. In my case:
That’s all that needs to be done to get the serial connection working properly. What remains next is MQTT setup. MQTT (Message Queuing Telemetry Transport) is a lightweight publish subscribe messaging machine to machine communication protocol that’s often used at the heart of an IoT system. There are many ways to get an MQTT broker up and running. I use docker to run a MQTT broker on my Raspberry Pi, see e.g.: rpi-mosquitto. Once you have a MQTT broker up and running you can verify that the MQTT broker is behaving correctly by using e.g. mosquitto client tools to publish a message and subscribe to a topic.
./mosquitto_sub -h your-broker-ip-or-hostname -p 1883 -t test-topic
./mosquitto_pub -h your-broker-ip-or-hostname -p 1883 -t test-topic -m "hello world"
With the MQTT broker running what’s next is to adjust the MQTT settings of dsmr-forwarder by setting the MQTT_HOST and MQTT_PORT settings to point to your MQTT broker. Now everything is in place to process our first P1 telegram and publish the measurements on our MQTT broker. You start dsmr-forwarder for testing purposes with e.g.:
You verify whether the P1 port was successfully read by subscribing to the DSMR topic by invoking:
./mosquitto_sub -h your-broker-ip-or-hostname -p 1883 -t dsmr0/#
Note the #, which is a wildcard for a subscription to all nested MQTT topics starting with ‘dsmr0’.
If everything is ok then you should see the measurements coming in, otherwise happy debugging 😉 In the next blogpost I will show how to create nice dashboards using the TIG-stack (Telegraf, InfluxDB and Grafana).