Reading Energy-Meter via (wired) M-Bus

Hi all,

I’m looking for someone who has already used HomeAssistant to read data from M-Bus.

earlier this week I’ve reactivated one of my Raspberry Pi3 and installed HomeAssistant. My primary focus is to read my meters and temperature in the house.

So far I’ve setup my utility meter with an IR-SML interface and four Gosund SP112, all of them via tasmota / mqtt integration.

My next step is to read two meters which are available via M-Bus for which I still have some equipment. I could also get a M-Bus MQTT Gateway but those are approx 230€.

Best
Mircsicz

As a reply to myself here’s how I’ve currently set it up:

I found that Blog post which described how to send the data to MQTT. With some additional step’s I could read the data from my old PiiGab MBus810 Mbus-Ethernet Gateway

But to have it working through reboots I also had to add a Systemd unit to my 2nd respberry Pi4 (8GB) which is running my MQTT-Broker (mosquitto) that unit File looks like this:
´´´

/etc/systemd/system/mbus-ip-socat.service

[Unit]
Description=MBus IP Gateway SerialPort
After=timesyncd.service
Requires=networking.service

[Service]
Type=simple
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=mbus-ip-socat

ExecStart=socat -d -d pty,group-late=tty,mode=660,rawer,echo=0,b2400 tcp:10.10.190.62:10001
Restart=always

[Install]
WantedBy=multi-user.target
´´´

What I’ve not yet working is reading it from wmbusmeters HA Addon.

To whom it may concern:

I’ve upgraded the Setup to NodeRed and do now read the Data and post it directly to MQTT:
NodeRed M-Bus Setup

This is my Flow:

