Hacky integration for M-Bus

@martgras this is great! could you build the same for M-bus? :slight_smile:

Didn’t know that m-bus is not modbus. Just saw register and got triggered :slightly_smiling_face:

3 Likes

I am using it via LAN; I cannot say something about the stability of wifi.

As of my understanding, this should not be a problem. You would have two masters (e.g. the Gateway; sorry they have no other word for this over at MBus) and one Slave (the meter; again MBus-Words). The Gateway queries the meters every x seconds.

It would be good, to have this for M-Bus (Meter Bus) too. The both standards (Modbus and M-Bus) are mixed up very often; so I tend to use the term “Meter Bus” for M-Bus.

I have integrated a gas meter to the M-Bus (Meter Bus) with an pulse reader and a pulse counter . Perhaps, this works for water meter as well. The equipment is quite expensive IMHO, but since I am not the electronic engineer, this was my way. It would be much better, when my gas provider would install a meter, that has a digital interface, but in 2021 they still install gas meters as in 1970 :-(.

I’ve linked a quite cheap (35 bucks) M-Bus solution using a cheap USB-M-Bus-Dongle in my blog I already mentioned before. There you only need to add a small bash script to cron that publishes the sensors found in a first run to MQTT and all you need to do is configuring it once in Home Assistant.

Here is the link to the blog post again (for the lazy ones):

If there is heavy interest in some ESP32 M-Bus master (e.g. to use it with ESPhome), I would put it on top of my list of projects to realize in the near future… But the quick and reliable solution is to use the USB-M-Bus-Master from aliexpress…

@the78mole thank you for sharing your solution.

/1./
My preference would really be to have an ESP32/ESPHome solution for reading M-bus meters.
Firstly, because the meters are physically located quite far away from my RPi, and I would not have to pull two m-bus wires all over my apartment.
Secondly - I have an HAOS installation on an RPi (Installation - Home Assistant) which is a managed OS, and I am not sure how to install third party software like libmbus on it.

So ESPHome would (hopefully) solve those two issues for me.

On that note, I have found another project (to the above Snedig’s), which has implemented it:

Have you checked it?
I am just not sure what are its limitations, would it work on other meters than listed, and would it work with an M-Bus Master module, instead of a Slave.

/2./
Since I am looking forward to connecting it to the ESP32, I have ordered an M-bus Master module with TTL serial port from Ali (17EUR): https://www.aliexpress.com/item/33009939864.html?spm=a2g0s.9042311.0.0.27424c4dlVSRON

In real life it looks like this:

However, I haven’t figured out yet if/how it supplies 30V power to the bus. I have hooked up 12VDC to VIN and GND, but I see 0 DC voltage on the MBUS terminals.
The poorly translated specs on Ali don’t say much:

" 7, M: MBUS bus interface, the initial high level bus 30 ± 1V(customizable)"

Messaging with the seller is fruitless because of the language barrier (or the lack of subject knowledge?).

On the other hand I see in the description of your device it states clearly:

  1. The module takes power from the USB port of the computer and boosts the internal voltage to 36V.

Maybe you happened to measure the voltage across the MBUS terminals of your module? Does it show ~30V right after you hook it up to the USB port? Or maybe it starts feeding 30V only after some event?

1 Like

Hi paulius,

first of all: Great finding!!! :slight_smile:

No, I didn’t stuble over this solution, even if I searched quite a bit for it…

And yes, I’ve measured the voltage on the M-Bus of my adapter (and did it right now again to make myself certain): It is exactly 30.0…30.1V

This part heavily looks like some simple Step-Up-Converter, but unfortunately, I can not read the exact IC part number. But the coil and the pin-count of the IC lead to this conclusion.

The larger 3-pin part on the left (with AGO naming) seems to be the Step-Up switch, which shortens the output coil pin to ground to store energy on the coil and then release it, to store the higher voltage on the Capacitor (10/50V VT). The diode SS16 is the output diode of the step-up (quite a chaotic design :rofl:)
The two resistors 203 (20K) and 303 (30K) could be selectable feedpack divider parts for changing the output voltage of the step-up converter to the two levels for TX = HIGH/LOW.

So, you should be able to apply e.g. 12V to Vin and you could measure the M-Bus-Voltage at the right pin of the large capacitor (should be 30V). If this is not the case, the step-up converter is not starting. You should find a datasheet for the IC and look out for enable signal, measure it and find the root cause, if it is deactivated.

If I would have a little more time, I could reverse-engineer the design quite easily with your nice foto shots, but unfortunately (as you can see from the time of my post), I’m currently under quite heavy load.

If you can get a more crispy shot of the little IC, I’ll do my best to support further. Some hint: Take the shot with flash and in an angle around 45 degree. The characters will light up when the angle is just right because of very different reflection properties of the ink and the case. Pictures from the top have often very low contrast.

I’ll already ordered one of these TTL-M-Bus master converters, since I’m planning to also get rid of some long M-Bus wires in my house. But it will be delivered around christmas :roll_eyes:

Hope you can report some success soon.

If we finish this successfully, I’ll extend my blog post (or write a second onw) for all to copy the solution, maybe with some more advanced own hardware.

Thanks for sharing also your findings. :kissing_heart:

Regards,
Daniel

1 Like

@the78mole, hi Daniel,

your response has given me the knowledge I did not have and inspired to search deeper for the reasons behind my problems.

In short - I got it working, huge thanks! :slight_smile:

The details of my journey:
/1. I checked the voltage on the capacitor as you suggested and got 28V there:

/2. Your text “If this is not the case, the step-up converter is not starting. You should find a datasheet for the IC and look out for enable signal, measure it and find the root cause, if it is deactivated.” has made me do the RTFM and I paid attention to this item in the specs of my MBUS-TTL module:

6, TTLVCC: TTL level voltage input, can not be left floating, you must input TTL level voltage

I have to say I had previously connected ONLY GND and VIN terminals to 14V, leaving others ‘floating’.
Needless to say, connecting all terminals (TTLVCC, RXD, TXD) has solved my problem and I started getting 27.5V on MBUS terminals!

/3. Then I installed libmbus as per instructions on your blog.
Scanning for connected devices gave some response, which gave hope that some communication is happening, but no meaningful results - i.e. no physical or secondary addresses:

paulius:~/libmbus$ mbus-serial-scan -b 2400 /dev/ttyUSB0
Collision at address 162
Collision at address 168
Collision at address 173
paulius:~/libmbus$ mbus-serial-scan -b 2400 /dev/ttyUSB0
Collision at address 55
paulius:~/libmbus$ mbus-serial-scan -b 2400 /dev/ttyUSB0
Collision at address 0
paulius:~/libmbus$ mbus-serial-scan-secondary -b 2400 /dev/ttyUSB0

I then did RTFM again - I checked the the specs of my heating meter Ista sensonic II mbus:

It gave me two pointers:
a. by long-pressing the button I can go to the third display loop and find out the M-bus address:

b. detailed info regarding baud rates:

This brought me to the function call:
paulius:~/libmbus$ mbus-serial-request-data -b 300 /dev/ttyUSB0 85

And soon thereafter came the response:

<?xml version="1.0" encoding="ISO-8859-1"?>
<MBusData>

    <SlaveInformation>
        <Id>16</Id>
        <Manufacturer>RKE</Manufacturer>
        <Version>105</Version>
        <ProductName>Ista sensonic II mbus</ProductName>
        <Medium>Heat: Outlet</Medium>
        <AccessNumber>226</AccessNumber>
        <Status>02</Status>
        <Signature>0000</Signature>
    </SlaveInformation>

[...]

Scanning for addresses with 300 baud rate gives results:

paulius:~/libmbus$ mbus-serial-scan -b 300 /dev/ttyUSB0
Found a M-Bus device at address 85


So now - the “only” thing left is to bring libmbus libraries to ESPHome? :smiley:

Once again big thanks for the guidance and hoping you can find some time for that new endeavor.

2 Likes

Hi paulius,

wow, a meter without a secondary address, must be from the century before the last :rofl:

I’m really happy to see your first problems solved. The migration to ESPhome should be not so hard, since M-Bus itself is quite an easy protocol (upwards the physical layer which get’s complex with more than three meters).

Unfortunately, the name of the step-up-converter did not lead to any result. There exist some MAX848 boost converter, but with a totally different footprint and the voltage output capability is far below the needed 30V. But in fact, it doesn’t matter… It’s a step-up and can be replaced easily with other solutions in an own design.

Regards,
Daniel

Hi paulius,

Could you please share a few more information about how you managed to connect to Ista Sensonic II? Did you disassemble to unit and soldier it? I have a similar sensor installed by our provider in the building, but as far as I am concerned it’s forbidden to change anything in this sensor.

Hi @liberostelios,

I disassembled the unit only because its battery died and I needed to supply it with fresh 3VDC :slight_smile:
After that it became a test unit, which I am playing with.

You don’t need to do that.

In the photo below you will see that my unit has 3 wires: No.1 and No.2 thicker ones are going to the temperature sensors; No.3 is the M-Bus wire, which you need to connect to:

Let me know if this helps, and I wish you happy experimenting :slight_smile:

Paulius

Thanks so much for the response! That’s pretty cool. Although in my case this cable is not loose, but goes to another component of Ista (called an Optosonic) which apparently stores the data and then transmits it wireless (I am assuming with wireless M-BUS).

As I am not supposed to touch any of this (all screws and stuff are sealed), at this point I am wondering if I can just join the wireless M-BUS network somehow and listen to it. Although I am really no expert here and just trying to figure out the basics.

Hi @liberostelios,

I found this about your mentioned Optosonic on p.34 of https://www.ista.com/fileadmin/twt_customer/countries/content/Tutorial/Documents/ista_symphonic.pdf:

The optosonic 3 radio net connects simply to
the optical interface of the heat meter, saves
the metered values and performs the radio
transmission. This means that heat meters
already installed can be easily integrated into
the radio system.

The “optical interface” part is a bit confusing to me - it doesn’t sound like an M-bus protocol.
But maybe your Optosonic is of a different version?

Do you really see the No.3 M-bus wire mentioned in my previous post going to the Optosonic module?
Maybe you can post a photo how it all looks in your case just out of curiosity.

But if indeed the only option for you is to connect to wireless-mBus, then I’d try to follow the instructions by @the78mole in the entry of this thread with a link to his blog where he talks about wmBus:

I haven’t done wmBus yet myself.

Best regards,

That’s a great point! I tracked the 3rd cable below the sensor and it seems to get lost inside the housing.

Given that nothing but the pipe sensor is below it and that if I go to the display entry 3D there is no M-BUS address (gives me a 0) I suspect that this is not connected to anything! I just don’t know how to get it out of there as it seems to be stuck.

wmBus seems another solution to explore. I haven’t noticed the blog posts before! Thanks for pointing that out. I’ll try to see what I can learn and do with this.

Assuming I manage to connect to Sensonic II have you succeeded in getting its info? Like what you can see in the display itself.

Check the wiring again - I cannot see it fully in your photo.
I.e. my M-bus wire is exiting the top head of the meter at one corner next to the temperature sensor wire:

Which wire is going to your Ista Optosonic device?

This is the XML I am receiving from the device - it contains 30 data records:

Summary
<?xml version="1.0" encoding="ISO-8859-1"?>
<MBusData>

    <SlaveInformation>
        <Id>16</Id>
        <Manufacturer>RKE</Manufacturer>
        <Version>105</Version>
        <ProductName>Ista sensonic II mbus</ProductName>
        <Medium>Heat: Outlet</Medium>
        <AccessNumber>226</AccessNumber>
        <Status>02</Status>
        <Signature>0000</Signature>
    </SlaveInformation>

    <DataRecord id="0">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Fabrication number</Unit>
        <Value>64651072</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="1">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Time Point (time &amp; date)</Unit>
        <Value>2021-09-06T01:38:00</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="2">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Volume (1e-1  m^3)</Unit>
        <Value>82925</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="3">
        <Function>Instantaneous value</Function>
        <StorageNumber>1</StorageNumber>
        <Unit>Volume (1e-1  m^3)</Unit>
        <Value>77278</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="4">
        <Function>Instantaneous value</Function>
        <StorageNumber>2</StorageNumber>
        <Tariff>0</Tariff>
        <Device>0</Device>
        <Unit>Volume (1e-1  m^3)</Unit>
        <Value>82925</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="5">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Tariff>1</Tariff>
        <Device>0</Device>
        <Unit>Volume (1e-1  m^3)</Unit>
        <Value>0</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="6">
        <Function>Instantaneous value</Function>
        <StorageNumber>1</StorageNumber>
        <Tariff>1</Tariff>
        <Device>0</Device>
        <Unit>Volume (1e-1  m^3)</Unit>
        <Value>0</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="7">
        <Function>Instantaneous value</Function>
        <StorageNumber>2</StorageNumber>
        <Tariff>1</Tariff>
        <Device>0</Device>
        <Unit>Volume (1e-1  m^3)</Unit>
        <Value>0</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="8">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Energy (100 Wh)</Unit>
        <Value>794919</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="9">
        <Function>Instantaneous value</Function>
        <StorageNumber>1</StorageNumber>
        <Unit>Energy (100 Wh)</Unit>
        <Value>751999</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="10">
        <Function>Instantaneous value</Function>
        <StorageNumber>2</StorageNumber>
        <Tariff>0</Tariff>
        <Device>0</Device>
        <Unit>Energy (100 Wh)</Unit>
        <Value>794919</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="11">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Tariff>1</Tariff>
        <Device>0</Device>
        <Unit>Energy (100 Wh)</Unit>
        <Value>0</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="12">
        <Function>Instantaneous value</Function>
        <StorageNumber>1</StorageNumber>
        <Tariff>1</Tariff>
        <Device>0</Device>
        <Unit>Energy (100 Wh)</Unit>
        <Value>0</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="13">
        <Function>Instantaneous value</Function>
        <StorageNumber>2</StorageNumber>
        <Tariff>1</Tariff>
        <Device>0</Device>
        <Unit>Energy (100 Wh)</Unit>
        <Value>0</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="14">
        <Function>Instantaneous value</Function>
        <StorageNumber>1</StorageNumber>
        <Unit>Time Point (date)</Unit>
        <Value>2020-12-31</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="15">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Time Point (date)</Unit>
        <Value>2021-12-31</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="16">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Volume flow (m m^3/h)</Unit>
        <Value>0</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="17">
        <Function>Maximum value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Volume flow (m m^3/h)</Unit>
        <Value>463</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="18">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Power (W)</Unit>
        <Value>0</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="19">
        <Function>Maximum value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Power (W)</Unit>
        <Value>5224</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="20">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Flow temperature (deg C)</Unit>
        <Value>0</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="21">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Return temperature (deg C)</Unit>
        <Value>0</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="22">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Temperature Difference (m deg C)</Unit>
        <Value>0</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="23">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>On time (hours)</Unit>
        <Value>0</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="24">
        <Function>Instantaneous value</Function>
        <StorageNumber>1</StorageNumber>
        <Unit>On time (days)</Unit>
        <Value>2620</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="25">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>On time (days)</Unit>
        <Value>5283</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="26">
        <Function>Instantaneous value</Function>
        <StorageNumber>5</StorageNumber>
        <Tariff>0</Tariff>
        <Device>0</Device>
        <Unit>Time Point (date)</Unit>
        <Value>2006-11-14</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="27">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Error flags</Unit>
        <Value>10</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="28">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Volume (my m^3)</Unit>
        <Value>9</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

    <DataRecord id="29">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Cold / Warm Temperature Limit ( degree C)</Unit>
        <Value>90</Value>
        <Timestamp>2021-11-26T14:04:59Z</Timestamp>
    </DataRecord>

Okay, that clarifies a lot. Apparently I am missing the 3rd cable. as in my installation there are only 2 black external cables at the corners + the one underneath.

The Optosonic is connected through the optical interface, which is basically some additional plug installed on the top of the sensor’s face:

So, I guess I am out of luck regarding a way to connect to this through M-BUS. I also did some digging regarding the wmbus that Ista uses and found some discussion about it on a German discussion list, but apparently everyone states the obvious, that even if you can manage to parse the data they are encrypted and unless the provider gives you the key (which I find impossible) you won’t be able to read it.

Too bad, I guess.

Hi liberostelios,

if you live in germany (EU schould be very similar), the provider must give you the encryption key and also needs to provide a standard way to get the data more often than on a yearly schedule.

See here (in german): Vermieter-Ratgeber

So the easiest way for many providers is allowing access to the wireless protocol e.g. by using OMS (wmBus) and handing out the encryption key.

Regards,
Daniel

1 Like

@the78mole - sorry for stepping in - this is very interesting, thank you for the reference.
On the other hand, can it be that this point:

  • From 2022, residents should receive consumption information during the year, provided that the necessary measuring technology is available in the house (new Annex VIIa, Para. 2).

… also means that your utility provider collects the data and provides it to the user in realtime / very frequently on their secure portal where you login and see it in “nice tables and charts”, but does not necessarily provide you the encryption keys?

On a different topic: is there any chance that you will consider coming back to the task of bringing libmbus features to ESPHome? :blush:

Hi paulius2k,

I believe, the provider will hand over the key. They are somehow forced to use a standardized wireless protocol, I believe. If you only get the data through some (nasty) WebUI, you could still use a scraper to pull the data into your smart home. Using e.g. node-red, this is quite easy. I already done this with the EPEX market data, which was also forced to be public (provided as a website), and an API only paying parties. So I simply implemented a scraper for their website to pull in the data. But for me, it’s just a second source beside aWATTar, which provide a public API for the same piece of data for germany and austria free of charge.

And for the M-Bus, yes, it really could be, that I continue with the M-Bus in ESPhome. Currently, I’m training my ESPhome skills (Custom Components with C++) with my Buderus KM271 project.

But as soon as I finish this, I’ll step back to the M-Bus topic. First bringing M-Bus in general to life with the TTL-to-M-Bus controller (old naming: master) module I have received lately and the designing my own M-Bus controller with more than just a single digit number of M-Bus responder (prev. slave). Since I have a full time job, a family with two children and also a small company beside, my time is quite limited… Nevertheless, this is my hobby and I love to spend time on it :slight_smile:

Regards,
Daniel

4 Likes