Trigger node and global variables

Hi again folks.

I have a trigger node and I want it to wait a certain time.

So I say:

Send: existing msg
Then: wait for .......

And I can only set milliseconds; seconds; minutes;hours; etc.

I want this value to be a global context value.

Possible?

Not a big deal if it isn't, but as I am working on a thing just now, that would be nicer than having a fixed value.

Alternative node?

Can't you send msg.delay or something similar to the trigger node?

I don't use it but I'm certain I've read something somewhere.

Have you checked the info for trigger node on the side bar?

I think that is for the delay node rather than the trigger node.

I have kind of got it working, but with an external node called mytimeout which allows the trigger time to be set.

Thanks though for the reply.

Appreciated.

How about this ...

[{"id":"5ff626e9.141ac8","type":"delay","z":"4ee0e132.e7df2","name":"variable delay","pauseType":"delayv","timeout":"0","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":440,"y":260,"wires":[["71243006.b8b14"]]},{"id":"31f462f.376889e","type":"inject","z":"4ee0e132.e7df2","name":"set 277ms delay","topic":"","payload":"277","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":40,"wires":[["a9095cd3.3bb64"]]},{"id":"4aa9a154.13781","type":"inject","z":"4ee0e132.e7df2","name":"set 5s delay","topic":"","payload":"5000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":80,"wires":[["a9095cd3.3bb64"]]},{"id":"71243006.b8b14","type":"debug","z":"4ee0e132.e7df2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":180,"wires":[]},{"id":"a9095cd3.3bb64","type":"change","z":"4ee0e132.e7df2","name":"","rules":[{"t":"set","p":"delay","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":40,"wires":[[]]},{"id":"d83ed7d3.dc4ed8","type":"inject","z":"4ee0e132.e7df2","name":"set 1m delay","topic":"","payload":"60000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":120,"wires":[["a9095cd3.3bb64"]]},{"id":"d7293d4a.22f75","type":"inject","z":"4ee0e132.e7df2","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":180,"wires":[["71243006.b8b14","ab715b96.396ba8"]]},{"id":"ab715b96.396ba8","type":"change","z":"4ee0e132.e7df2","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"delay","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":260,"wires":[["5ff626e9.141ac8"]]}]

Nice.

But I think the meaning got lost in translation.

This sends out a pulse train at a given interval.

I'm wanting a time out with a variable amount of time for the time out.

So:
I set the global time out to 20 seconds.
I get a pulse message coming in every..... (when ever).
If it is quicker than 20 seconds, the output is OK.

If the time goes beyond 20 seconds, the output is FAIL.

I can change the time form 20 seconds to 30, 15, 5, what ever.

The idea is that really the time out and frequency are the same. So to avert any erroneous time outs, I get the time and (say) add half again.

So:
Every 20 seconds something happens. I need to see it has happened. (Get an I am working signal.)

If something goes wrong, after time + time/2 the trigger isn't reset and I get a Something is wrong signal.

Clearer?

Indulging me with my flow:
(You will need mytimeout to see it working.)

[{"id":"c85e8713.ea705","type":"mytimeout","z":"15af81c5.64999e","name":"","outtopic":"","outsafe":"on","outwarning":"","outunsafe":"off","warning":"","timer":"30","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":430,"y":390,"wires":[["6e063b00.75032c"],[]]},{"id":"b9a5395f.f8a57","type":"inject","z":"15af81c5.64999e","name":"","topic":"","payload":"2","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":120,"wires":[["75c50db2.3263f4"]]},{"id":"75c50db2.3263f4","type":"function","z":"15af81c5.64999e","name":"","func":"var t = msg.payload\nmsg.timeout = t;\nflow.set('timer',t);\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":240,"wires":[[]]},{"id":"c9086361.d7225","type":"inject","z":"15af81c5.64999e","name":"","topic":"","payload":"3","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":160,"wires":[["75c50db2.3263f4"]]},{"id":"35481fd9.3309a8","type":"inject","z":"15af81c5.64999e","name":"","topic":"","payload":"4","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":200,"wires":[["75c50db2.3263f4"]]},{"id":"1b9fd93e.e3cc07","type":"inject","z":"15af81c5.64999e","name":"","topic":"","payload":"5","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":240,"wires":[["75c50db2.3263f4"]]},{"id":"1d2a5070.ed4c28","type":"inject","z":"15af81c5.64999e","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":390,"wires":[["dd4f1df6.497f2"]]},{"id":"6e063b00.75032c","type":"debug","z":"15af81c5.64999e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":320,"wires":[]},{"id":"dd4f1df6.497f2","type":"function","z":"15af81c5.64999e","name":"","func":"var t = flow.get('timer');\nt = t + (t/2);\nmsg.timeout = t;\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":390,"wires":[["c85e8713.ea705"]]}]

Oh, and you need to press one of the buttons at the top before you start.
My bad.

Clearer yes but if you'd said that in the first place :roll_eyes:

Sorry, I thought I did.

I'm wanting a trigger node with a controllable time out value.

What about, storing a time stamp every time a message comes. Then use a function node to see if the time from last timestamp to current time stamp is less than your global setting, send OK. If it's greater, send FAIL

Yeah, that's possible.

Thanks.

There's always more ways to skin the cat than are in the book.

:smile:

Here is an example...

[{"id":"31f462f.376889e","type":"inject","z":"4ee0e132.e7df2","name":"set 277ms delay","topic":"","payload":"277","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":40,"wires":[["a9095cd3.3bb64"]]},{"id":"4aa9a154.13781","type":"inject","z":"4ee0e132.e7df2","name":"set 5s delay","topic":"","payload":"5000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":80,"wires":[["a9095cd3.3bb64"]]},{"id":"71243006.b8b14","type":"debug","z":"4ee0e132.e7df2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":180,"wires":[]},{"id":"a9095cd3.3bb64","type":"change","z":"4ee0e132.e7df2","name":"","rules":[{"t":"set","p":"maxtime","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":40,"wires":[[]]},{"id":"d83ed7d3.dc4ed8","type":"inject","z":"4ee0e132.e7df2","name":"set 1m delay","topic":"","payload":"60000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":120,"wires":[["a9095cd3.3bb64"]]},{"id":"d7293d4a.22f75","type":"inject","z":"4ee0e132.e7df2","name":"fake pulse train","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":180,"wires":[["4f608851.67b078"]]},{"id":"4f608851.67b078","type":"function","z":"4ee0e132.e7df2","name":"on time?","func":"var maxtime = flow.get(\"maxtime\") || 20000;//default to 20s\nvar thisTimestamp = Date.now();\nvar lastTimestamp = flow.get(\"lastmsg\") || thisTimestamp;\nvar diffMS = thisTimestamp - lastTimestamp;\nflow.set(\"lastmsg\",thisTimestamp);\nif(diffMS < maxtime){\n    msg.payload = \"OK\";\n} else {\n    msg.payload = \"FAIL\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":180,"wires":[["71243006.b8b14"]]}]

you can adapt your solution from this.

1 Like

SO close

I will try to work it out from that.
(maybe not, though. The mechanics are not compatible. Read on please.)

The only problem is this:

Say I have it for 5 seconds.
Pulse. (3 seconds) pulse (3 seconds) pulse (repeat)
All is good.

But! (This is the kicker!)
If I send a pulse, and then there is a 6 (or greater than the delay)........
I don't get the "FAIL" until the next signal.

Given the next signal didn't arrive because the sending thing failed...... It will never arrive and I will not get a FAIL message.

Bed is calling.

I'm calling it a night.

Thanks for the help though.

Again: I appreciate it. It helps me see things from a different perspective, and that can be a good thing as it helps keep an open view on things.
A narrow view can be problematic sometimes.

combine the two flows I gave you and add a reset.

Only takes a little imagination...

[{"id":"eb862e26.25a2d","type":"change","z":"4ee0e132.e7df2","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"FAIL","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":260,"wires":[["71243006.b8b14"]]},{"id":"31f462f.376889e","type":"inject","z":"4ee0e132.e7df2","name":"set 277ms delay","topic":"","payload":"277","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":40,"wires":[["a9095cd3.3bb64"]]},{"id":"4aa9a154.13781","type":"inject","z":"4ee0e132.e7df2","name":"set 5s delay","topic":"","payload":"5000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":80,"wires":[["a9095cd3.3bb64"]]},{"id":"71243006.b8b14","type":"debug","z":"4ee0e132.e7df2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":180,"wires":[]},{"id":"a9095cd3.3bb64","type":"change","z":"4ee0e132.e7df2","name":"","rules":[{"t":"set","p":"maxtime","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":40,"wires":[[]]},{"id":"d83ed7d3.dc4ed8","type":"inject","z":"4ee0e132.e7df2","name":"set 1m delay","topic":"","payload":"60000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":120,"wires":[["a9095cd3.3bb64"]]},{"id":"d7293d4a.22f75","type":"inject","z":"4ee0e132.e7df2","name":"fake pulse train","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":180,"wires":[["4f608851.67b078","5b828c11.6e0874"]]},{"id":"4f608851.67b078","type":"function","z":"4ee0e132.e7df2","name":"on time?","func":"var maxtime = flow.get(\"maxtime\") || 20000;//default to 20s\nvar thisTimestamp = Date.now();\nvar lastTimestamp = flow.get(\"lastmsg\") || thisTimestamp;\nvar diffMS = thisTimestamp - lastTimestamp;\nflow.set(\"lastmsg\",thisTimestamp);\nif(diffMS < maxtime){\n    msg.payload = \"OK\";\n} else {\n    return null;\n}\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":180,"wires":[["71243006.b8b14","b6114284.392cd"]]},{"id":"4d5ce745.142e28","type":"delay","z":"4ee0e132.e7df2","name":"variable delay","pauseType":"delayv","timeout":"0","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":360,"y":260,"wires":[["eb862e26.25a2d"]]},{"id":"5b828c11.6e0874","type":"change","z":"4ee0e132.e7df2","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"maxtime","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":160,"y":260,"wires":[["4d5ce745.142e28"]]},{"id":"b6114284.392cd","type":"change","z":"4ee0e132.e7df2","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":220,"wires":[["5b828c11.6e0874"]]}]