Issue with node-red-contrib-simpletime

#1

@Paul-Reed

I'm having a slight issue


image

[{"id":"8bc823cb.6b9ca","type":"inject","z":"48a2710e.b4384","name":"","topic":"","payload":"something ","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":540,"y":980,"wires":[["889dd4cc.e917e8"]]},{"id":"dd5ac8c7.8182b8","type":"debug","z":"48a2710e.b4384","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1230,"y":980,"wires":[]},{"id":"889dd4cc.e917e8","type":"simpletime","z":"48a2710e.b4384","name":"","x":730,"y":980,"wires":[["66f435ae.25292c","2d78ca24.7df136"]]},{"id":"a9329680.1a7bb8","type":"change","z":"48a2710e.b4384","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload & myrawdate","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":1060,"wires":[["dd5ac8c7.8182b8"]]},{"id":"66f435ae.25292c","type":"change","z":"48a2710e.b4384","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"myrawdate","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":980,"wires":[["dd5ac8c7.8182b8"]]},{"id":"2d78ca24.7df136","type":"delay","z":"48a2710e.b4384","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":740,"y":1060,"wires":[["a9329680.1a7bb8"]]}]

When I trigger the flow - I get an expanded date time string instead of the documented myrawdate format
But in the delayed change node path (which concats the payload with myrawdate )- I get the expected format but with extra "" marks

I'm very confused as to what is going on!

0 Likes

#2

Have you tried clicking on the top one in the debug?
I think it recognises it as a Date and therefore “translates” it for display

1 Like

#3

Aah - yes - that explains the 1st one- ta :slight_smile:

But still got those extra quotes in the delayed one

0 Likes

#4

I've just tried your flow, and the output from Simpletime is correct: myrawdate: "2018-12-13T17:10:06.809Z", so the error appears to be in your change node jsonata expression in the way it's trying to combine the two strings.

Sorry, can't help further with jsonata - it's the black arts as far as I'm concerned!!
Probably one for guru Steve @shrickus

0 Likes

#5

There's black arts going on all over the place with this one!

Just tried a simpe function node - and that transforms the msg.myrawdate as well

image

