Can a "Change Node" display node status?

I would like the Change node to display a short date and time and the value of the new msg.payload it sends, a bit like other nodes.

Is this possible?

I could change out all the change nodes and replace then with function nodes and then write “node.status…” lines and so exactly display what I want, but if there’s a simple way that a change node could display node status, that would be nice, at the very least just the date and time it was last activated.

Change Node example

The node itself generates that message, it needs to be programed to display it. Afaik this is not an option for a change node.

Use a Debug node - and set to ‘node status’ only.

You can use JSONata to generate any message you like, as long as it is no more than 32 characters.

$now() will get a UTC ISO timestamp, so it does require a bit more work to get local time. For just the hh:mm with a given timezone offset, use

$now('[H02]:[m02]','-0700')

You can have the JSONata expression either as the debug output (to window and/or status) or you can have the debug output as msg.payload, and the status message as something else.

If you get the create order of the node correct, then you can even hide the debug node behind the change node and make it look just as you want it!

There is almost no end to the fun you can have with Node-RED !

1 Like

Improved the code:

Independent JSONata that does not need any other information to run. Should work to get local time anywhere (including the Chatham Islands) and offers summary details on the msg.payload dependent on type.

[{"id":"ba5270517b89a8cb","type":"debug","z":"98e189d983fd232f","name":"Message Status","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"(\t    \t/* JSONata to display local time and msg.payload details in debug node */\t\t    /* set your time display format, including separator, details at */\t    /* https://www.w3.org/TR/xpath-functions-31/#date-picture-string */\t    \t    $tdisp:=\"[MNn,-3]-[D01] [H]:[m] > \";\t    \t    /* select msg field to inspect - for some reason just payload */\t    /* is not working, so have to use compatibility mode...       */\t    \t    $p:=msg.payload;\t    \t    /* get local time by finding machine offset to 15 minutes */\t    $t:=($millis()-$toMillis($substringBefore($now(),\"Z\")))/900000;\t    $sign:=$t<0 ? \"-\" : \"+\";\t    $t:=$abs($t);\t    $off:=$sign & $formatNumber($floor($t/4),'00')  & $formatNumber(($t%4)*15,'00');\t    $time:=$now($tdisp, $off);\t \t    /* inspect the message field */\t    $type:= $exists($p) ? $type($p) : \"empty...\";\t    $det:=\t        $type=\"object\" ? \"object \" & $count($keys($p)) & \" keys\" :\t        $type=\"array\" ? \"array \" & $count($p) & \" items\"         :\t        $type=\"number\" or $type = \"boolean\" ? \"\" & $p:\t        $type=\"null\" ? \"is null\"                     :\t        $type=\"string\" ? $p                          :\t        $p;\t        \t    /* trim to 32 characters if necessary */\t    $l:= 32 - $length($time);\t    $d:= $length($det) <= $l ? $det : $substring($det, 0, $l-3) & \"...\";\t    \t    $time & $det;\t    \t)","statusType":"jsonata","x":900,"y":200,"wires":[]}]

Does not have locale access, so you have to set your own timestamp format as required (see comments in code).

Note> Node-RED bug - JSONata should work off the msg.payload by just ‘payload’ and the use of msg.payload is a compatibility mode. However, inside the Debug node JSONata is not picking up payload so I have to use msg.payload.