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"?>
            <DataRecord id="0">
                <Function>Instantaneous value</Function>
                <Unit>Fabrication number</Unit>
            <DataRecord id="1">
                <Function>Instantaneous value</Function>
                <Unit>Volume (m m^3)</Unit>

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.


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
  source: sensor.sensushri
  name: "Wasserverbrauch stündlich"
  cycle: hourly

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

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

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

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

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


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


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
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:


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:


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.


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.

I have a very similar setup as you, only using an esp32 to read mbus data and send mqtt info to the mqtt server running on my home nuc server. I have a bunch of other data gathered in a similar way (esp32 getting data through modbus through some other way (one wire, direct a2d sensors,… Esp 32 is super flexible but it’s arduino like so quite low level) and send to mqtt server then dispatched to home assistant… Works very well and i was pleasantly surprised to find the energy integration, i sent my electricity consumption (also gathered from my modbus meter) and got nice statistics without any effort…
now i hope water will be avaible soon, else i will use gas as a hack (no gas in my home)…
I add more and more sensors and activators in this way, it’s super cheap and flexible… Even if it demand some soldering and c programming skills, once you have it done once you can quite easily do crazy things…

@Glielens Is it possible to share code on ESP32/MBus integration? I am looking to do something similar with sending MBus data over MQTT.


Yes, in fact I would need to share my code on github or something… It’s not great clean code, but it can be useful. In the meantime i could send you code snippets :wink:

That would be great, thanks. I will also publish the code when it’s ready.

@Glielens - could you please share your ESP32 code for M-bus integration with me as well? Thank you.

Any idea how i can convert the values from m3 to L for use in the glance card for example?

Do i need to do this inside the utility_meter or later on a different location/code?

    source: sensor.watermeter_3c39e72d82ec_total_water_usage
    name: "Water usage hourly"
    cycle: hourly

    source: sensor.watermeter_3c39e72d82ec_total_water_usage
    name: "Water usage daily"
    cycle: daily