Help with a trigger node - trick

I'm trying to optimise some code but am stuck.

This is my trigger node.

[{"id":"21982222.97dd2e","type":"trigger","z":"fb549e2f.4d026","g":"9f73c6fa33db761f","name":"","op1":"{\"command\": \"remove-all\"}","op2":"{\"command\":\"add\",\"name\":\"30\",\"payload\":\"30\",\"expression\":\"0 */30 * * * * *\"}","op1type":"json","op2type":"json","duration":"250","extend":false,"units":"ms","reset":"","bytopic":"all","outputs":1,"x":1330,"y":1800,"wires":[["15e1c4e1.b0dbab"]]}]

This part in particular:
{"command":"add","name":"30","payload":"30","expression":"0 */30 * * * * *"}

The 30 part is variable.

It could be 5, 10, 12, 15, 20, 30, or 60.

So the event is done at those frequencies.

How can I make this value set by msg.payload, either in that node or I could construct the message in a function node and have that sent into the trigger node.

How about this? I don't now exacly what you want to do :wink:
Looks like adding stuff to the the cron-plus node?

[{"id":"59a30ad669ffa86c","type":"inject","z":"8c6cb615b3919618","name":"30","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"30","payloadType":"num","x":270,"y":220,"wires":[["21982222.97dd2e"]]},{"id":"6b6fb16ecfc05e98","type":"function","z":"8c6cb615b3919618","name":"format","func":"const p = msg.payload\nmsg.payload = {\n    \"command\":\"add\",\n    \"name\":`${p}`,\n    \"payload\":`${p}`,\n    \"expression\":`0 */${p} * * * * *`\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":830,"y":160,"wires":[["cac826c266164a5a"]]},{"id":"cac826c266164a5a","type":"debug","z":"8c6cb615b3919618","name":"dynamic","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1000,"y":220,"wires":[]},{"id":"b3d0d145cd6d3ed8","type":"inject","z":"8c6cb615b3919618","name":"15","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"15","payloadType":"num","x":270,"y":180,"wires":[["21982222.97dd2e"]]},{"id":"21982222.97dd2e","type":"trigger","z":"8c6cb615b3919618","name":"","op1":"{\"command\": \"remove-all\"}","op2":"","op1type":"json","op2type":"pay","duration":"250","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":480,"y":220,"wires":[["441d9406a868e29c"]]},{"id":"441d9406a868e29c","type":"switch","z":"8c6cb615b3919618","name":"Number?","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"number","vt":"number"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":660,"y":220,"wires":[["6b6fb16ecfc05e98"],["cac826c266164a5a"]]}]
1 Like

Nice, but not quite.

The second command needs to be a bit more.... complicated.

Your gives me nearly enough, but not quite enough.

Sorry I didn't mention it originally, but the message is being sent into the cron-plus node.

I need to add a schedule that repeats every.... 5, 6, 10, 12, 15.... etc minutes.

So it needs to be
{"command":"add","name":"30","payload":"30","expression":"0 */30 * * * * *"}
where the 30 is the message received and the entire line is what is sent.

Thanks.

Ooops.

Sorry.

I think that does work.

Hang on.

Adding multiple schedules to the cron-plus node at the given intervalls:

[{"id":"4a9ce1991df50e32","type":"inject","z":"8c6cb615b3919618","name":"intervalls","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[5,10,12,15,20,30,60]","payloadType":"json","x":260,"y":480,"wires":[["4743b5ef1816d934","5592076892aa31a6"]]},{"id":"4743b5ef1816d934","type":"split","z":"8c6cb615b3919618","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":430,"y":480,"wires":[["7f375f758287737b"]]},{"id":"7f375f758287737b","type":"function","z":"8c6cb615b3919618","name":"format","func":"const p = msg.payload\nmsg.payload = {\n    \"command\":\"add\",\n    \"name\":`${p}`,\n    \"payload\":`${p}`,\n    \"expression\":`0 */${p} * * * * *`\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":570,"y":480,"wires":[["06e1b527fb0597a4"]]},{"id":"06e1b527fb0597a4","type":"join","z":"8c6cb615b3919618","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":"false","timeout":"","count":"","reduceRight":false,"x":730,"y":480,"wires":[["6a1e7a11f7b55f8c","cec843e969361d1d"]]},{"id":"6a1e7a11f7b55f8c","type":"debug","z":"8c6cb615b3919618","name":"dynamic","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":880,"y":480,"wires":[]},{"id":"cec843e969361d1d","type":"cronplus","z":"8c6cb615b3919618","name":"","outputField":"payload","timeZone":"","storeName":"","commandResponseMsgOutput":"output1","defaultLocation":"","defaultLocationType":"default","outputs":1,"options":[],"x":880,"y":540,"wires":[[]]},{"id":"5592076892aa31a6","type":"change","z":"8c6cb615b3919618","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"command\": \"remove-all\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":540,"wires":[["cec843e969361d1d"]]}]

GREATEST APOLOGIES

It did work.

Only 1 schedule needs to be active.

That's why I send the WIPE command first.

I goofed when putting your code in my test flow and hadn't realised a mistake with it and the problem is my end.

It does work.

Thanks.

(That is the first one you posted.)