I’d like to share how I managed integrate an M-Bus connected water meter into HA. M-Bus or Meter-Bus is a specification for a serial bus and communication protocol that is popular for smart meters. These meters usually have long-lasting batteries (10 years+) that will last even longer when the meter can draw power from the bus. In this way the meter has a persistent counter value, and one doesn’t miss any counts, even if the meter is not read for a while.
Unfortunately most M-Bus interfaces are quite expensive, but a cost-effective solution is available for the Raspberry Pi as a so-called Hat from packom.net. They also provide a RESTful server mbus-httpd) that runs on the Raspi, which in turn can be integrated into HA via the rest platform. The RESTful server returns XML formatted meter data (in my case counted water volume, timestamp, etc.), without requiring any instructions. Apparently the M-Bus interface provides the server with all of this information.
I am running HA OS on a different Raspi than the one that runs the RESTful server. The respective part of my configuration.yaml looks roughly as follows:
# water meter
- platform: rest
resource: http://raspberrypi.home:8080/mbus/get/ttyAMA0/2400/0
method: POST
name: "water meter"
value_template: "{{ value_json.MBusData.DataRecord[0].Value | int }}"
unit_of_measurement: "l"
scan_interval: 60
The resource URL is straight from the mbus-httpd. I had to play around a bit with the proper value_template to extract the one value I am interested in from the JSON-converted XML. HA’s template test page was quite helpful in this respect.
I hope this may be helpful for others, too.