AI solution for analog water meter

Hi all,
since a long time i was looking for a solution to measure my water consumption.
Because i have an old classical analog water meter i didn’t found an solution.
Last week i found this fancy solution which i really like. It is based on ESP32CAM and the developer has designed the needed housings for 3d-printing as well.

Integration into Homeassistant goes via mqtt.
Have fun.

8 Likes

I have read something similar before. Yes this type of projects certainly are interesting:

OCR on camera image for water / electricity meter - Configuration - Home Assistant Community (home-assistant.io)
OCR for analog meter using opencv - Third party integrations - Home Assistant Community (home-assistant.io)

Why is your previous value greater than current value?

i made some adjustments played around with some config values. :wink:

Mqtt didnt work for me, could you share your mqtt Config?

  • platform: mqtt
    name: “wasserzaehler”
    state_topic: “wasserzaehler/main/value”
    qos: 0
    unit_of_measurement: ‘m3’
    icon: “mdi:water”
1 Like

Did MQTT works now for you?

I get values with the letter N for example N1234.53N2
How can I clean this values? To get a realy integer or float value?

Hi, it looks to you like the AI is having trouble recognizing the numbers he is displaying with an N. Try to create a new reference image and create a new reference for the single numbers. If that doesn’t help, try another tflite file directly in the web browser of the AI, you can select it in the advanced configuration.

I have used this for an electricity meter. With analogue dials it took a bit of playing with on the size of the boxes used; I found that bigger than you think was better, but it really was about fine tuning to remove N - but across all numbers. Our meter was changed to a digital, non smart, one and recognition became more tricky and irreproducible. The eventual fix to make it more stable was to add an LED strip to fully illuminate all numbers consistently.

I get relatively good results via node red and a filter to stop increases due to 1 being recognised as 7 for example.

I don’t rely on the actual numbers anymore as the glow pulse monitor for electricity meters I find better, but use the camera based readings as a check - if/when an issue with the glow connection drops then the numbers are out, but one sensible AI reading in the morning and one in the evening is a good sanity check.

Tldr: needs playing with and does not work out of the AI box.

Any idea why I can’t get the last digit right?

Because your blue rectangle is way too big and because its rotated up and the top of the 5 is too close to the white part, it should be an NaN.

As long as your pre-value is set correctly it shouldn’t matter. the N will be replaced with whatever is in your pre-value for that digit.

if you are still having issues when it is in the middle try using a different tflite file, but dont do it when the 5 is so close to the top… just wait

Was just thinking about this again and remembered the challenges I had setting all this up so here are a few things that some using this Jomjol AI thing may find useful.
this is what my panel looks like


starting with getting the data into home assistant, they probably aren’t all needed… but I have more than enough space on the hard drive.

mqtt:
  sensor:
    - name: Watermeter_reading
      unique_id: a220223801
      unit_of_measurement: "L"
      state_class: total_increasing
      state_topic: "WaterMeter/main/value"
    - name: Watermeter_error
      unique_id: a220223802
      state_topic: "WaterMeter/main/error"
    - name: Watermeter_json
      unique_id: a220223803
      state_topic: "WaterMeter/main/json"
    - name: Watermeter_RSSI
      unique_id: a220223804
      unit_of_measurement: "dB"
      state_topic: "WaterMeter/wifiRSSI"
    - name: Watermeter_Timestamp
      unique_id: a220223805
      state_topic: "WaterMeter/main/timestamp"
    - name: Watermeter_Raw
      unique_id: a220223806
      unit_of_measurement: "L"
      state_topic: "WaterMeter/main/raw"

using the watermeter MQTT message to trigger an automation to download the image from the watermeter, this triggers even on miss reads making it useful with the logs off the device to see what’s happening

alias: watermeter picture
description: ''
trigger:
  - platform: mqtt
    topic: WaterMeter/main/json
