Connecting sensors to Rpi (2/3)

By Atomstar on Sunday 2 December 2018 18:07
Categories: Linux, RaspberryPi, Smarthome, Views: 3.459

Here I describe the various sensors I connected to my RPi. Specifically:
  1. Kaifa DSMR 4.0/4.2 smart meter
  2. SMA sunnyboy PV inverter
  3. Honeywell Evohome thermostat
  4. Sensus analog water sensor
  5. Landis+Gyr Ultraheat digital 7-segment LCD heat meter

Kaifa DSMR smart meter ('slimme meter')

I have a Kaifa MA105(c)/MA304(c) DSMR4.0/DSMR4.2 meter. Simply connect this using a so called 'P1-cable' to the RPi (via hub or otherwise). I bought my P1 cable at SOSSolutions. There are a number of programs that can read it out:
  1. Domoticz - a home automation hub
  2. smeterd - a command-line python script
  3. DSMR-P1-telegram-reader - another python script
  4. dsmr-reader - a python hub including graphing
  5. Manually - see this guide (in Dutch)
I use option 1 and push the data to influxdb using a dzVents Lua script.

More info on the smart meter is here: https://www.netbeheernede...e_meter_15_a727fce1f1.pdf. Instructions to make your own P1 cable.

SMA Sunny Boy PV inverter

The Sunny Boy 2000HF/2500HF/3000HF inverter for our solar panels can actually be read out over bluetooth :o. There are several tools to make this easier:
  1. SBFspot - C-program that outputs to sqlite, mysql, or CSV. This was called SMASpot before.
    1. I made a script to push this to influxdb
    2. domoticz can read this natively. Note that domoticz does not use the timestamp from the CSV file, but the local time when it reads the file, which gives a ±1 minute error.
  2. German blog on install instructions (uses dated SMAspot).
Find the inverter using hcitool scan from the command-line.

Before I figured out it supported bluetooth, I failed at two alternative read out methods. These might be of help to you:

Read out pulse signal or 62056 port
62056 = DIN IEC 62056-21 and I believe is a definition of pulse generation. S0 = DIN 43864, which seems to be something related, but different.

I have this em-lite ECA2 meter which gives optical pulses when generating power. There are several solutions for reading this out: an OpenEnergyMonitor pulse sensor, instructions to read out using arduino, or instructions to build your own sensor.

Read out via Solo III geotogether energynote hub
It seems the em-lite meter mentioned above has a wireless connection capability with a geo together Solo III hub. This hub can then be connected to energynote and upload data somewhere. I didn't get this to work. Sources: and and

Honeywell Evohome thermostat

I read out the Honeywell thermostat thermometers using the web API connected to Domoticz.

I then push the data to influxdb using a dzVents Lua script.

Sensus analog water sensor

I have an analog Sensus water meter which I read out using a line sensor connected to GPIO on my RPi via a Python script. This sensor detects of the red-white rotating disc through the difference in IR reflection. Alternatively, you could read out the magnetic field (change) using a Hall sensor, but the line sensor worked easier for me.

  1. Water meter (any model with a rotating disk with different infrared reflection should do). I have a Sensus 520/620 meter
  2. Raspberry Pi with pre-soldered GPIO pins (any RPi will do, I tested on RPi0W and RPi3B+)
  3. CNY70 Line sensor (at least with digital out, prefereably also analog out to ease debugging. Working on 3.3V or 5.0V, I used this one)
  4. Jumper cables to connect to RPi (easier than soldering)
  5. Arduino or oscilloscope (optional but recommended to ease electronic debugging)
  6. Some metal/wood/putty/screws for sensor mounting

Installation & oscilloscope debugging
If you have an arduino: get arduinoscope working.

Connect line sensor to oscilloscope, then try to find the best orientation to detect the contrast in reflection. For me this was under a ±45 degree angle with the plastic window of the water meter, I got a contrast of ±0.5V to ±2.5V.

Once you are comfortable you know how the sensor works, mount it. Optionally use the potentiometer to adjust the digital out threshold. This should ideally be in the midpoint of the min and max voltage. For me this was at ±1.5V ((2.5+5)/2).

Install python3-gpiozero as pre-requisite, use to debug reading the LDR, get to run as daemon.

@reboot /home/pi/
to crontab

  1. Create dummy hardware, note idx
  2. Create virtual water sensor, using JSON
    1. curl --insecure "<dummy hardware idx>&sensorname=Water&sensortype=113"
    2. curl --insecure "<idx of sensor just created>&name=RFXMeter&switchtype=2&used=true"
  3. Edit name of virtual sensor via web interface, set current value
  4. Update RFX division to 1000 for water in Domoticz setting (if you're updating per liter)
  5. Test updating: curl --insecure "<sensor idx>&svalue=1"
  6. Enter domoticz details in script preamble

  1. Create database (e.g. 'smarthome')
  2. Enter influxdb URI in script preamble
  3. Set current value explicitly in influxdb, the rest will be added incrementally:curl -i -XPOST http://localhost:8086/write?db=smarthometest --data-binary "water,type=potable,device=sensus value=123456"

  1. Watermeter elektronisch aflezen
  2. Rood/grijs herkennen van teller op watermeter met CNY70
  3. Analoge meter uitlezen met een Arduino/Raspberry Pi
  4. Watermeter lezen met raspberry en Inductieve NPN sensor

Landis+Gyr Ultraheat digital 7-segment LCD heat meter

I read out the analog 7-segment LCD display using a camera and some simple OCR using this script.
  1. Landis+Gyr Ultraheat
  2. Camera
  3. Optional: USB light (as camera flash)
Meter units is in GJ, with 3 decimal digits (e.g. 271.199 GJ). Value we recognize is in MJ because we ignore the decimal point in OCR. Domoticz units are in m^3, with 2 decimal digits (e.g. 3581.92 m^3) -- internally might be stored with higher precision, again not visible through JSON api because of poor interface.

Conversion unit is 13.20772 m^3 gas/GJ, resolution is 0.01 m^3 for total count or 0.001 m^3 for daily count. For electric energy, conversion would be 277.7777 kWh/GJ.
Test camera:
raspistill --datetime -v -o cam_%d.jpg -t 0
Calibrate using script:
./ --calibrate
or if you want to calibrate on an image taken previously
./ --calibrate <file>
See for detailed instructions to add to domoticz
  1. looks promising
  2. is very sensitive to noise, didn't work for me
  3. tesseract / character recognition is overkill given the simplicity of seven segment LCD
  4. openCV's adaptive thresholding didn't work for me
  1. https://www.pyimagesearch...ts-with-opencv-and-python
  2. https://www.swarthmore.ed...s2016/install_opencv.html

Volgende: Getting started with LOLIN D1 mini/DHT22 on Mac 12-'18 Getting started with LOLIN D1 mini/DHT22 on Mac
Volgende: Installing domoticz on raspberry pi (1/3) 12-'18 Installing domoticz on raspberry pi (1/3)


Comments are closed