Interval function node

Is it possible to create a function node code which can do this.

If receive a topic "Start" will send a signal out at one second interval.
And when receive a topic "Stop" will stop the previous signal from going out.

You can do something close to that with the Trigger node.

It can be configured to start sending a message at regular intervals until it receives a second message that resets it.

You can see that in action as part of this recipe in the cookbook: https://cookbook.nodered.org/basic/trigger-placeholder

1 Like

Going along with @knolleary idea - here is a flow to do it using basic nodes

[{"id":"3e95b40a.1d0f3c","type":"inject","z":"edc07904.d80ae8","name":"","topic":"Start","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":322,"y":132,"wires":[["81bdffba.51685"]]},{"id":"814476d0.d223f8","type":"inject","z":"edc07904.d80ae8","name":"","topic":"Stop","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":322,"y":176,"wires":[["81bdffba.51685"]]},{"id":"4afbf1eb.09de","type":"trigger","z":"edc07904.d80ae8","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"-1","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":1026,"y":154,"wires":[["2745b9da.cd7096"]]},{"id":"2745b9da.cd7096","type":"debug","z":"edc07904.d80ae8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1236,"y":154,"wires":[]},{"id":"3559b2b1.f9d23e","type":"change","z":"edc07904.d80ae8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Whatever","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":762,"y":132,"wires":[["4afbf1eb.09de"]]},{"id":"81bdffba.51685","type":"switch","z":"edc07904.d80ae8","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"Start","vt":"str"},{"t":"eq","v":"Stop","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":556,"y":154,"wires":[["3559b2b1.f9d23e"],["25a83951.0991e6"]]},{"id":"25a83951.0991e6","type":"change","z":"edc07904.d80ae8","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"anything - will be ignored","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":762,"y":198,"wires":[["4afbf1eb.09de"]]}]
2 Likes