{"id":4414,"date":"2017-07-04T18:00:29","date_gmt":"2017-07-04T17:00:29","guid":{"rendered":"http:\/\/www.marshflattsfarm.org.uk\/wordpress\/?p=4414"},"modified":"2017-07-16T13:13:01","modified_gmt":"2017-07-16T12:13:01","slug":"m-bus-water-meter-readings","status":"publish","type":"post","link":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/?p=4414","title":{"rendered":"M-Bus Water Meter Readings"},"content":{"rendered":"<p>In addition to the usual supply meters, there are a set of sub-meters in the house to report on particular aspects of resource consumption:<\/p>\n<ul>\n<li>Water Meters, to assess how the water usage is broken down (e.g. hot water versus cold water)\n<ul>\n<li>One on the incoming cold water main<\/li>\n<li>One on the separate incoming cold main which supplies the WCs, washing machine and outside taps and might, in future, be connected to a rainwater harvesting system<\/li>\n<li>One on the cold supply pipe to the domestic hot water cylinder\n<ul>\n<li>This measures hot water usage based on the cold water used to top-up the cylinder as the hot water is used (it is generally better to meter \u00a0cold water than hot water)<\/li>\n<li>This water also flows through the &#8220;incoming cold water main&#8221; meter so needs to be subtracted from that to calculate the cold water consumption<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>Heat Meters, to enable the real-world <a href=\"https:\/\/en.wikipedia.org\/wiki\/Coefficient_of_performance\" target=\"_blank\" rel=\"noopener\">Coefficient of Performance<\/a> of the Ground Source Heat Pump to be measured\n<ul>\n<li>One on the Central Heating output from the GSHP<\/li>\n<li>One on the Water Heating output from the GSHP (likely to be a lower CoP because of the higher temperatures required)<\/li>\n<\/ul>\n<\/li>\n<li>Electricity Meters, to assess the consumption of some high-usage appliances<\/li>\n<\/ul>\n<p>While it&#8217;s perfectly possible to read these meters manually (which is what I have been doing, on the first day of every month) the plan was always to read them automatically and to log the usage on a much more frequent basis. In line with my policy of using non-proprietary standards with good Open Source software support I settled on using the\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Meter-Bus\" target=\"_blank\" rel=\"noopener\">Meter-Bus<\/a>\u00a0standard (usually abbreviated to M-Bus, not to be confused with <a href=\"https:\/\/en.wikipedia.org\/wiki\/Modbus\" target=\"_blank\" rel=\"noopener\">Modbus<\/a>) to do this and hence specified \/ purchased meters with M-Bus interfaces.<\/p>\n<p>(Actually, most of the Electricity meters don&#8217;t have M-Bus interfaces since those only seem to be available on the higher-capacity meters &#8211; 80A or so &#8211; and they attract a very high price premium. For the low-current sub-meters I used small DIN-Rail mounting meters with S0 pulse outputs rather than M-Bus interfaces, on the basis that it was better to have a simple meter than no meter at all.)<\/p>\n<p>I cover a lot of the technical aspects of M-Bus on my\u00a0<a href=\"http:\/\/www.marshflattsfarm.org.uk\/wordpress\/?page_id=1864\" target=\"_blank\" rel=\"noopener\">M-Bus Meter Data Collection<\/a>\u00a0Page so see that for more details. The event that prompted this Post is that I&#8217;ve <em>just<\/em> got the water meter data collection working. It took me an embarrassingly long time to spot that the Itron Aquadis water meters were initially supplied with Pulse-Counting Cyble modules rather than M-Bus Cyble modules and once that was corrected it took a while to get the right version of the software needed to configure those. Kudos to the team at <a href=\"https:\/\/www.mwatechnology.com\" target=\"_blank\" rel=\"noopener\">MWA Technology<\/a>\u00a0in Birmingham for helping me out (and no thanks to Itron for being thoroughly unhelpful &#8211; they only seem to want to deal with their big distributors).<\/p>\n<p>I&#8217;ve found the best way to talk to an M-Bus meter from Linux is using the <a href=\"http:\/\/www.rscada.se\/libmbus\/\" target=\"_blank\" rel=\"noopener\">libmbus<\/a> software. Basically this provides two data access mechanisms:<\/p>\n<ul>\n<li>Using the generic\u00a0<tt>mbus-serial-request-data<\/tt> utility to dump out all the data from a meter to an XML data string<\/li>\n<li>Using the libmbus C API functions directly in your own code to grab the relevant subset of the data<\/li>\n<\/ul>\n<p>I briefly toyed with the idea of writing a Perl module to map the C API to Perl so I could call it directly from a Perl script and then I wrote a simple C program to grab a limited set of data using the C API. However, in the end, I decided it was better to go down the XML route and to parse the full XML output string to extract the necessary data fields. I&#8217;ve written a Perl script which runs continuously (on the Raspberry Pi connected via an RS-232 interface to the M-Bus protocol converter) and extracts the data from all the M-Bus meters every few minutes. It then publishes the readings as messages using <a href=\"https:\/\/en.wikipedia.org\/wiki\/MQTT\" target=\"_blank\" rel=\"noopener\">MQTT<\/a>\u00a0from where they follow the same route of logging and graphing used for other monitoring (Telegraf -&gt; InfluxDB -&gt; Grafana).<\/p>\n<p>Some observations:<\/p>\n<ul>\n<li>The request to read the M-Bus data seems to fail on a fairly regular basis (10-20% of the time) so the script needs to check for that and re-run the query until a response is received from each meter<\/li>\n<li>The water meters report usage units of whole litres only (listed as milli cubic metres in the M-Bus response) which seems like quite a&#8221;chunky&#8221; response compared to some of the other meter readings<\/li>\n<li>I found it was best to subtract the hot water reading from the cold water reading within the script and to create a further virtual meter for the difference (i.e. the actual cold water consumption)<\/li>\n<li>I&#8217;m still working on how often to grab the data (currently every 2 minutes) and how best to present it (currently graphed as a &#8220;derivative&#8221; value of litres \/ minute)<\/li>\n<\/ul>\n<p>An example of the full XML response from one of the Itron Aquadis water meters with an <a href=\"https:\/\/www1.itron.com\/local\/Poland%20Product%20Portolio\/GA-CYBLEMBUSSTD-01-EN-10-14.pdf\" target=\"_blank\" rel=\"noopener\">M-Bus Cyble communications module<\/a> installed is shown below. Only the block highlighted in bold is really of interest (and actually it&#8217;s only the Value of 20312 which changes &#8211; that&#8217;s the same as displayed on the meter readout).<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"ISO-8859-1\"?&gt;\r\n&lt;MBusData&gt;\r\n\r\n &lt;SlaveInformation&gt;\r\n     &lt;Id&gt;17003877&lt;\/Id&gt;\r\n     &lt;Manufacturer&gt;ACW&lt;\/Manufacturer&gt;\r\n     &lt;Version&gt;20&lt;\/Version&gt;\r\n     &lt;ProductName&gt;Itron CYBLE M-Bus 1.4&lt;\/ProductName&gt;\r\n     &lt;Medium&gt;Water&lt;\/Medium&gt;\r\n     &lt;AccessNumber&gt;23&lt;\/AccessNumber&gt;\r\n     &lt;Status&gt;00&lt;\/Status&gt;\r\n     &lt;Signature&gt;0000&lt;\/Signature&gt;\r\n &lt;\/SlaveInformation&gt;\r\n\r\n &lt;DataRecord id=\"0\"&gt;\r\n     &lt;Function&gt;Instantaneous value&lt;\/Function&gt;\r\n     &lt;StorageNumber&gt;0&lt;\/StorageNumber&gt;\r\n     &lt;Unit&gt;Fabrication number&lt;\/Unit&gt;\r\n     &lt;Value&gt;17003877&lt;\/Value&gt;\r\n     &lt;Timestamp&gt;2017-06-30T08:03:19&lt;\/Timestamp&gt;\r\n &lt;\/DataRecord&gt;\r\n\r\n &lt;DataRecord id=\"1\"&gt;\r\n     &lt;Function&gt;Instantaneous value&lt;\/Function&gt;\r\n     &lt;StorageNumber&gt;0&lt;\/StorageNumber&gt;\r\n     &lt;Unit&gt;cust. ID&lt;\/Unit&gt;\r\n     &lt;Value&gt;0A\u00a0 \u00a0 \u00a0 \u00a0 &lt;\/Value&gt;\r\n     &lt;Timestamp&gt;2017-06-30T08:03:19&lt;\/Timestamp&gt;\r\n &lt;\/DataRecord&gt;\r\n\r\n &lt;DataRecord id=\"2\"&gt;\r\n     &lt;Function&gt;Instantaneous value&lt;\/Function&gt;\r\n     &lt;StorageNumber&gt;0&lt;\/StorageNumber&gt;\r\n     &lt;Unit&gt;Time Point (time &amp;amp; date)&lt;\/Unit&gt;\r\n     &lt;Value&gt;2017-06-30T09:02:00&lt;\/Value&gt;\r\n     &lt;Timestamp&gt;2017-06-30T08:03:19&lt;\/Timestamp&gt;\r\n &lt;\/DataRecord&gt;\r\n\r\n &lt;DataRecord id=\"3\"&gt;\r\n     &lt;Function&gt;Instantaneous value&lt;\/Function&gt;\r\n     &lt;StorageNumber&gt;0&lt;\/StorageNumber&gt;\r\n     &lt;Unit&gt;bat. time&lt;\/Unit&gt;\r\n     &lt;Value&gt;5352&lt;\/Value&gt;\r\n     &lt;Timestamp&gt;2017-06-30T08:03:19&lt;\/Timestamp&gt;\r\n &lt;\/DataRecord&gt;\r\n\r\n<strong> &lt;DataRecord id=\"4\"&gt;\r\n     &lt;Function&gt;Instantaneous value&lt;\/Function&gt;\r\n     &lt;StorageNumber&gt;0&lt;\/StorageNumber&gt;\r\n     &lt;Unit&gt;Volume (m m^3)&lt;\/Unit&gt;\r\n     &lt;Value&gt;20312&lt;\/Value&gt;\r\n     &lt;Timestamp&gt;2017-06-30T08:03:19&lt;\/Timestamp&gt;\r\n &lt;\/DataRecord&gt;<\/strong>\r\n\r\n &lt;DataRecord id=\"5\"&gt;\r\n     &lt;Function&gt;Instantaneous value&lt;\/Function&gt;\r\n     &lt;StorageNumber&gt;0&lt;\/StorageNumber&gt;\r\n     &lt;Unit&gt;Volume (m m^3)&lt;\/Unit&gt;\r\n     &lt;Value&gt;0&lt;\/Value&gt;\r\n     &lt;Timestamp&gt;2017-06-30T08:03:19&lt;\/Timestamp&gt;\r\n &lt;\/DataRecord&gt;\r\n\r\n &lt;DataRecord id=\"6\"&gt;\r\n     &lt;Function&gt;Instantaneous value&lt;\/Function&gt;\r\n     &lt;StorageNumber&gt;1&lt;\/StorageNumber&gt;\r\n     &lt;Unit&gt;Volume (m m^3)&lt;\/Unit&gt;\r\n     &lt;Value&gt;0&lt;\/Value&gt;\r\n     &lt;Timestamp&gt;2017-06-30T08:03:19&lt;\/Timestamp&gt;\r\n &lt;\/DataRecord&gt;\r\n\r\n &lt;DataRecord id=\"7\"&gt;\r\n     &lt;Function&gt;Manufacturer specific&lt;\/Function&gt;\r\n     &lt;Value&gt;00 01 1F&lt;\/Value&gt;\r\n     &lt;Timestamp&gt;2017-06-30T08:03:19&lt;\/Timestamp&gt;\r\n &lt;\/DataRecord&gt;\r\n\r\n&lt;\/MBusData&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In addition to the usual supply meters, there are a set of sub-meters in the house to report on particular aspects of resource consumption: Water Meters, to assess how the water usage is broken down (e.g. hot water versus cold &hellip; <a href=\"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/?p=4414\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82,12],"tags":[],"class_list":["post-4414","post","type-post","status-publish","format-standard","hentry","category-metering","category-services"],"_links":{"self":[{"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4414","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4414"}],"version-history":[{"count":5,"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4414\/revisions"}],"predecessor-version":[{"id":4426,"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4414\/revisions\/4426"}],"wp:attachment":[{"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}