Here is a way to get the data directly from the SMA Energy Meter or from the SMA Home Manager 2.0 by using Node Red. Why Node Red? It has all we need to intercept the udp multicast messages the Energy Meter sends out every second.
I assume a hass.io environment with installed Node-RED & Mosquitto broker Add-on
We use a function to extract data from the buffer containing the broadcast and feeding them via MQTT to HA.
- start a new Flow in Node-Red and call it SMA
- drag a “udp in” node (from the network section) on the canvas and configure it like this
sorry about the German localization in the pic. We need to receive multicast data from the ip 239.12.255.254 using port 9522 to be passed on in a buffer which btw. will contain 608 Bytes per message with the actual firmware of the SMA device.
see also here: http://www.eb-systeme.de/wp-content/uploads/2019/12/EMETER-Protokoll-TI-de-10.pdf
If you connect a debug node to the output of the udp node you should already see the 608 Bytes message coming in every second. If you don’t see any activity it might be that the device you are running Node-Red on is blocking udp multicast messages. This can be the case if you run your instance on a NAS System. It will work perfectly on a PI running HASS.io
- drag a function node to the canvas and connect the output from the udp node to the input of the function node.
- Configure the function node to have 4 outputs and add the following code
var count = context.get('count')||0;
count += 1;
/*
IF you do not want to update HA every second you can set the fuction to pass
the data less often - see below
*/
if (count < 30) { /* process data only every 30 seconds */
context.set('count',count);
return null;
}
count = 0;
context.set('count',count);
var msg1 = { payload:"actual consumption" };
var msg2 = { payload:"actual gridfeed" };
var msg3 = { payload:"consumption counter" };
var msg4 = { payload:"gridfeed counter" };
/* to get the actual grid consumption in W we need the offset 0.1.4.0 */
offset = msg.payload.indexOf("00010400", 0, "hex")+ 4;
var consumption = parseInt((msg.payload[offset+0]*0x1000000 +
msg.payload[offset+1]*0x10000 +
msg.payload[offset+2]*0x100 +
msg.payload[offset+3]) / 10);
/* to get the actual grid consumption counter in Wh we need the offset 0.1.8.0 */
offset = msg.payload.indexOf("00010800", 0, "hex")+ 4;
var consumption_c = parseInt((msg.payload[offset+0]*0x100000000000000 +
msg.payload[offset+1]*0x1000000000000 +
msg.payload[offset+2]*0x10000000000 +
msg.payload[offset+3]*0x100000000 +
msg.payload[offset+4]*0x1000000 +
msg.payload[offset+5]*0x10000 +
msg.payload[offset+6]*0x100 +
msg.payload[offset+7]) / 3600);
/* to get the actual grid feed in W we need the offset 0.2.4.0 */
offset = msg.payload.indexOf("00020400", 0, "hex")+ 4;
var gridfeed = parseInt((msg.payload[offset+0]*0x1000000 +
msg.payload[offset+1]*0x10000 +
msg.payload[offset+2]*0x100 +
msg.payload[offset+3]) / 10);
/* to get the actual grid feed counter in Wh we need the offset 0.2.8.0 */
offset = msg.payload.indexOf("00020800", 0, "hex")+ 4;
var gridfeed_c = parseInt((msg.payload[offset+0]*0x100000000000000 +
msg.payload[offset+1]*0x1000000000000 +
msg.payload[offset+2]*0x10000000000 +
msg.payload[offset+3]*0x100000000 +
msg.payload[offset+4]*0x1000000 +
msg.payload[offset+5]*0x10000 +
msg.payload[offset+6]*0x100 +
msg.payload[offset+7]) / 3600);
if (consumption >= 0 && consumption < 100000 ) {
msg1.payload = consumption.toString();
} else msg1 = null;
if (consumption_c >= 0 && consumption_c < 50000000 ) {
msg2.payload = consumption_c.toString();
} else msg2 = null;
if (gridfeed >= 0 && gridfeed < 100000 ) {
msg3.payload = gridfeed.toString();
} else msg3 = null;
if (gridfeed_c >= 0 && gridfeed_c < 5000000 ) {
msg4.payload = gridfeed_c.toString();
} else msg4 = null;
return [msg1, msg2, msg3, msg4 ];
-
now the 4 outputs will push every 30s the following measurements:
output 1: actual grid consumption in W
output 2: grid consumption counter in Wh
output 3: actual grid feed in W
output 4: grid feed counter in Wh -
push this data back into HA using “MQTT out” nodes of your choosing.
-
define corresponding mqtt sensors in HA to retrieve the data