GPIO meter

From Domoticz
Jump to: navigation, search

Analog water meter reading with line sensor on GPIO Raspberry Pi.


  • Water sensor (any model with a rotating disk with different infrared reflection should do)
  • Raspberry Pi Zero W with pre-soldered GPIO pins (any RPi will do)
  • Line sensor (at least with digital out, prefereably also analog out to ease debugging. Working on 3.3V or 5.0V, I used
  • Jumper cables to connect to RPi (easier than soldering)
  • Adruino or oscilloscope (optional but recommended to ease electronic debugging)
  • Some metal/wood/putty/screws for sensor mounting



If you have an arduino: get arduinoscope working

Debug with oscilloscope

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).


Set up domoticz

  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 "<id of sensor just created>&name=RFXMeter&switchtype=2&used=true"
  3. Edit name of virtual sensor via web interface
  4. Update RFX division to 1000 for water in Domoticz setting (if you're updating per liter)
  5. Test updating
    1. curl --insecure ""

Add script


Run at startup


@reboot /home/pi/meter_water/

to crontab using crontab -e as any user