[
    {
        "id": "f64d3c8935a38d30",
        "type": "tab",
        "label": "M-Bus_to_MQTT",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "b8264450e270741c",
        "type": "inject",
        "z": "f64d3c8935a38d30",
        "name": "Read ID 12 (NZR)",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "60",
        "crontab": "",
        "once": false,
        "onceDelay": "",
        "topic": "getDevice",
        "payload": "{\"address\": 12}",
        "payloadType": "json",
        "x": 170,
        "y": 100,
        "wires": [
            [
                "935c9f4fad634959"
            ]
        ]
    },
    {
        "id": "935c9f4fad634959",
        "type": "mbus-controller",
        "z": "f64d3c8935a38d30",
        "name": "",
        "client": "1297b765d08ed607",
        "x": 390,
        "y": 160,
        "wires": [
            [
                "f24a5a799575ed83",
                "b8cf0abac568a0af",
                "df7f6f1c3236d6e4"
            ]
        ]
    },
    {
        "id": "46ea21f4a57f027a",
        "type": "inject",
        "z": "f64d3c8935a38d30",
        "name": "Read ID 14 (SBC)",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "60",
        "crontab": "",
        "once": false,
        "onceDelay": "",
        "topic": "getDevice",
        "payload": "{\"address\": 14}",
        "payloadType": "json",
        "x": 170,
        "y": 220,
        "wires": [
            [
                "935c9f4fad634959"
            ]
        ]
    },
    {
        "id": "b8cf0abac568a0af",
        "type": "function",
        "z": "f64d3c8935a38d30",
        "name": "scanSecondary (SBC - PA:14)",
        "func": "var myId;\nvar myMedium;\nvar myProduct;\nvar myTS;\nvar myTotal;\nvar myTotalUnit;\nvar myPower1;\nvar myPower2;\nvar myPowerUnit;\n\nmyId = msg.payload.SlaveInformation.Id;\nmyMedium = msg.payload.SlaveInformation.Medium;\nmyProduct = msg.payload.SlaveInformation.Manufacturer;\nmyTotalUnit = msg.payload.DataRecord[0].Unit;\nmyTS = msg.payload.DataRecord[0].Timestamp;\n\nmyTotal = msg.payload.DataRecord[0].Value/10\nmyPower1 = msg.payload.DataRecord[17].Value*0.01\nmyPower2 = msg.payload.DataRecord[18].Value/100\n\nif (myId == \"90003AF\") {\nmsg.payload = (\n{\"sn\": {\"Time\":myTS,\"SecondaryAddress\":myId,\"Medium\":myMedium,\"Product\":myProduct,\"MeterReading\":\n    { \"total\": myTotal, \"Power_1\": myPower1, \"Power_2\": myPower2}, \"ver\":1 }}\n);\nreturn msg;\n}",
        "outputs": 1,
        "timeout": "5",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 650,
        "y": 240,
        "wires": [
            [
                "64c5dbbd2c047693",
                "f08ca8580eea9294"
            ]
        ]
    },
    {
        "id": "f24a5a799575ed83",
        "type": "function",
        "z": "f64d3c8935a38d30",
        "name": "scanSecondary (NZR - PA:12)",
        "func": "var myId;\nvar myMedium;\nvar myProduct;\nvar myTS;\nvar myTotal;\nvar myTotalUnit;\nvar myPower;\nvar myPowerUnit;\n\nfunction float32ToUint16(value) {\n    var buffer = new ArrayBuffer(4);\n    var intView = new Uint16Array(buffer);\n    var floatView = new Float32Array(buffer);\n    floatView[8] = value;\n    return [intView[0], intView[1]];\n}\n\nmyId = msg.payload.SlaveInformation.Id;\nmyMedium = msg.payload.SlaveInformation.Medium;\nmyProduct = msg.payload.SlaveInformation.ProductName;\nmyTotalUnit = msg.payload.DataRecord[0].Unit;\nmyTS = msg.payload.DataRecord[0].Timestamp;\n\nmyPower = msg.payload.DataRecord[4].Value\nmyTotal = msg.payload.DataRecord[0].Value/1000\n\nif (myId == \"30101282\") {\n\nmsg.payload = (\n{\"sn\": {\"Time\":myTS,\"SecondaryAddress\":myId,\"Medium\":myMedium,\"Product\":myProduct,\"MeterReading\":\n    {\"total\":myTotal,\"Power_curr\":myPower}, \"ver\":1 }}\n);\nreturn msg;\n}",
        "outputs": 1,
        "timeout": "5",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 650,
        "y": 80,
        "wires": [
            [
                "11d2ab5e52f4c780",
                "64c5dbbd2c047693"
            ]
        ]
    },
    {
        "id": "11d2ab5e52f4c780",
        "type": "mqtt out",
        "z": "f64d3c8935a38d30",
        "name": "M-Bus to MQTT",
        "topic": "mbus/benito/sensors",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "30951472ee910571",
        "x": 1020,
        "y": 100,
        "wires": []
    },
    {
        "id": "64c5dbbd2c047693",
        "type": "debug",
        "z": "f64d3c8935a38d30",
        "name": "debug 5",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1060,
        "y": 160,
        "wires": []
    },
    {
        "id": "f08ca8580eea9294",
        "type": "mqtt out",
        "z": "f64d3c8935a38d30",
        "name": "M-Bus to MQTT",
        "topic": "mbus/apartment/sensors",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "30951472ee910571",
        "x": 1020,
        "y": 220,
        "wires": []
    },
    {
        "id": "df7f6f1c3236d6e4",
        "type": "debug",
        "z": "f64d3c8935a38d30",
        "name": "debug 6",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 650,
        "y": 160,
        "wires": []
    },
    {
        "id": "1297b765d08ed607",
        "type": "mbus-client",
        "name": "PiiGAB-Appartment",
        "clienttype": "tcp",
        "tcpHost": "10.10.190.62",
        "tcpPort": "10001",
        "tcpTimeout": "4000",
        "serialPort": "/dev/ttyUSB",
        "serialBaudrate": "2400",
        "reconnectTimeout": "10000",
        "autoScan": true,
        "storeDevices": true,
        "disableLogs": true
    },
    {
        "id": "30951472ee910571",
        "type": "mqtt-broker",
        "name": "mbus@Pi8",
        "broker": "10.10.150.8",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]

For this to work you need to have this installed on your nodered

Integration in HA is over in this thread.