Make water meter smart for 20 euros

Lese­dau­er 9 Minu­ten

I would like to moni­tor our water con­sump­ti­on, also to be war­ned in time enough in case of leaka­ge. But… our water meter is stu­pid! It does­n’t even have a magnet for a reed relay or a hol­der for a light barrier.

You can buy smart water meters for hund­reds of Euros and have the offi­cial water meter instal­led in the back for hund­reds of Euros again. For­tu­n­a­te­ly, the­re are resource­ful tin­ke­rers and geni­u­ses inte­res­ted in the com­mon good (from my point of view) who have coded some­thing tog­e­ther. So let’s make the water meter smart.

Who inven­ted it?

Jom­jol, for examp­le, is one such guy. He wro­te„Digi­ti­zer – AI on the edge – An ESP32 all inclu­si­ve neural net­work reco­gni­ti­on sys­tem for meter digi­tiz­a­ti­on”.

The pro­gram runs on a tiny ESP32 that has a built-in came­ra and is pro­bab­ly capa­ble of using arti­fi­cial intel­li­gence with its few mega­hertz. I don’t care how exact­ly it does it, but the result is abso­lute­ly fascinating! 🙂

„WELCOME (dra­ma­tic pau­se) TO THE FUTURE!”

Wow! I’ve always wan­ted to wri­te that!

IMG 20210311 154824 resized

An ESP32-CAM with a power sup­ply and pro­gramming modu­le. Wait… is that a pie­ce of lint in the upper left cor­ner? Yeah, that thing is real­ly small.

Whe­re to buy the ESP?

I got the ESP on eBay at jan­fried­ri­ch­elek­tro­nik­ver­sand(1). As bul­ky as the eBay name is, the good man is friend­ly and cour­te­ous. The set is cal­led „Star­ter­set HK-ESP32-CAM-MB | ESP32-CAM + OV2640 came­ra + CH340G USB2Serial” and cos­ts just 13 Euro with shipping.


But the came­ra on the board is set to a grea­ter distance than we need. So we have to score the glue with a scal­pel all around and turn the lens about 1/​4 turn coun­ter­clock­wi­se so that the came­ra can focus the dial of the water clock from a half­way accep­ta­ble distance.


We also need a simp­le, small micro USB power sup­ply with 500 mA (0.5 A, 2.5 watts) and a maxi­mum 16 GB microSD card. The total cost is about 21 Euros. Oh yes… a 3D prin­ter would be good. But you can also easi­ly and quick­ly build a hol­der for the water meter from a sui­ta­ble sewa­ge pipe (or rol­led card­board) and a pie­ce of card­board for the lid. I used PETG to print the hol­der that Jom­jol desi­gned for it. Unfor­tu­n­a­te­ly, I did­n’t have any black PLA in stock – but it should be black, other­wi­se the images will be overexposed.

IMG 20210311 181929 resized

Well, I’m not that much of a PETG prin­ter under the Lord. Does­n’t look so cool. But it works. Adden­dum: Jo, recent­ly prin­ted a spa­re part for my RC car and dro­ve 240 degrees. The result was abso­lute­ly gre­at! Loo­ked almost like carbon.

IMG 20210311 181941 resized

Yes, it loo­ks even sil­lier on the edges (bot­tom) of the parts, but I prin­ted the who­le thing strai­ght into the air without sup­port. Howe­ver, right when I tried it on the water clock, some of the „clips” bro­ke off. May­be I need to print hotter?

But let’s worry about the instal­la­ti­on first!

Well, it’s alrea­dy extre­me­ly fast. Much fas­ter and easier than I expec­ted. I have never held such an ESP32 in my hand, let alo­ne vapo­ri­zed it with a new firm­ware. The inst­ruc­tions are for a Debi­an Linux. I don’t use Win­dows sin­ce 2005. For Win­dows, howe­ver, the­re are pro­grams with a gra­phi­cal inter­face that do the same (only more awk­ward­ly) that I do under Ubun­tu with a few copied com­mand lines in a few seconds. Befo­re the Win­dows disci­ples have down­loa­ded their pro­grams from the net, instal­led and at the start, I’m alrea­dy long finis­hed 😉 So, for you swea­ty, mou­se pushing, virus-loving, secu­ri­ty-instal­ling and opti­miz­a­ti­on-tools-belie­ving Win­dows fan­boys: You need the Flash-Down­load-Tool from Expre­sif. Use it to dele­te the firm­ware of the ESP and reflash it with the firmware.bin from the link below. But Win­dows 10 also has the Powers­hell (start as admin!), which pro­vi­des Linux com­pa­ti­bi­li­ty. So you can also just replace „sudo apt-get install” with „npm install” I guess. But no idea if Win­dows has pip and esp­tool in the sources. You can post a com­ment below if that works. But honest­ly: With Win­dows you won’t get far in the smart home world. Just to flash Tuya devices OTA with Tas­mo­ta, you have to have a Linux at the start. You might as well switch com­ple­te­ly to Ubun­tu, you won’t have the stress of con­stant update restarts and you don’t need to be afraid of viru­ses and other mal­wa­re. The pro­grams (or simi­lar) you use are also avail­ab­le for Ubun­tu. And, hey, you are also com­ple­te­ly legal and don’t need to ste­al pro­grams any­mo­re. Gre­at, isn’t it? Down­load Firm­ware! https://​git​hub​.com/​j​o​m​j​o​l​/​A​I​-​o​n​-​t​h​e​-​e​d​g​e​-​d​e​v​ice Unzip in the down­loads direc­to­ry. Open ter­mi­nal! Install Pip! 

