Water metering using Sensus HRI, libmbus, MQTT and Utility Meter integration

Recently I got a new water meter installed due to the German “Eichrecht”. While I never finished hooking up the old Cyble sensor I took this event to do so for the new Sensus HRI. I’ve found this sensor (Sensus HRI-B4/8L), matching my water meter, online and for local pick-up. Since both sensors are using M-Bus I could use the existing USB interface (USB - MBUS available at e.g. aliexpress).

Sensus HRI supports impulse reading as well NM-Bus protocol. Since I had the M-Bus interface I figured it is more reliable to use a proper protocol and the real data. :wink: Quick research revealed the following library: rSCADA - Raditex control systems / GitHub - rscada/libmbus: Meter-bus library and utility programs , which immediately worked! First you scan for devices and next up you can read the data of the specific device using its address-:

mbus-serial-request-data -b 2400 /dev/ttyUSB0 <deviceid>

<?xml version="1.0" encoding="ISO-8859-1"?>
        <MBusData>
            <SlaveInformation>
                <Id>xxx</Id>
                <Manufacturer>INV</Manufacturer>
                <Version>64</Version>
                <ProductName></ProductName>
                <Medium>Water</Medium>
                <AccessNumber>222</AccessNumber>
                <Status>00</Status>
                <Signature>0000</Signature>
            </SlaveInformation>
            <DataRecord id="0">
                <Function>Instantaneous value</Function>
                <StorageNumber>0</StorageNumber>
                <Unit>Fabrication number</Unit>
                <Value>xxx</Value>
                <Timestamp>2021-11-01T21:58:31Z</Timestamp>
            </DataRecord>
            <DataRecord id="1">
                <Function>Instantaneous value</Function>
                <StorageNumber>0</StorageNumber>
                <Unit>Volume (m m^3)</Unit>
                <Value>877</Value>
                <Timestamp>2021-11-01T21:58:31Z</Timestamp>
            </DataRecord>
        </MBusData>

I’ve explored a few more options around the library and possible usage, at the end I put it into a Docker container together with a Python based MQTT daemon. This process runs every minute reading the data from the sensor to put it as message onto my MQTT broker. I’m also using MQTT auto-discovery to not have to configure the sensor within Home Assistant. As a foundation for my own daemon I used miflora-mqtt-daemon Thanks to Thomas Dietrich!

Wtihin Home Assistant I know have a sensor which is using the device_class gas as water is not available. :scream: Unit of measurement is in liters, matching what I get from the physical sensor.

grafik

As you can see above, I’m always getting the total instead of impulses. This allows easy processing using the Utility Meter - Home Assistant integration:

# SensusHRI
water_hourly_sensushri:
  source: sensor.sensushri
  name: "Wasserverbrauch stündlich"
  cycle: hourly

water_daily_sensushri:
  source: sensor.sensushri
  name: "Wasserverbrauch täglich"
  cycle: daily

water_weekly_sensushri:
  source: sensor.sensushri
  name: "Wasserverbrauch wöchentlich"
  cycle: weekly

water_monthly_sensushri:
  source: sensor.sensushri
  name: "Wasserverbrauch monatlich"
  cycle: monthly

water_yearly_sensushri:
  source: sensor.sensushri
  name: "Wasserverbrauch jährlich"
  cycle: yearly

I’ve configured all cycles, which allows some interesting dashboards/graphs, e.g.

grafik

Based on the values of the utility meters I also added a markdown card with some calculations about costs per week, month, year:

grafik

With the ability to render Jinja templates in a markdown card I was able to put in all needed calculation for this summary.

type: markdown
content: >-
  Die Wasserkosten für:

  - die **aktuelle Woche** betragen **{{
  ((states('sensor.wasserverbrauch_wochentlich') | float / 1000) * 4.06) |
  round(2) }}** € 

  - den **aktuellen Monat** betragen **{{
  ((states('sensor.wasserverbrauch_monatlich') | float / 1000) * 4.06) |
  round(2) }}** € 

  - das **aktuelle Jahr** betragen **{{
  ((states('sensor.wasserverbrauch_jahrlich') | float / 1000) * 4.06) | round(2)
  }}** € 

  *Diese Berechnungen basieren auf dem Wasserpreis von 1,92€  je Kubikmeter und
  der  Schmutzwassergebühr von 2,14€ je Kubikmeter. Details auf [Hamburg
  Wasser](https://www.hamburgwasser.de/privatkunden/service/gebuehren-abgaben-preise).*
title: Kosten

I might be able to use another sensor/value to store the price, but since I’m not using it anywhere else I took the easy route.

My final dashboard looks like this:

I hope that gives some inspiration about how you use Home Assistant for water (or gas) metering and potential use-cases.

If you have ideas about what else to do with this data, let me know! :wink:

4 Likes

Thanks for sharing!

1 Like

Hi, thank you for your post! I just registered an account here to reply as I’m very interested in your solution. I’d like to ask for some more details hope you don’t mind:

  1. Which USB-MBUS interface do you have? Can you perhaps share a photo?
  2. Is it enough just to connect the pulse output to the USB-MBUS adapter and plugin to the server to read the numbers? Or do I need other special hardware?
  3. I don’t fully understand the software part (the link to Raditex control system is broken). What do I need and how do you setup the docker container to read and drop the MQTT message? Can you perhaps share the docker image?

My water meter is Sensus 620 and I think the model Sensus HRI-B4/8L also works. Do you know the meaning of 8L in the model number? There is also something called Sensus HRI-B4/D1.

Hi @Mai_Sun,

I’m using this black box (left one) which is available on aliexpress.com:

mbus

The one on the right might work as well, seems to be newer version.

For the M-Bus Gateway and the Sensus HRI-B4/8L it is ok to only connect the two wires, nothing else needed (for me). The HRIs provide both, MBus and Impulse. I didn’t had much luck using the impulse counter (connected to an ESPP), so I went with the digital MBus protocol.

About the software, I’m not able to share a Docker Image or the code as of right now. I’m still debugging some nasty MQTT behaviour in regard to discovery. Question really is if you need MQTT or, when directly connected, you can use another implementation to read the data (see GitHub - rscada/libmbus: Meter-bus library and utility programs).

About the different types of HRIs, you really need to check online for a documentation in your language. I see a lot of PDFs in German explaining the difference between the available types. Basically make sure the HRI fits to your water meter and that it is a D1 if you would like to measure in liters, as there are other versions measuring in steps of 100 liters.

Bests
Jens

Very nice post, thanks! Can you still add your real gas meter to the energy dashboard after applying your trick to setup the water sensor as device_class = gas? So can you have two gas meters? I presume you get the long term statistics for water as well with this setup?

Sure, because you can have every device as often as you want. The trick is not about using THE gas meter, it is only about the flow/volume of the gas meter as entity.