Turning analog water meters into a Home Assistant sensor

I’d like to share my small project that turns into a Home Assistant sensor: https://github.com/nohn/watermeter

3 Likes

That looks awesome! I’ve been thinking about how to do this exact same thing with our gas meter.

Thanks.

Gas would be easier. At least in Germany, gas meters send magentic impulses. You can easily read them out for example with a HMC5883L magnetometer. And even if not, I’ve never seen a gas meter with analog gauges. All, I’ve seen so far should easily be readble with OCR only.

It now has a configuration UI and optional JSON output.

Hi Sebastian, this looks awesome and something I really would like to try.

I have a fully functional Home Assistant instance running on an Intel NUC and I have multiple Raspberry Pi around the house to use. First I would like to duplicate what you have done though and later connect it to my current setup.

Could you give me some pointers on how to get started, I have read your readme file at Github but unfortunately it is not enough to get me to get going.

Are you running everything on the Raspberry Zero?

  • Raspberry Pi OS?
  • The camera (which one?) connected directly to the Raspberry Zero?
  • Home assistant?
  • Docker compose?
  • PHP?

The python code for controlling the LED and camera, where do I put that, it needs to be run at regular intervals?

Thanks for your patience.
Daniel

Hi Daniel,

this’ll take some time. I’ll post an update here, once it’s done. If you want to track progress, please watch https://github.com/nohn/watermeter/issues/34.

Thanks,
Sebastian

1 Like

This is cool. Possibly will work for something similar since it require an image for the readings.

@f00dagi please take a look at https://github.com/nohn/watermeter/tree/howto, if that helps you. If not, it would be great, if you could give more information in https://github.com/nohn/watermeter/issues/34 what you don’t actually understand.

1 Like

@f00dagi you’ll now find an extensive howto on https://github.com/nohn/watermeter/blob/710baebab32d1947c0b6aa57f039d10e99d13771/doc/HOWTO.md. If that still misses some details, please feel free to open new tickets on https://github.com/nohn/watermeter/issues stating, what parts need more information.

Just finished to get https://github.com/jomjol/AI-on-the-edge-device/wiki running. Wanted to let you know that all this can be accomplished on a esp32. Now looking for ways to make this available to HA…

Hi, integration to HA is interest also for me. Can be done via MQTT from Watermeter OS to Home Assistant?

Yes, this could be accomplished quite easily. I added mqqt sensors for total value and rate. The value I used as input for an utility meter to see consumption over a certain time range

Please, could you guide me? I set MQTT on ESP-CAM digitiser firmware (up address with port). I tried to add this IP address to HA but without successful result. What have I to do on digitiser ESP-CAM side and on HA side, please?

Thank you.

You can find information on how to get MQTT running here: MQTT - Home Assistant

This topic is specifically about https://github.com/nohn/watermeter. Please discuss things related to MQTT or configuring Home Assistant in general in the respective forums.

Hello Sebastian,

I have this running in docker getting images from a webcam that is pointed at my electricity meter.
While I have the impression all is working technically I do not get any numbers recognized.
Not an expert but think this might be because the numbers are white on a black background which seems to give problems for most OCRs.
I get the images directly from my webcam and don’t have the knowledge to change these (invert them) on the fly.

Any suggestions how to resolve?
Output (ps: the error occurs when pushing contrast higher)

Starting image

Thanks for any help,
Hans

Hi Hans,

I’ve added an option to invert the colors in the latest Docker release:

image

That should work for you.

Hi Sebastian,

thank you for the very swift response.

I pulled the new version however seems that setting the checkmark doesn’t stick when previewing or saving. It’s blanked out after such action and as such has no effect.
I tried also manually adding “digitInversion” (assuming this the name of the switch) in the config.php however this isn’t being loaded (probably the wrong name).

I’m working with Opera as browser and also tried with Chrome and Edge - same results.

Could you check?

Best regards,
Hans

Please update & try again.

WRT cropping: Can you please attach your original config & image to a Github issue (Issues · nohn/watermeter · GitHub)?

Sebastian,

Images are now getting recognized as Raw OCR, CleanOCR and Digital are showing the correct numbers…

image

However getting error probably prohibiting further processing and as such no lastValue is being set.

Fatal error : Uncaught DivisionByZeroError: Division by zero in /usr/src/watermeter/vendor/nohn/analogmeterreader/src/AnalogMeter.php:173 Stack trace: #0 /usr/src/watermeter/vendor/nohn/analogmeterreader/src/AnalogMeter.php(69): nohn\AnalogMeterReader\AnalogMeter->processImage(false) #1 /usr/src/watermeter/classes/Reader.php(152): nohn\AnalogMeterReader\AnalogMeter->getValue() #2 /usr/src/watermeter/classes/Reader.php(48): nohn\Watermeter\Reader->readGauges() #3 /usr/src/watermeter/public/configure.php(233): nohn\Watermeter\Reader->getReadout() #4 {main} thrown in /usr/src/watermeter/vendor/nohn/analogmeterreader/src/AnalogMeter.php on line 173

I tried to run without Gauge (as I don’t have one) and without Post Decimal Digits however then other warnings / errors are thrown.

> Warning** : Undefined array key "postDecimalDigit" in **/usr/src/watermeter/public/configure.php** on line **90
> Warning** : Undefined array key "gauge" in **/usr/src/watermeter/public/configure.php** on line **93

Resulting in

Fatal error** : Uncaught TypeError: Unsupported operand types: int - string in /usr/src/watermeter/classes/Reader.php:57 Stack trace: #0 /usr/src/watermeter/public/configure.php(233): nohn\Watermeter\Reader->getReadout() #1 {main} thrown in /usr/src/watermeter/classes/Reader.php on line **57

Best regards,
Hans

Sebastian,

noticed you had updated the container that allows nullyficaiton for post decial and gauge.
Loaded this and updated in line with comments of github, but still getting error.

> **Fatal error** : Uncaught TypeError: Unsupported operand types: int - string in /usr/src/watermeter/classes/Reader.php:59 Stack trace: #0 /usr/src/watermeter/public/configure.php(235): nohn\Watermeter\Reader->getReadout() #1 {main} thrown in **/usr/src/watermeter/classes/Reader.php** on line **59**

Thanks again for the effort.

Best regards,
Hans