# Query SMA Energy Meter / Home Manager by UDP Part2

**URL:** <https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498>\
**Category:** General\
**Created:** [30 November 2021 07:20 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498 "2021-11-30T07:20:40Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [30 November 2021 07:20 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/1 "2021-11-30T07:20:40Z")

</div>

In the continuation of

> [@Query SMA Energy Meter / Home Manager by UDP in](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-in/42983):
>
> Hi, I came across the possibility to query my home manager directly in Node Red with UDP in: [{"id":"a14c0e39.6a108","type":"udp in","z":"4726af68.c62a98","name":"Home Manager","iface":"","port":"9522","ipv":"udp4","multicast":"true","group":"239.12.255.254","datatype":"buffer","x":310,"y":440,"wires":[["124446eb.e14ff9"]]},{"id":"76a01c62.9a89b4","type":"debug","z":"4726af68.c62a98","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","s…

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:

```auto
[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:

```auto
[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]

```

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3cbc9f65d1c78e0ba1dc250587fb14a18f968926.png)

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

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [30 November 2021 19:24 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/2 "2021-11-30T19:24:25Z")

</div>

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:

```auto
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:

```auto
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:

```auto
[
    {
        "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:

```auto
[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]

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [30 November 2021 19:41 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/3 "2021-11-30T19:41:17Z")

</div>

> [@Becker](#):
>
> I need a function to filter this packet from udp in.  
> Is that possible?

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 ?

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

```

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [30 November 2021 19:46 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/4 "2021-11-30T19:46:47Z")

</div>

very nice 😃

```auto
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.

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [30 November 2021 19:52 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/5 "2021-11-30T19:52:59Z")

</div>

```auto
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 ?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 November 2021 21:33 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/6 "2021-11-30T21:33:28Z")

</div>

> [@UnborN](#):
>
> i dont know the exact reason why we have to `return null` in the case of no msg

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [30 November 2021 21:34 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/7 "2021-11-30T21:34:47Z")

</div>

> [@Becker](#):
>
> or can you write the expression even more beautifully?

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

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 November 2021 21:53 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/8 "2021-11-30T21:53:08Z")

</div>

I think we must be telepathically linked across the world.

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [30 November 2021 21:57 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/9 "2021-11-30T21:57:00Z")

</div>

are the ";" necessary or not? 😬

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

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

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [30 November 2021 22:00 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/10 "2021-11-30T22:00:33Z")

</div>

Only one thing could tell are linked minds apart?

> [@Becker](#):
>
> are the ";" necessary or not?

No

```auto
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;

```

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [30 November 2021 22:32 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/11 "2021-11-30T22:32:46Z")

</div>

TypeError: Cannot mix BigInt and other types, use explicit conversions 😬 😒

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [30 November 2021 22:39 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/12 "2021-11-30T22:39:53Z")

</div>

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

then try

```auto
msg.payload[key] / 3600000n

```

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [30 November 2021 22:42 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/13 "2021-11-30T22:42:02Z")

</div>

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 ?

* * *

```auto
3600000n

```

is cutting the decimals after the ,

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [30 November 2021 22:58 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/14 "2021-11-30T22:58:01Z")

</div>

> [@Becker](#):
>
> ```auto
> 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.

> **[BigInt - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#description)**
>
> BigInt values represent numeric values which are too large to be represented by the number primitive.

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [1 December 2021 07:06 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/15 "2021-12-01T07:06:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [1 December 2021 12:34 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/16 "2021-12-01T12:34:53Z")

</div>

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

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/0425ba039f69775b24e709a72a550df44e660c33.jpeg)  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/3/83ad8d4401ab448530de20211599093a2981921e.jpeg)  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/c/2cbf1c786383e2b346797f547d973a954f7f5e57.jpeg)

> **[EM.zip](https://drive.google.com/file/d/1piYQf4VXmHusahFg1pvAuj7wUGbL3Y67/view?usp=sharing)**
>
> Google Drive file.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [15 December 2021 12:35 UTC](https://discourse.nodered.org/t/query-sma-energy-meter-home-manager-by-udp-part2/54498/17 "2021-12-15T12:35:14Z")

</div>

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