condition: []
action:
  - service: downloader.download_file
    data:
      url: http://192.168.1.60/img_tmp/alg_roi.jpg
      subdir: watermeter
      filename: >-
        {{ states('sensor.watermeter_timestamp') | replace ( ':' , '-' )
        }}_RAW-{{ states('sensor.watermeter_raw')
        }}_Value-{{states('sensor.watermeter_reading')}}.jpg
  - service: downloader.download_file
    data:
      url: http://192.168.1.60/img_tmp/alg_roi.jpg
      filename: latest_reading.jpg
      overwrite: true
mode: single

theres a few things to add to configuation.yaml to do this, under homeassistant i needed to add media_dirs: to allow me to browse old images easily from the frontend

homeassistant:
  media_dirs:
    watermeter: "/config/downloads"

for the downloader in the automation i needed to add this

downloader:
  download_dir: downloads

so that the folder doesnt fill up too much i clear it out using a shell command

shell_command:
  remove_watermeter_images: 'find /config/downloads/watermeter/* -mtime +3 -exec rm {} \;'

notice in the automation there is 2 downloads, one has a time date stamp, the other is latest_reading.jpg well i use this to have a have a camera on my dashboard always showing the latest image

camera:
  - platform: local_file
    file_path: /config/downloads/latest_reading.jpg
    name: watermeter_image

i also like to have a few utility meters setup too,

utility_meter:
  quaterhour_water:
    source: sensor.watermeter_reading
    cycle: quarter-hourly
    tariffs:
      - peak
  daily_water:
    source: sensor.watermeter_reading
    cycle: daily
    tariffs:
      - peak
  monthly_water:
    source: sensor.watermeter_reading
    tariffs:
      - peak

and the lovelace panel i have setup to display the info

type: vertical-stack
cards:
  - hours_to_show: 24
    graph: line
    type: sensor
    entity: sensor.daily_water_peak
    detail: 2
    name: Water Today
  - type: entities
    entities:
      - entity: sensor.watermeter_reading
        name: Water Meter Reading
        secondary_info: last-updated
        icon: mdi:counter
      - entity: sensor.watermeter_error
        name: Error State
        icon: mdi:water-alert
      - entity: sensor.watermeter_rssi
        name: RSSI
        icon: mdi:signal-cellular-1
      - entity: sensor.watermeter_json
        name: Raw
        secondary_info: last-changed
  - show_state: false
    show_name: false
    camera_view: auto
    type: picture-entity
    entity: camera.watermeter_image
    tap_action:
      action: none
    hold_action:
      action: none
2 Likes

A question, would it be possible to configure this for the TTGO T-Journal Camera edition without SD Card?

If the data would be directly sent to the Docker server, would that not be an option?
Just wondering.
Thanks for the feedback :slight_smile:

hi guys,

thanks to this topic i got it working. i started with my gas meter.
gas1

now only looking how i can integrate it with the enegry dashboard within home assistant? i can’t select my gas meter within the dashboard?

Hi Everyone,

Would like to share with you a Science paper which was published very rencently (in december) about this use-case using Deep-Learning and the YOLOv5 Model :

I couldn’t find if they published their model, but I guess that’s interesting to look at. What do you think ?

Hi all
Is there a way online to use AI-on-the-edge-device to check a picture of mine (coming from water counter) before buying everything ?
For instance this picture

Regards

sure, you can doit,
what’s your problem?

actually, i did some tests today with some picture of my water counter .
i tested with a raspberry pi and OCR called tesseract.
It was not possible to catch the digits coming from a picture with OCR Solution.
I don’t have any ESP32-CAM available, and i wonder if AI-on-the-edge is more powerfull than OCR.
To let you know, considering that my water counter is located outside, in a concrete box, so in the dark
i wonder if it is possible to use AI-on-the-edge in that condition
Thx for your advices

sorry, but you should read the documentation of this project first.

the solution uses the ESP32CAM with an integrated led. usage in darkness is ok.

i use this solution for a gas and a watermeter.

The ESP32Cam features an onboard LED, so dark places shouldn’t matter
Also, the firmware uses a trained Tensorflow network to do OCR, so it should be capable of reading these just fine.
Also, you must align the ESP32Cam properly before it can read sucessfully. That’s why people are 3D printing enclosures that plop it right above the meter itself.