Connecting sensors to Rpi (2/3)
Here I describe the various sensors I connected to my RPi. Specifically:
- Kaifa DSMR 4.0/4.2 smart meter
- SMA sunnyboy PV inverter
- Honeywell Evohome thermostat
- Sensus analog water sensor
- 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:
- Domoticz - a home automation hub
- smeterd - a command-line python script
- DSMR-P1-telegram-reader - another python script
- dsmr-reader - a python hub including graphing
- 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:
- 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.
- 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: https://www.youtube.com/watch?v=1zTQLphHd9o and https://www.energynote.eu/?lang=en and https://support.geotogether.com/en/support/home#.
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.
- Water meter (any model with a rotating disk with different infrared reflection should do). I have a Sensus 520/620 meter
- Raspberry Pi with pre-soldered GPIO pins (any RPi will do, I tested on RPi0W and RPi3B+)
- 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)
- Jumper cables to connect to RPi (easier than soldering)
- Arduino or oscilloscope (optional but recommended to ease electronic debugging)
- 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 read_ldr.py to debug reading the LDR, get water_worker.py to run as daemon.
- Create dummy hardware, note idx
- Create virtual water sensor, using JSON
curl --insecure "https://127.0.0.1:10443/json.htm?type=createvirtualsensor&idx=<dummy hardware idx>&sensorname=Water&sensortype=113"
curl --insecure "https://127.0.0.1:10443/json.htm?type=setused&idx=<idx of sensor just created>&name=RFXMeter&switchtype=2&used=true"
- Edit name of virtual sensor via web interface, set current value
- Update RFX division to 1000 for water in Domoticz setting (if you’re updating per liter)
- Test updating:
curl --insecure "https://127.0.0.1:10443/json.htm?type=command¶m=udevice&idx=<sensor idx>&svalue=1"
- Enter domoticz details in script preamble
- Create database (e.g. ‘smarthome’)
- Enter influxdb URI in script preamble
- 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"
- Watermeter elektronisch aflezen
- Rood/grijs herkennen van teller op watermeter met CNY70
- Analoge meter uitlezen met een Arduino/Raspberry Pi
- 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.
- Landis+Gyr Ultraheat
- 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.
raspistill --datetime -v -o cam_%d.jpg -t 0
Calibrate using get_digits.py script:
or if you want to calibrate on an image taken previously
./get_digits.py --calibrate <file>
See README.md for detailed instructions to add to domoticz
- https://github.com/jiweibo/SSOCR looks promising
- https://www.unix-ag.uni-kl.de/~auerswal/ssocr/ is very sensitive to noise, didn’t work for me
- tesseract / character recognition is overkill given the simplicity of seven segment LCD
- openCV’s adaptive thresholding didn’t work for me
#Linux #RaspberryPi #smarthome