sudo apt-get install python3-pip

Install ESP-Tool!

sudo pip install esptool

ATTENTION: DO NOT install ESP-Tool from the packa­ge sources of the dis­tri­bu­ti­on! Chan­ge to the direc­to­ry of the loa­ded firmware! 

cd ~/Downloads/AI-on-the-edge-device-master/firmware/

Con­nect the ESP32 via USB to the com­pu­ter and: 

esptool erase_flash
esptool write_flash 0x01000 bootloader.bin 0x08000 partitions.bin 0x10000 firmware.bin
You get an error mes­sa­ge that the ESP­tool would not be present?
pip show -f esptool

Is the esp­tools direc­to­ry in your home?

sudo cp -r $HOME/esptool $HOME/.local/bin/

Still not working? Then we do it like this

sudo ~/.local/bin/esptool/ -p /dev/ttyUSB0 erase_flash
sudo ~/.local/bin/esptool/ write_flash 0x01000 bootloader.bin 0x08000 partitions.bin 0x10000 firmware.bin

But actual­ly the instal­la­ti­on should work flaw­less­ly. But not for me. 😛

For­mat a micro SD card with FAT32. For examp­le, with Gno­me Disks. In Down­load­s/AI-on-the-edge-device-mas­ter/sd-car­d/ adjust the file wlan.ini and save it again. Just enter the SSID and the pass­word of your network:
nano ~/Downloads/AI-on-the-edge-device-master/sd-card/wlan.ini

Chan­ge the fol­lowing lines:

ssid = "YOUR-SSID"
password = "YOUR-PASSWORD"


hostname = "waterclock"
gateway = "XXX.XXX.XXX.XXX"
netmask = ""

Copy the con­tent of the direc­to­ry „/​SDCard” to the empty SD card and insert it into the ESP32. Short test on the desk­top: Is the thing run­ning? The ESP32 needs only a few seconds to boot and to log on to the WLAN.

You can find out the IP address by loo­king for the net­work devices in your rou­ter, using the tool „Angry IP Scan”, or you were so smart (like me 🙂 )and gave the ESP a fixed IP in the wlan.ini. 😛 Open this IP in the browser!

It should open /setup.html (remem­ber this path, if you want to start the instal­la­ti­on later again) Good, that’s all we can do right now. Off to the base­ment! Fix the ESP on the hol­der and put both on the water meter.

The ESP does­n’t boot? You can’t find it on the network?

You read this more often on the forum! Accord­ing to the user pfried, it is best to use San­Disk Extre­me SD cards. He recom­mends the tool „San­Disk Res­cue­Pro Delu­xe”. But the licence key can only be found on the Extre­me card packaging.

I haven’t had such a pro­blem yet. Did I men­ti­on that I’m only run­ning Ubun­tu now…? no? So, if the ESP does­n’t run, plea­se try any fresh par­ti­tio­ned and for­mat­ted other SD cards (up to 16GB max). In my ESP the­re is a SD card with 8 GB from Toshiba.

Went on the first go. What I mes­sed up was a typo in the WLAN pass­word. This can also be the rea­son that the ESP can­not be found. Under Open­WRT, howe­ver, you can see in the over­view all devices that wan­ted to con­nect to the WLAN. With the frit, you have to rum­mage through the log.

  • (Wer­bung) hessburg affi cloud banner

Attach­ment on the water meter

Wasseruhr smart machen

Sits and wob­bles. Fits rather poorly.

Yes, Jom­jol did not reck­on with the fact that I lea­ve the pro­gramming modu­le on the ESP right away, so his cover does not fit over my ESP. But for three euros extra I pre­fer­red not to sol­der a USB power sup­ply together.

The abo­ve-men­tio­ned eBay dea­ler was also kind enough to mea­su­re the vol­ta­ge the pro­gramming board out­puts. It is 5V, which is good becau­se the ESP does not run reli­ab­ly with only 3.3V.

