# Help with a trigger node - trick

**URL:** <https://discourse.nodered.org/t/help-with-a-trigger-node-trick/97643>\
**Category:** General\
**Created:** [16 June 2025 04:43 UTC](https://discourse.nodered.org/t/help-with-a-trigger-node-trick/97643 "2025-06-16T04:43:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [16 June 2025 04:43 UTC](https://discourse.nodered.org/t/help-with-a-trigger-node-trick/97643/1 "2025-06-16T04:43:02Z")

</div>

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

This is my `trigger` node.

```auto
[{"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.

---

<div class="post-metadata">

**Author:** ![kitori](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kitori](https://discourse.nodered.org/u/kitori)\
**Post date:** [16 June 2025 05:11 UTC](https://discourse.nodered.org/t/help-with-a-trigger-node-trick/97643/2 "2025-06-16T05:11:45Z")

</div>

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

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/ca5c4245da20618a309bbe3a1029032891f26d92.png)

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [16 June 2025 05:26 UTC](https://discourse.nodered.org/t/help-with-a-trigger-node-trick/97643/3 "2025-06-16T05:26:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [16 June 2025 05:29 UTC](https://discourse.nodered.org/t/help-with-a-trigger-node-trick/97643/4 "2025-06-16T05:29:05Z")

</div>

Ooops.

Sorry.

I think that does work.

## Hang on.

---

<div class="post-metadata">

**Author:** ![kitori](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kitori](https://discourse.nodered.org/u/kitori)\
**Post date:** [16 June 2025 05:35 UTC](https://discourse.nodered.org/t/help-with-a-trigger-node-trick/97643/5 "2025-06-16T05:35:44Z")

</div>

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

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [16 June 2025 05:37 UTC](https://discourse.nodered.org/t/help-with-a-trigger-node-trick/97643/6 "2025-06-16T05:37:37Z")

</div>

# 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.)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [30 June 2025 05:38 UTC](https://discourse.nodered.org/t/help-with-a-trigger-node-trick/97643/7 "2025-06-30T05:38:26Z")

</div>

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