Small script for reading serial data from a DSMR energy meter. With influxDB backend.
Since I had a spare Raspberry Pi (Model B+) and a DSMR energy meter. I figured i could as well read all the data it is sending to its P1 port. However. There was a catch. Other projects aimed at reading energy data from their meters involved either a newer model Pi, or were not capable of high precision, or both.
The goal was to create something that can read and store the data efficiently, while maintaining high precision.
Reads all of the following:
- Gas usage total
- Power used from the grid, and sent back to the grid
- Power usage totals for tariff 1 and 2.
- Actual power usage
- Voltage reading
- Aperage
With a fixed interval of 1 second!
- Separate server with InifluxDB (mandatory). Graphing can be done in Grafana.
I would not reccomend InfluxDB on a Pi. This would destroy the SD card. Also, i have not tested it on my Pi. I have little to no CPU headroom left on mine.
According to my calculation; storing this information for 1 year, will take approx. 2GB disk space for the DB. You will have to create your own retention policy on InfluxDB, if you dont want to have 1s precision down the line.
- Raspberry Pi (tested on model B+ 2014)
- Headless (script is CPU intensive - Easiliy 50%-70%)
- Set-up with Debian preferred and up-to-date
- Timezone set, NTP prefferd
- Python3
- Serial->USB cable connected to DSMR (P1 cable)
- Ethernet connected
Set-up your Raspberry accordingly. You want your raspberry to be headless. This script CPU hungry.
- git clone the file to your raspberry pi.
- Either use
git clone
or move it to ~/DSMRpi. Make sure thatapp.py
and such are inside this directory.
- Either use
- Set up python:
pip install requests pyserial
- Set up the config file:
cp example.config.py config.py
- Make sure to edit
config.py
afterwards. Edit your settings accordingly.
- Make sure to edit
- Make
app.py
executablechmod +x app.py
- Create a systemd unit file:
sudo cp systemd.unit /lib/systemd/system/DSMRpi.service
- Enable the service
sudo systemctl daemon-reload sudo systemctl enable DSMRpi sudo systemctl start DSMRpi sudo systemctl status DSMRpi
If you have any errors here, please check your settings. Else open an issue on github if you suspect the error to be in the script. Even better: Create a pull request with a fix.
- Fix time reading from the meter
In my case, the time on my DSMR is lagging by ~2 minutes.
- Add in reading power Fail logs (
timeConv
function is already there) - More?
I have had to use many resources to get this working honestly. So here are some links to guides / information i have used:
- GeJanssen's blog (Dutch) - link
- DSMR5 spec sheet (hosted on GeJanssen) - link (pdf is ENG)
- InfluxDB write API - link
- InfluxDB Line Protocol - link