The only other thing it said was that the modu­le was not meant to be stuck on the ESP all the time. Well, not­hing gets warm, and the thing runs abso­lute­ly reli­able with me now for over four weeks in con­ti­nuous operation.

Of cour­se, this con­tra­dicts the pur­po­se of an ESP, if its GPI­Os are occu­p­ied, but I don’t need them. This is just a bet­ter webcam.

IMG 20210311 190456 resized e1615498964234

Fixed and pro­tec­ted the ESP from short cir­cuits with the fig leaf of armour tape.

In the sum­mer, the water clock will con­den­se and then ever­ything pro­bab­ly falls off anyway.

Sure, I could have desi­gned a lid for the ESP. I might do that some­day, but not now. Armour tape will have to do. Fur­ther­mo­re, the bra­cket did­n’t qui­te want to fit on the water clock. It’s kind of oddly shaped, so I used tape again to fix ever­ything rough­ly and very pro­vi­sio­nal­ly. May­be I’ll build mys­elf a sui­ta­ble base the­re, too.

Jom­jol has pro­vi­ded ever­ything inter­ch­an­ge­ab­le with bayo­net fas­te­ners so that you do not have to reprint the ent­i­re bra­cket when replacing.
But I wan­ted to see quick results!

Okay, you have the power sup­ply con­nec­ted to the ESP?


wasseruhr 01 resized

Wel­co­me. Unfor­tu­n­a­te­ly, I did­n’t take a screen­shot, but in the first dia­lo­gue you align the image hori­zont­al­ly. It is qui­te intui­ti­ve. First in rough steps, then finer. You can draw an auxi­li­a­ry line and align the edges of the digi­tal digits in one line, for examp­le. Set refe­rence points.

wasseruhr 03 resized

We mark two inva­ria­ble marks on the water clock so that the AI can ori­ent its­elf better.

wasseruhr 04 resized

Here I have cho­sen the cubic meters as the second refe­rence point.

wasseruhr 05 resized

We mark all digi­tal num­bers from left to right. This is done by drawing a frame over each digit with the mou­se. Child’s play. Plea­se pay atten­ti­on to the names and make sure that you dele­te super­fluous ROIs. This hap­pens quick­ly when you play around a bit. Final­ly, sim­ply call up each area again indi­vi­du­al­ly and check it. Don’t for­get to save with Save and con­ti­nue with Next.

wasseruhr 06 resized

The same game with the ana­lo­gue poin­ters. Here, howe­ver, from right to left, from lar­ge to small.

wasseruhr 07 resized

In the config.ini you still have to spe­ci­fy the MQTT ser­ver. mqtt://IP_OF_IOBROKER:1883 As MQTT user I have here… well, you see it. 😀 So, what? Nobo­dy can get into the net­work any­way, and I won’t want to have remo­te access either.
Update and continue.

wasseruhr 08 resized

Now you can reboot the sys­tem. This will take five seconds or so.

Inte­gra­ti­on in IOBroker

In ioBro­ker it con­ti­nues: Of cour­se, this is how it works with all other MQTT-enab­led (that is, all) Smar­tHome con­trol cen­ters like open­HAB and what they’­re all called.

wasser iob 3 resized

Befo­re you have instal­led the MQTT server/​client adap­ter in the IOBro­ker and matched it with the MQTT user­na­mes from the config.ini of the ESP. Or just after­wards. Does­n’t matter. 🙂

Wasser iob 1 resized

Now our coun­ter rea­ding appears under Objects, mqtt.0. Qui­te automagically! 🙂

wasser iob history resized

We click again on the small tool sym­bol and acti­va­te the record­ing by the histo­ry adap­ter. We had alrea­dy done this with the electri­ci­ty meter. Howe­ver, the­re is one small draw­back: The ESP is not that fast. It only mana­ges about one rea­ding every five minu­tes. But no mat­ter, that’s fine, it just does­n’t look that gre­at on the diagrams:

Strom und Wasser resized

Here the blue angu­lar water con­sump­ti­on com­pa­red to the fine dia­grams of the power con­sump­ti­on. This solu­ti­on is also inte­res­ting for wee­kend and vaca­ti­on homes. But I wro­te that alrea­dy in the arti­cle about the smart electri­ci­ty meter.

As a side note: You can also use this pro­ject to make an uns­mart electri­ci­ty meter smart! To accom­plish this, of cour­se, you have to build ano­t­her fix­tu­re and pos­si­b­ly live with the fact that the door of the meter box (the sub-dis­tri­bu­ti­on) no lon­ger closes.

  1. adver­ti­sing[]

Leave a comment

Ich bin mit der Datenschutzerklärung und der Speicherung meiner eingegebenen Daten einverstanden.