PLC Hex time send / recive

Hi everbody.
I am struggelig with read/send time to my Siemens PLC.

I have made a flow, but it only work when i send a value with 2 decimals.

Example:
13:13 - works fine.
18:56 - works fine

18:01 - Not working
10:07 - Not working.

Attached is the flow. Can somebody help me what i am missing ?

[
    {
        "id": "4dbd5df7b5513090",
        "type": "ui_numeric",
        "z": "55096135d3cea7da",
        "name": "",
        "label": "numeric",
        "tooltip": "",
        "group": "42f3e01d8f47c23c",
        "order": 2,
        "width": 0,
        "height": 0,
        "wrap": false,
        "passthru": true,
        "topic": "topic",
        "topicType": "msg",
        "format": "{{value}}",
        "min": 0,
        "max": "23",
        "step": "1",
        "className": "",
        "x": 740,
        "y": 3340,
        "wires": [
            [
                "c182fb6c1a79bbf1"
            ]
        ]
    },
    {
        "id": "c378fbaaa8d71338",
        "type": "function",
        "z": "55096135d3cea7da",
        "name": "function 44",
        "func": "var asHex = parseInt(msg.payload).toString(\"16\").padStart(4, \"0\");\nvar hh = asHex.substring(0, 2);\nvar mm = asHex.substring(2, 4);\nmsg.payload = `${hh}:${mm}`\nmsg.m=mm;\nmsg.h=hh;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 310,
        "y": 3400,
        "wires": [
            [
                "e9b1640f3de0be99",
                "3809542256f245ae"
            ]
        ]
    },
    {
        "id": "c182fb6c1a79bbf1",
        "type": "function",
        "z": "55096135d3cea7da",
        "name": "function 45",
        "func": "var asDEC = parseInt(msg.payload).toString(\"2\")\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 910,
        "y": 3300,
        "wires": [
            [
                "7b582763e018e38e"
            ]
        ]
    },
    {
        "id": "7b582763e018e38e",
        "type": "debug",
        "z": "55096135d3cea7da",
        "name": "debug 25",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1120,
        "y": 3240,
        "wires": []
    },
    {
        "id": "38142d962d4fced4",
        "type": "ui_numeric",
        "z": "55096135d3cea7da",
        "name": "h time 3",
        "label": "h:",
        "tooltip": "",
        "group": "045c538dbdcd8b16",
        "order": 7,
        "width": 2,
        "height": 1,
        "wrap": false,
        "passthru": true,
        "topic": "hh",
        "topicType": "str",
        "format": "{{msg.payload}}",
        "min": 0,
        "max": "23",
        "step": 1,
        "className": "",
        "x": 680,
        "y": 3420,
        "wires": [
            [
                "31971ee7eeb1c7af",
                "72843771666fd029"
            ]
        ]
    },
    {
        "id": "31971ee7eeb1c7af",
        "type": "debug",
        "z": "55096135d3cea7da",
        "name": "debug 26",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 840,
        "y": 3420,
        "wires": []
    },
    {
        "id": "6dd914d78b5da41d",
        "type": "inject",
        "z": "55096135d3cea7da",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "4883",
        "payloadType": "num",
        "x": 150,
        "y": 3400,
        "wires": [
            [
                "c378fbaaa8d71338"
            ]
        ]
    },
    {
        "id": "21c627195c60226e",
        "type": "ui_numeric",
        "z": "55096135d3cea7da",
        "name": "m time 3",
        "label": "m:",
        "tooltip": "",
        "group": "045c538dbdcd8b16",
        "order": 8,
        "width": 2,
        "height": 1,
        "wrap": false,
        "passthru": true,
        "topic": "mm",
        "topicType": "str",
        "format": "{{msg.payload}}",
        "min": 0,
        "max": "59",
        "step": 1,
        "className": "",
        "x": 680,
        "y": 3480,
        "wires": [
            [
                "af6b261f3752907d",
                "749d19fac53fcaf3"
            ]
        ]
    },
    {
        "id": "af6b261f3752907d",
        "type": "debug",
        "z": "55096135d3cea7da",
        "name": "debug 27",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 820,
        "y": 3520,
        "wires": []
    },
    {
        "id": "e9b1640f3de0be99",
        "type": "function",
        "z": "55096135d3cea7da",
        "name": "function 46",
        "func": "msg.payload=parseInt(msg.h);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 510,
        "y": 3420,
        "wires": [
            [
                "38142d962d4fced4",
                "a76d7ec2083be8fe"
            ]
        ]
    },
    {
        "id": "3809542256f245ae",
        "type": "function",
        "z": "55096135d3cea7da",
        "name": "function 47",
        "func": "msg.payload = parseInt(msg.m);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 510,
        "y": 3460,
        "wires": [
            [
                "21c627195c60226e",
                "c49f0f546676f54b"
            ]
        ]
    },
    {
        "id": "9883e41ad7e4817c",
        "type": "function",
        "z": "55096135d3cea7da",
        "name": "function 48",
        "func": "\nfunction revertDecimalToDecimal(h, m) {\n    const combined = \"\" + h + \"\" + m;\n    const originalDecimalValue = parseInt(combined, 16);\n    return originalDecimalValue;\n}\n\nlet h = flow.get(\"inp3h\");\nlet m = flow.get(\"inp3m\");\n\nmsg.payload = revertDecimalToDecimal(h, m);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1150,
        "y": 3440,
        "wires": [
            [
                "f3e47ebc047caff5"
            ]
        ]
    },
    {
        "id": "72843771666fd029",
        "type": "function",
        "z": "55096135d3cea7da",
        "name": "function 49",
        "func": "\nlet inv=msg.payload ;\nflow.set(\"inp3h\",inv);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 810,
        "y": 3380,
        "wires": [
            [
                "f8d2baaeb20a505c"
            ]
        ]
    },
    {
        "id": "749d19fac53fcaf3",
        "type": "function",
        "z": "55096135d3cea7da",
        "name": "function 50",
        "func": "\nlet inv=msg.payload ;\nflow.set(\"inp3m\",inv);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 850,
        "y": 3480,
        "wires": [
            [
                "f8d2baaeb20a505c"
            ]
        ]
    },
    {
        "id": "f8d2baaeb20a505c",
        "type": "trigger",
        "z": "55096135d3cea7da",
        "name": "",
        "op1": "",
        "op2": "0",
        "op1type": "nul",
        "op2type": "str",
        "duration": "1",
        "extend": false,
        "overrideDelay": false,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 1000,
        "y": 3440,
        "wires": [
            [
                "9883e41ad7e4817c"
            ]
        ]
    },
    {
        "id": "f3e47ebc047caff5",
        "type": "debug",
        "z": "55096135d3cea7da",
        "name": "final out",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1300,
        "y": 3420,
        "wires": []
    },
    {
        "id": "a76d7ec2083be8fe",
        "type": "debug",
        "z": "55096135d3cea7da",
        "name": "debug 29",
        "active": true,
        "tosidebar": false,
        "console": false,
        "tostatus": true,
        "complete": "h",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 580,
        "y": 3360,
        "wires": []
    },
    {
        "id": "c49f0f546676f54b",
        "type": "debug",
        "z": "55096135d3cea7da",
        "name": "debug 30",
        "active": true,
        "tosidebar": false,
        "console": false,
        "tostatus": true,
        "complete": "m",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 600,
        "y": 3540,
        "wires": []
    },
    {
        "id": "42f3e01d8f47c23c",
        "type": "ui_group",
        "name": "Tidsstyrring:",
        "tab": "9a5c087ffc889758",
        "order": 7,
        "disp": true,
        "width": "16",
        "collapse": false,
        "className": ""
    },
    {
        "id": "045c538dbdcd8b16",
        "type": "ui_group",
        "name": "Group 8",
        "tab": "9a5c087ffc889758",
        "order": 8,
        "disp": true,
        "width": 6
    },
    {
        "id": "9a5c087ffc889758",
        "type": "ui_tab",
        "name": "Rema 1000 Admin view",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

I can't test your flow at the moment, but show us what you see in the debug nodes for a good value and a bad value. From that you should be able to see which function is not working.

Hi Colin thanks for reply.

I have discovered this in my function block


function revertDecimalToDecimal(h, m) {
    const combined = "" + h + "" + m;
    const originalDecimalValue = parseInt(combined, 16);
    return originalDecimalValue;
}

let h = flow.get("inp3h");
let m = flow.get("inp3m");

msg.payload = revertDecimalToDecimal(h, m);
return msg;

With 0 inserted:

function revertDecimalToDecimal(h, m) {
    const combined = "" + h + "0 + m;
    const originalDecimalValue = parseInt(combined, 16);
    return originalDecimalValue;
}

let h = flow.get("inp3h");
let m = flow.get("inp3m");

msg.payload = revertDecimalToDecimal(h, m);
return msg;

If i put in the Zero number here it works up to 9, so somehow i need to make that if value is only on charachter it must put 0 in front...

Have a look at padStart(), though I see you are already using that in Function 44.
By the way, it is a good idea to give your nodes meaningful names.

Thank you. I think the problem is that the "nummeric" block automaticly delete "0" so is make only "5" instead of "05" Any idea to fix that ?

Do you mean the that the numeric node (they are nodes not blocks) shows numbers without leading zeros? Or do you mean the the number coming out of it hasn't got leading zeros?
If the former then try, in the Value Format field for the node, putting {{msg.payload | number:2}}, though I am not certain it will work there.
If the latter then Numbers just have a value, it is not until you convert it to a string the the concept of leading zeros has any meaning. That is what padStart() can do for you, add the leading zero when you convert it to a string for display.

Allmost there now, i think :smiley: ...

Can you tell me where to put the padstart in here in this function node?


let inv=msg.payload ;
flow.set("inp3m",inv);
return msg;

To use padStart() you first have to convert the number to a string, so this should do what you want.

let inv=msg.payload.toString().padStart(2, "0");
flow.set("inp3m",inv);
return msg;

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