[{"id":"8bc823cb.6b9ca","type":"inject","z":"48a2710e.b4384","name":"","topic":"","payload":"something ","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":540,"y":980,"wires":[["889dd4cc.e917e8"]]},{"id":"dd5ac8c7.8182b8","type":"debug","z":"48a2710e.b4384","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1230,"y":980,"wires":[]},{"id":"889dd4cc.e917e8","type":"simpletime","z":"48a2710e.b4384","name":"","x":730,"y":980,"wires":[["66f435ae.25292c","2d78ca24.7df136","96c00ce3.9f343"]]},{"id":"a9329680.1a7bb8","type":"change","z":"48a2710e.b4384","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload & myrawdate","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":1060,"wires":[["dd5ac8c7.8182b8","96c00ce3.9f343"]]},{"id":"66f435ae.25292c","type":"change","z":"48a2710e.b4384","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"myrawdate","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":980,"wires":[["dd5ac8c7.8182b8"]]},{"id":"2d78ca24.7df136","type":"delay","z":"48a2710e.b4384","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":740,"y":1060,"wires":[["a9329680.1a7bb8","aa57b088.3d998"]]},{"id":"96c00ce3.9f343","type":"debug","z":"48a2710e.b4384","name":"OBJECT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1220,"y":1020,"wires":[]},{"id":"6632bce6.655014","type":"function","z":"48a2710e.b4384","name":"","func":"msg.payload = msg.payload + msg.myrawdate;\nreturn msg;","outputs":1,"noerr":0,"x":980,"y":1120,"wires":[["dd5ac8c7.8182b8","96c00ce3.9f343"]]},{"id":"aa57b088.3d998","type":"delay","z":"48a2710e.b4384","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":820,"y":1120,"wires":[["6632bce6.655014"]]}]
0 Likes

#6

You could always use a template node...

[
    {
        "id": "5d349ec6.b27f7",
        "type": "inject",
        "z": "c53060.842a0fa",
        "name": "",
        "topic": "",
        "payload": "something ",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 110,
        "y": 1140,
        "wires": [
            [
                "8b3b9ad2.587968"
            ]
        ]
    },
    {
        "id": "9bf59e5e.5fe3b",
        "type": "debug",
        "z": "c53060.842a0fa",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 730,
        "y": 1140,
        "wires": []
    },
    {
        "id": "8b3b9ad2.587968",
        "type": "simpletime",
        "z": "c53060.842a0fa",
        "name": "",
        "x": 280,
        "y": 1140,
        "wires": [
            [
                "ec9557dd.389a98",
                "fc5ceeec.aed8f"
            ]
        ]
    },
    {
        "id": "fc5ceeec.aed8f",
        "type": "change",
        "z": "c53060.842a0fa",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "myrawdate",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 510,
        "y": 1140,
        "wires": [
            [
                "9bf59e5e.5fe3b"
            ]
        ]
    },
    {
        "id": "ec9557dd.389a98",
        "type": "delay",
        "z": "c53060.842a0fa",
        "name": "",
        "pauseType": "delay",
        "timeout": "1",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 290,
        "y": 1220,
        "wires": [
            [
                "13349c6b.cdcbc4"
            ]
        ]
    },
    {
        "id": "13349c6b.cdcbc4",
        "type": "template",
        "z": "c53060.842a0fa",
        "name": "",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "{{payload}}: {{myrawdate}}",
        "output": "str",
        "x": 500,
        "y": 1220,
        "wires": [
            [
                "9bf59e5e.5fe3b"
            ]
        ]
    }
]
0 Likes

#7

And you say JSONata is black arts! :slight_smile:

0 Likes

#8

It’s not black arts. It’s just the way strings are visualised in the sidebar . This is similar to the way the browser tools console shows strings. They have a “ before and after. They aren’t really there in the string. Check the length of a known string.

1 Like

#9

We all ignore the "at start of a string and the one at the end" - but this is sticking them in the middle of the debug displayed payload and including the internal ones in the length of the string

image

0 Likes

#10

You have so many different things wired to the Debug nodes, its hard to look at that Debug output and know what path it has taken through your flow.

In the screenshots you attached to this reply - Issue with node-red-contrib-simpletime - there are no extra quotes in the middle of the string. So what is different between the flow that generate those debug messages and whatever flow generated the debug messages in your most recent reply that include the extra quotes.

0 Likes

#11

simplest flow that shows the issue

[{"id":"e8871fe0.aab65","type":"inject","z":"48a2710e.b4384","name":"","topic":"","payload":"something ","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":1440,"wires":[["2671dc0f.ed7a54"]]},{"id":"898ef286.5edec","type":"debug","z":"48a2710e.b4384","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":950,"y":1440,"wires":[]},{"id":"2671dc0f.ed7a54","type":"simpletime","z":"48a2710e.b4384","name":"","x":450,"y":1440,"wires":[["286d9d0f.fd5b42"]]},{"id":"286d9d0f.fd5b42","type":"change","z":"48a2710e.b4384","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload & myrawdate","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1440,"wires":[["898ef286.5edec"]]}]

produces this in debug
image

But its not confined to the simpletime node

This flow give identical results

[{"id":"803bbfb.1c8c54","type":"inject","z":"48a2710e.b4384","name":"","topic":"","payload":"something ","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":1520,"wires":[["85d3359a.6f1528"]]},{"id":"d391325.fb8acd","type":"debug","z":"48a2710e.b4384","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":950,"y":1520,"wires":[]},{"id":"858c9488.9aa0e8","type":"change","z":"48a2710e.b4384","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload & myrawdate","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1520,"wires":[["d391325.fb8acd"]]},{"id":"85d3359a.6f1528","type":"function","z":"48a2710e.b4384","name":"","func":"msg.myrawdate = new Date();\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":1520,"wires":[["858c9488.9aa0e8"]]}]

It seems that JSONata is just not handling the concatenation of a string with a date object as well as it could

0 Likes

#12

Digging thru javascript/JSONata documentation (and further testing)I think the issue is that JSONata is using JSON.Stringify to convert nearly all objects to strings.

i.e its not the concatenation that is the issue - its the basic conversion from data object to a string that is an issue

And this doesn't work cleanly if the object is a date (needs to use .toString() instead)

If people agree with my reasoning, I'll go looking for a JSONata forum and raise it on there

0 Likes

#13

I went to jsonata.org but the website is down (at least for me)

I wonder if anyone could contact the JSONata people/person and find out the situation with it?
[edit]its backup now :slight_smile: [/edit]

0 Likes