Query SMA Energy Meter / Home Manager by UDP Part2

In the continuation of

I have a new question to @Steve-Mcl :
the SMA EM got a new firmware, like it always get, but now the query stucks every 30s.

I analyzed the raw data and I saw this data every 30s:

[83,77,65,0,0,4,2,160,0,0,0,1,0,38,0,16,96,101,9,160,255,255,255,255,255,255,0,0,116,1,228,181,89,113,0,0,0,0,0,0,27,177,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

instead of this for example:

[83,77,65,0,0,4,2,160,0,0,0,1,2,76,0,16,96,105,1,116,113,89,181,228,111,170,172,50,0,1,4,0,0,0,18,63,0,1,8,0,0,0,0,6,231,89,65,104,0,2,4,0,0,0,0,0,0,2,8,0,0,0,0,14,179,226,181,240,0,3,4,0,0,0,0,0,0,3,8,0,0,0,0,0,19,192,28,136,0,4,4,0,0,0,39,2,0,4,8,0,0,0,0,16,57,140,115,32,0,9,4,0,0,0,43,16,0,9,8,0,0,0,0,13,180,146,239,112,0,10,4,0,0,0,0,0,0,10,8,0,0,0,0,17,122,14,240,192,0,13,4,0,0,0,1,168,0,14,4,0,0,0,195,90,0,21,4,0,0,0,5,62,0,21,8,0,0,0,0,3,242,250,89,16,0,22,4,0,0,0,0,0,0,22,8,0,0,0,0,10,227,44,209,200,0,23,4,0,0,0,0,0,0,23,8,0,0,0,0,0,32,71,176,216,0,24,4,0,0,0,15,180,0,24,8,0,0,0,0,6,32,88,154,80,0,29,4,0,0,0,16,142,0,29,8,0,0,0,0,5,206,12,21,56,0,30,4,0,0,0,0,0,0,30,8,0,0,0,0,11,222,138,215,104,0,31,4,0,0,0,7,147,0,32,4,0,0,3,137,50,0,33,4,0,0,0,1,61,0,41,4,0,0,0,11,16,0,41,8,0,0,0,0,3,2,43,169,8,0,42,4,0,0,0,0,0,0,42,8,0,0,0,0,2,202,30,51,240,0,43,4,0,0,0,0,0,0,43,8,0,0,0,0,0,11,235,1,248,0,44,4,0,0,0,10,189,0,44,8,0,0,0,0,3,16,219,62,0,0,49,4,0,0,0,15,107,0,49,8,0,0,0,0,4,89,198,213,96,0,50,4,0,0,0,0,0,0,50,8,0,0,0,0,2,235,185,130,48,0,51,4,0,0,0,6,236,0,52,4,0,0,3,143,104,0,53,4,0,0,0,2,206,0,61,4,0,0,0,1,242,0,61,8,0,0,0,0,2,44,209,6,144,0,62,4,0,0,0,0,0,0,62,8,0,0,0,0,3,65,53,126,128,0,63,4,0,0,0,0,0]

Do you have an idea what this could be? 58 <-> 608

Other question:
every 30 seconds there is a too small packet with 58 bytes.
I need a function to filter this packet from udp in.
Is that possible?
If packet size == 608 bytes then let through e.g.


I rebuilt Steve's speedwiredecoder myself in a very easy way and without generating CPU load.

Question:
Is there a way to change all values of an object like this:

var a = Number (msg.payload.W_bez);
a = a / 3600000;
msg.payload = a;
return msg;

the output are bigint (from counters) in Ws, I need kWh.

somebody showed me a function for rounding:

Object.entries(msg.payload).forEach((v) =>{
    msg.payload[v[0]] = Math.round(v[1]);
})
return msg;

maybe like this

This is the new flow with just 2 Buffer Parser:

[
    {
        "id": "6fa3a49d.1e4bec",
        "type": "udp in",
        "z": "4726af68.c62a98",
        "name": "SMA EM",
        "iface": "",
        "port": "9522",
        "ipv": "udp4",
        "multicast": "true",
        "group": "239.12.255.254",
        "datatype": "buffer",
        "x": 200,
        "y": 20,
        "wires": [
            [
                "e6588919.6def9",
                "72ebe599718bdb9a",
                "612794d01b5cb9ad"
            ]
        ]
    },
    {
        "id": "72ebe599718bdb9a",
        "type": "buffer-parser",
        "z": "4726af68.c62a98",
        "name": "Messwerte",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "uint32be",
                "name": "P_bez",
                "offset": 32,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "P_ein",
                "offset": 52,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "Q_ind",
                "offset": 72,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "Q_kap",
                "offset": 92,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "S_bez",
                "offset": 112,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "S_ein",
                "offset": 132,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "cos_phi",
                "offset": 152,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.001",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "Hz",
                "offset": 160,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.001",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "P1_bez",
                "offset": 168,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "P1_ein",
                "offset": 188,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "Q1_ind",
                "offset": 208,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "Q1_kap",
                "offset": 228,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "S1_bez",
                "offset": 248,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "S1_ein",
                "offset": 268,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "I1",
                "offset": 288,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.001",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "U1",
                "offset": 296,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.001",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "cos_phi1",
                "offset": 304,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.001",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "P2_bez",
                "offset": 312,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "P2_ein",
                "offset": 332,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "Q2_ind",
                "offset": 352,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "Q2_kap",
                "offset": 372,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "S2_bez",
                "offset": 392,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "S2_ein",
                "offset": 412,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "I2",
                "offset": 432,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.001",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "U2",
                "offset": 440,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.001",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "cos_phi2",
                "offset": 448,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.001",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "P3_bez",
                "offset": 456,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "P3_ein",
                "offset": 476,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "Q3_ind",
                "offset": 496,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "Q3_kap",
                "offset": 516,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "S3_bez",
                "offset": 536,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "S3_ein",
                "offset": 556,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.1",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "I3",
                "offset": 576,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.001",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "U3",
                "offset": 584,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.001",
                "mask": ""
            },
            {
                "type": "uint32be",
                "name": "cos_phi3",
                "offset": 592,
                "length": 1,
                "offsetbit": 0,
                "scale": "0.001",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "resultType": "keyvalue",
        "resultTypeType": "output",
        "multipleResult": false,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 610,
        "y": 740,
        "wires": [
            [
                "6da45803f5650ecc"
            ]
        ]
    },
    {
        "id": "612794d01b5cb9ad",
        "type": "buffer-parser",
        "z": "4726af68.c62a98",
        "name": "Zähler",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "biguint64be",
                "name": "W_bez",
                "offset": 40,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_ein",
                "offset": 60,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_Q_ind",
                "offset": 80,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_Q_kap",
                "offset": 100,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_S_bez",
                "offset": 120,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_S_ein",
                "offset": 140,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W1_bez",
                "offset": 176,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W1_ein",
                "offset": 196,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_Q1_ind",
                "offset": 216,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_Q1_kap",
                "offset": 236,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_S1_bez",
                "offset": 256,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_S1_ein",
                "offset": 276,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W2_bez",
                "offset": 320,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W2_ein",
                "offset": 340,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_Q2_ind",
                "offset": 360,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_Q2_kap",
                "offset": 380,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_S2_bez",
                "offset": 400,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_S2_ein",
                "offset": 420,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W3_bez",
                "offset": 464,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W3_ein",
                "offset": 484,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_Q3_ind",
                "offset": 504,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_Q3_kap",
                "offset": 524,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_S3_bez",
                "offset": 544,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "biguint64be",
                "name": "W_S3_ein",
                "offset": 564,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "resultType": "keyvalue",
        "resultTypeType": "output",
        "multipleResult": false,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 590,
        "y": 800,
        "wires": [
            [
                "6da45803f5650ecc"
            ]
        ]
    },
    {
        "id": "6da45803f5650ecc",
        "type": "debug",
        "z": "4726af68.c62a98",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 870,
        "y": 760,
        "wires": []
    }
]

you can try it with:

[83,77,65,0,0,4,2,160,0,0,0,1,2,76,0,16,96,105,1,116,113,89,181,228,114,77,104,54,0,1,4,0,0,0,21,132,0,1,8,0,0,0,0,6,234,67,77,216,0,2,4,0,0,0,0,0,0,2,8,0,0,0,0,14,179,233,174,120,0,3,4,0,0,0,0,0,0,3,8,0,0,0,0,0,19,192,28,136,0,4,4,0,0,0,38,183,0,4,8,0,0,0,0,16,59,174,224,112,0,9,4,0,0,0,44,75,0,9,8,0,0,0,0,13,184,120,144,184,0,10,4,0,0,0,0,0,0,10,8,0,0,0,0,17,122,101,181,224,0,13,4,0,0,0,1,230,0,14,4,0,0,0,195,67,0,21,4,0,0,0,6,61,0,21,8,0,0,0,0,3,244,74,170,184,0,22,4,0,0,0,0,0,0,22,8,0,0,0,0,10,227,85,224,24,0,23,4,0,0,0,0,0,0,23,8,0,0,0,0,0,32,71,176,216,0,24,4,0,0,0,15,118,0,24,8,0,0,0,0,6,33,39,47,40,0,29,4,0,0,0,16,172,0,29,8,0,0,0,0,5,207,168,226,24,0,30,4,0,0,0,0,0,0,30,8,0,0,0,0,11,222,209,21,32,0,31,4,0,0,0,7,179,0,32,4,0,0,3,130,247,0,33,4,0,0,0,1,118,0,41,4,0,0,0,11,250,0,41,8,0,0,0,0,3,2,226,230,184,0,42,4,0,0,0,0,0,0,42,8,0,0,0,0,2,202,42,245,64,0,43,4,0,0,0,0,0,0,43,8,0,0,0,0,0,11,235,1,248,0,44,4,0,0,0,10,198,0,44,8,0,0,0,0,3,17,113,225,152,0,49,4,0,0,0,16,28,0,49,8,0,0,0,0,4,90,175,235,96,0,50,4,0,0,0,0,0,0,50,8,0,0,0,0,2,235,203,92,128,0,51,4,0,0,0,7,117,0,52,4,0,0,3,129,252,0,53,4,0,0,0,2,231,0,61,4,0,0,0,3,77,0,61,8,0,0,0,0,2,46,20,112,240,0,62,4,0,0,0,0,0,0,62,8,0,0,0,0,3,65,103,150,24,0,63,4,0,0,0,0,0]

Hi Becker ..

so with the new firmware you get some msgs that are 58 bytes instead of 608 ?

use a simple if statement to filter those out ?

if (msg.payload.length === 608) {
// process the 608 byte msgs only
}
1 Like

very nice :smiley:

if (msg.payload.length === 608) {
    msg.payload = msg.payload;
}
else {
    return;
}
return msg

or can you write the expression even more beautifully?

yes every 30s one msg with 58bytes arrives, as you can see in pic1.

if (msg.payload.length === 608) {
    return msg;
}
else {
    return null;
}

i dont know the exact reason why we have to return null in the case of no msg .. but i saw in many posts people using it .. possibly to safely close the Function node ?

1 Like

You can just drop out of the bottom of the function node without an explicit return, which has the same effect. The main reason is, I think, so that it is clear that it is an intentional return and don't send a message, rather than just a missing return statement. Personally I prefer to code this as

if (msg.payload.length != 608) {
    msg = null
}
return msg

I would not generally have a return statement in the middle of a function, I have seen this cause bugs too many times. It is all too easy to come back to a function and forget that there is a return in the middle and start adding code at the end. Less likely in trivial instances like this, but the function may start off simple and then grow in complexity over time.

2 Likes
if (msg.payload.length !== 608) {
     msg = null;
}
return msg;
2 Likes

I think we must be telepathically linked across the world.

2 Likes

are the ";" necessary or not? :grimacing:

anybody have an idea about bigint in an object converting to number & /3600000 ?

Object.entries(msg.payload).forEach((?) =>{
    msg.payload[?] = number / 3600000 ?;
})
return msg;

Only one thing could tell are linked minds apart?

No

Object.keys(msg.payload).forEach((key) => {
    msg.payload[key] = msg.payload[key] / 3600000 ;
})
return msg;

//or 

for(let key of Object.keys(msg.payload)){
    msg.payload[key] = msg.payload[key] / 3600000;
}

return msg;

TypeError: Cannot mix BigInt and other types, use explicit conversions :grimacing: :unamused:

havent worked with bigInt before but i believe if you are doing calculations between bigInts like your msg.payload[key]

then try

msg.payload[key] / 3600000n

Last question for today:
if I want to round in "text" (dashboard) node with:
{{msg.payload.Q_kap|number:1}} var
i get:
1,028.5 var

is it possible to get 1028.5 or (even better) 1028,5 ?


3600000n

is cutting the decimals after the ,

The / operator also works as expected with whole numbers — but operations with a fractional result will be truncated when used with a BigInt value — they won’t return any fractional digits.

yes I know.

Will I get a problem with bigint to number ever ?

Today the highest counter is: 69760845000 kvars = 19,378.0125 kvarh

In 30years it will rise to ~ 597.950.100.000 kvars = 166.097,25 kvarh

This is my solution for the SMA Home Manager 2.0 / Energy Meter:



This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.