Water meter reading with a cheap webcam and Dialeye

My house has an analogue water meter reader with dials, so the only way to read it is using an image and getting the reading from it.

A cheap usb webcam with LED lights was used.

Application used to take images is fswebcam (apt-get install fswebcam)

Dialeye is configured to read the image using Python. DialEye has great instructions for setting it up: http://olammi.iki.fi/sw/dialEye/

After calibration the image looked like this

The test run looked like this

Running the Dialeye python command turns out as a number like this

$ python dialEye.py -r meter docs/dialeye_calibration.jpg

Writing dialeye_result.png

0692

Every five minutes a cronjob is run that takes a photo, reads the image with DialEye and stores the results in a file. It is then uploaded to Openhab with curl using the REST API.

The old result is stored each time so a cumulative and a 5 minute average is read.

$ more dialeye.sh

#!/bin/bash

#Cleanhouse and log results

cat /home/pi/scripts/dialeye/dialeye_result.txt >> /home/pi/scripts/dialeye/dialeye_result.log

mv /home/pi/scripts/dialeye/dialeye_result.txt /home/pi/scripts/dialeye/dialeye_result_previous.txt

#Take snapshot and read with Dialeye

fswebcam -r 640x480 --jpeg 95 /home/pi/images/dialeye.jpg

python /home/pi/scripts/dialeye/dialEye/dialEye.py -f /home/pi/scripts/dialeye/dialEye/dialEye.conf meter /home/pi/images/dialeye.jpg > /home/pi/scripts/dialeye/dialeye_result.txt

#post to Openhab via curl, read variable from text file

read -r -d '' str < <(cat /home/pi/scripts/dialeye/dialeye_result.txt)

curl --header "Content-Type: text/plain" --request POST --data $str http://192.168.1.45:8080/rest/items/Vedenkulutus

#Count average water 5 minute consumption and send to Openhab

read -r -d '' strold < <(cat /home/pi/scripts/dialeye/dialeye_result_previous.txt)

COUNT=`expr $str - $strold`

curl --header "Content-Type: text/plain" --request POST --data $COUNT http://192.168.1.45:8080/rest/items/Vedenkulutus_now

This results in Openhab with a total litres (according to the meter) and a 5 minute average.

Finally I configured the Cacti to read the Openhab REST API and draw Graphs from the data.

This is done similarly as in this post

Below are live graphs of water consumption and the webcam image of the water meter.