esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
420 stars 26 forks source link

M-Bus support #1646

Open poear opened 2 years ago

poear commented 2 years ago

Describe the problem you have/What new integration you would like I have a energy meter installed in my house that exposes its data via M-Bus. I would like to see support for reading values over M-Bus. Since M-Bus, supposedly, is used for many kinds of utility meters this might be useful to a lot of people in Europe. I'm looking for some guidance on how to continue. I'm a bit lost or stuck. If anyone has some input or

Please describe your use case for this integration and alternatives you've tried: I want to enable users to easily add new components for M-Bus meters.

Using M-Bus Master hardware (MIKROE-3880 looks promising, or DIY version) and code supporting communication with M-Bus like libmbus. Adding support for a new meter should be limited to implementing the manufacturers protocol.

Alternatives: I have not tried anything else.

Additional context Wikipedia says M-Bus or Meter-Bus is a European standard (EN 13757-2 physical and link layer, EN 13757-3 application layer) for the remote reading of water, gas or electricity meters. M-Bus is also usable for other types of consumption meters, such as heating systems or water meters. The M-Bus interface is made for communication on two wires, making it cost-effective. A radio variant of M-Bus Wireless M-Bus is also specified in EN 13757-4.

The M-Bus was developed to fill the need for a system for the networking and remote reading of utility meters, for example to measure the consumption of gas or water in the home. This bus fulfills the special requirements of remotely powered or battery-driven systems, including consumer utility meters. When interrogated, the meters deliver the data they have collected to a common master, such as a hand-held computer, connected at periodic intervals to read all utility meters of a building. An alternative method of collecting data centrally is to transmit meter readings via a modem.

Other applications for the M-Bus such as alarm systems, flexible illumination installations, heating control, etc. are suitable.

github-k8n commented 2 years ago

Dumping some information here as this was a bit difficult to find and maybe might help someone looking for this.

At the moment I am using a raspberry pi to read out the data from a UART IR head (same the ones used for the electricity meters used with SML) connected to the heat meter (SENSUS Pollustat) using pyMeterBus https://github.com/ganehag/pyMeterBus/ and sending the data on via MQTT (using paho-mqtt) taking inspiration from the scripts here: https://forum.iobroker.net/topic/32722/smart-meter-sensus-pollucom-e/4 (note the initial wakeup sequence for these kind of meters) , however it would be great if there were a way to incorporate this somehow in esphome. (read-only as pyMeterBus does might be a good start?)

Maybe if someone could refactor the code from pyMeterBus into C to make it usable as a module in esphome?

(of course, full support of M-Bus with all the bells and whistles might be even better :)

Aikawa24 commented 2 years ago

some guy on https://www.mikrocontroller.net/topic/113984

make this code to read the pollucom E via opto ir

`#include

include

include <sys/stat.h>

char buf; char in[256] = ""; ssize_t ret_out; int fd = open ("/dev/ttyUSB0", O_RDWR | O_NOCTTY ); set_interface_attribs (fd, B2400, 0); // set speed to 2,400 bps, 8n1 (no parity) set_blocking (fd, 0 ); // set no blocking strcpy( in, "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU"); ret_out = write (fd, in, strlen(in)); // sent wakeup usleep ((1000 + 25) 100); // sleep enough to transmit plus buf = read_data( fd); // Initialisiere MBus -> ACK mit 'E5' in[0] = 0x10; in[1] = 0x40; // Init MBus in[2] = 0x00; in[3] = 0x40; // Checksumme = in[1] + in [2] in[4] = 0x16; ret_out = write (fd, in, 5); // sent usleep ((1000 + 25) 100); // sleep enough to transmit plus buf = read_data( fd); if (buf[5] == 0xE5) { // Get Data from MBus in[0] = 0x10; in[1] = 0x5B; // GetData in[2] = 0x00; in[3] = 0x5B; // Checksumme = in[1] + in [2] in[4] = 0x16; ret_out = write (fd, in, 5); usleep ((1000 + 25) 100); // sleep enough to transmit plus buf = read_data( fd); // Zaehlerstand double waerme = ((double) toInt(&buf[26])) + (100.0 (double) toInt(&buf[27])) + (1000.0 (double) toInt(&buf[28])) + (10000.0 (double) toInt(&buf[29])); //aktuelle Leistung double leistung = ((double) toInt(&buf[44])) + (100.0 (double) toInt(&buf[45])) + (1000.0 (double) toInt(&buf[46])) + (10000.0 (double) toInt(&buf[47])); }

int toInt( char *in ) {

char out[2]; int iOut = 0; sprintf(out, "%02x", in[0]); iOut = atoi(out); return iOut; }`

karllinder commented 2 years ago

Hi

Looks like there is some need for this, this is what @turbokongen has solved in HA https://github.com/turbokongen/hass-AMS

There is also a mbus.h that I use, not working 100%, taken from this post: https://www.hjemmeautomasjon.no/forums/topic/5141-han-til-home-assistant-over-esphome/

wmeler commented 1 year ago

One more interesting link https://github.com/dev-lab/esp-iot-mbus

bf8392 commented 1 year ago

+1 for (W)M-Bus Support

RogMoe commented 1 year ago

yep, would be great to have (wired)Mbus support!

bf8392 commented 1 year ago

yep, would be great to have (wired)Mbus support!

Wm-bus means wireless m-bus :-) but it would be best to have support for both... someone made a "hacky" integration..maybe it helps for the standard integration... https://community.home-assistant.io/t/hacky-integration-for-m-bus/127288/14

RogMoe commented 1 year ago

MBus-master adapters<>USB are very cheap and failsafe. I prefer hardwired instead of wireless. Reason for asking: I have three Kamstrup heat meters (2x 601, 1x 403) installed to measure solarboiler/vacuumtubes, pelletheater and hotwater-consumption. All three meters have MBus (wired). I configured all three meters with different addresses using Kamstrps software and optical adapter. Now I want to get all data to show up in HA using one Mbus master<>USB adapter... (it works fine on windows)

mortenx commented 7 months ago

+1 for MBus Support

kluszczyn commented 5 months ago

There is custom component based on CC1101 transceiver implementing WMBus reader https://github.com/SzczepanLeon/esphome-components

luka6000 commented 4 months ago

There is custom component based on CC1101 transceiver implementing WMBus reader https://github.com/SzczepanLeon/esphome-components

I'm also using this with great success for electricity, heat and water meters (total 4 independent meters with multiple data points). It can be used standalone or with wmbusmeters add-on in HA (passing raw decrypted datagrams - how awesome is that!) Buy frankly speaking I don't like this component implementation. It works great but it's purpose built all-in-one. @jesserockz what would you suggest? Wireless M-bus implementation requires receiver component (like CC1101), then protocol implementation (M-bus) and then meters definition with specific attributes/sensors. Would you accept such a all-in-one approach or should it be rebuilt with layers?

Nappyy commented 2 months ago

Is there any progress with m-bus support? I‘ve got a new water Meter and a NZR Mod M-Bus (#8140) Module.