GPIO water meter

From Domoticz
(Redirected from GPIO meter)
Jump to navigation Jump to search


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

Hardware

  • 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 https://www.hackerstore.nl/Artikel/26)
  • 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

Install

Arduinoscope

If you have an arduino: get arduinoscope working http://www.instructables.com/id/Another-Arduino-Oscilloscope/

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.

Calibration

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

Software

Set up domoticz

  1. Create dummy hardware, note idx
  2. Create virtual water sensor, using JSON
    1. curl --insecure "https://127.0.0.1:10443/json.htm?type=createvirtualsensor&idx=<dummy hardware idx>&sensorname=Water&sensortype=113"
    2. curl --insecure "https://127.0.0.1:10443/json.htm?type=setused&idx=<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 "https://127.0.0.1:10443/json.htm?type=command&param=udevice&idx=24&svalue=1"

Add script

See https://github.com/tvwerkhoven/water_meter_reader/blob/4bb9f2d1f59e44a8b9769b6ad2a4dc31ccb84237/water_worker.py

Run at startup

Add

@reboot /home/pi/meter_water/water_worker.py

to crontab using crontab -e as any user

Reference