Trying to build message with CHANGE node. Not working

(And template node.)

This is the flow: (Basic)

[{"id":"15ae0152.83044f","type":"inject","z":"675e227d.d158b4","name":"Weekly","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"50 23 * * 0","once":false,"onceDelay":0.1,"x":160,"y":1990,"wires":[["c99fea29.aeaf1"]]},{"id":"c99fea29.aeaf1","type":"moment","z":"675e227d.d158b4","name":"","topic":"","input":"","inputType":"msg","inTz":"Australia/Sydney","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-ww","locale":"en_AU","output":"","outputType":"msg","outTz":"Australia/Sydney","x":390,"y":1990,"wires":[["8ed6e064.5d98e","d8d204f7.310a8"]]},{"id":"8ed6e064.5d98e","type":"change","z":"675e227d.d158b4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"directory","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"log_paths","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":1990,"wires":[["791399b9.493ee","8921a9ee.bfb6d8"]]},{"id":"791399b9.493ee","type":"template","z":"675e227d.d158b4","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload}}reboot","output":"str","x":790,"y":1990,"wires":[["74e6ce8a.becc68"]]},{"id":"d8d204f7.310a8","type":"function","z":"675e227d.d158b4","name":"","func":"msg.directory = msg.payload;\n\nvar path = global.get(\"log_paths\");\nmsg.path = path + \"reboot/\";\n\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":2030,"wires":[["d5e9569e.50cea"]]},{"id":"d5e9569e.50cea","type":"debug","z":"675e227d.d158b4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":710,"y":2100,"wires":[]},{"id":"74e6ce8a.becc68","type":"debug","z":"675e227d.d158b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":980,"y":1920,"wires":[]}]

Generate timestamp, feed it into moment node to get format YYYY-ww, send that to a change node to set the msg.directory to that path - sort of, into template node to append to the path name, which is held in msg.payload.

Ok, the global stuff:
given log_paths is set to: /media/pi/06BB-C87D/logs/

So at this stage I would expect:
msg.directory to be 2020-12
and
msg.payload to be /media/pi/06BB-C87D/logs/reboot

This is what I get/see:

{"_msgid":"b3cea20a.1254b","topic":"","directory":"2020-12","payload":"/media/pi/06BB-C87D/logs/reboot"}

But if I go down the lower path via the function node I get:

{"_msgid":"b3cea20a.1254b","topic":"","payload":"2020-12","directory":"2020-12","path":"/media/pi/06BB-C87D/logs/reboot/"}

Which looks a lot better than the first one.

Ok, the second one does it a bit differently. I gives me msg.path and msg.directory
Hope you can get what I am wanting to do.

Where's the elephant?

Try using {{{payload}}}reboot in the template node

(I gotta ask)

Why the 3 { ?

In the example in the template node there are only 2.

But thanks for the reply.

Google search 'mustache syntax'

from https://scalate.github.io/scalate/documentation/mustache.html

All values are HTML escaped by default. If you want to return unescaped HTML use the triple mustache {{{name}}} . Or you can use {{& name}}

1 Like

It was knowing it is "mustache syntax"..... Yeah, I have heard of it, but just hadn't put the two together.

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