Time bounded Condition on Node-Red

Hello everyone, I want to create a time bounded 'if' condition for my RFID system that I created on Node-Red. My task is to provide a condition:
"If detected RFID TAG is not read once again in 30 seconds, give a message"

So, basically I want the timer to start once the rfid tag is detected, then if it is not read once again in 30 seconds, the output is a message"
I am following some JS tutorials on time bounded 'if else' condition. Is there any simpler way or a much better way for this approach on Node-RED. Thanks :slightly_smiling_face:

Best Regards

The trigger node is your friend here. :grinning:

Have a look at the example in the cookbook, it might cover your need as-is.

https://cookbook.nodered.org/basic/trigger-timeout

1 Like

Thanks a lot @kuema, I am trying with trigger node. :slight_smile:

Now, my flow looks a bit like this and I am able to get the desired output when the particular tag is not read again in 30s.

Is there a possibility to display the msg.payload for the failed detected tag(debug 2) to just display the output for a time specified duration(10s)?

Can the "mytimeout" node be useful?

Display where? Do you have a dashboard attached? I don't quite follow. :sweat_smile:

At the moment your output goes to the debug node and MQTT.

If you want to "clear" the message on the debug node, you could use a delay node in parallel that sends and empty payload after the delay of 10s or so.

The MQTT output goes to a SCADA system, it looks like this

I want to clear the message after it is displayed on SCADA system, I will try with delay node

With delay node, I do not think I can erase the msg.payload after a specific duration, it just delays the output as far as I know. I tried to experiment with delay node but it does not suit the purpose.

Would you like to show the particular way in which I can use it to ERASE THE MSG.PAYLOAD AFTER 10s? Thanks a lot in advance.

Best regards

Will this do what you want?

2 Likes

It does exactly that, if you use it in parallel :wink:

[{"id":"4bbd6019.c26b","type":"inject","z":"71d50c24.c428a4","name":"","topic":"","payload":"my value","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":340,"y":380,"wires":[["fff77905.4b00f8","714a858a.90428c"]]},{"id":"fff77905.4b00f8","type":"debug","z":"71d50c24.c428a4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":930,"y":380,"wires":[]},{"id":"714a858a.90428c","type":"delay","z":"71d50c24.c428a4","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":540,"y":440,"wires":[["63b2dfd0.2c33e"]]},{"id":"63b2dfd0.2c33e","type":"change","z":"71d50c24.c428a4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"clear","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":440,"wires":[["fff77905.4b00f8"]]}]
1 Like

Haha, good timing Simon. :grin:

1 Like

I just added one more function node after the 'change' node as I had some MQTT topics to be sent to SCADA. Anyway thanks a lot, it solves my purpose and I have learnt some extra functionality.

Schönen Tag noch. Vielen Dank :slight_smile:

SG

1 Like

Thanks a lot Simon for your comment. It solved the purpose.
Thanks and have a nice day. :slight_smile:

it was @kuema idea :slight_smile:

@kuema The screenshot of my flow which I have sent below, I am facing a situation, where my trigger node sends msg.payload to the 'switch' node in the time duration of '10s'.

My aim is to fulfil the condition: "If in this particular time duration, the same tagID is read again, then send it as a normal condition, 'else' if the tag is not read in this duration, give a message"

Presently, in the 'switch' node:

  1. == previous value (normal condition)
  2. != previous value (alert condition)

But the previous condition for this switch node appears to be the msg.payload it received in the previous event, as the trigger node sends the data in every 10s and not in between this duration what it has read.

I have tried:

  1. In parallel, a delay node(5s) attaching direct to the RFID(MQTT IN) node and output goes to the switch node, so that it compares this msg.payload value received from this node to the msg.payload value received from the trigger node in 10s, which ever comes first becomes the 'previous value'.

But it is not functioning exactly as the condition I am expecting. Can you or anyone has a better possible solution?

Thanks and regards