[Announcing] node-red-contrib-mytimeout

This started out as a learning exercise (hence the lousy name) and turned into something I think others might find useful.

Node-red-contrib-mytimeout is a countdown timer that can be triggered by sending it input. It can be turned off with an off, or a stop or a cancel input message. Any other input will cause the timer to trigger and if already running restart the timer with the existing timeout and warning values.

The timeout and warning values can be dynamically set (overriding the node's set values) by sending a message with JSON in it (see the Readme section of my node-red-contrib-mytimeout repos).

I've also posted a mytimeout example flow which should help with it's usage.

Any helpful comments would be appreciated. If you find any issues just open an issue on the issues page and I'll try to respond in a timely manner.

Thanks

using this node and working well, thanks, is it possible to output a numeric value for on and off?

You could always ask the author...

Actually both of these got sent to me. :slight_smile:

I think you can change the " Timer On payload" and the "Timer Off payload" in the Properties.
I'm checking that now.

Is this what you want?

[{"id":"0e3463d5de466243","type":"mytimeout","z":"b431bcd1.51942","name":"","outtopic":"","outsafe":"1","outwarning":"Warning","outunsafe":"0","warning":"5","timer":"30","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":1150,"y":520,"wires":[["ba574d575218a5ea"],[]]},{"id":"2c5b32d1bbd3d6f8","type":"inject","z":"b431bcd1.51942","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"0.2","topic":"","payload":"1","payloadType":"str","x":990,"y":420,"wires":[["0e3463d5de466243"]]},{"id":"ba574d575218a5ea","type":"debug","z":"b431bcd1.51942","name":"OneZero","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1357.895751953125,"y":406.8888854980469,"wires":[]},{"id":"93e9f666382d3fe5","type":"inject","z":"b431bcd1.51942","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"0.2","topic":"","payload":"0","payloadType":"str","x":990,"y":600,"wires":[["0e3463d5de466243"]]}]

I left "warning" in, you can blank that to avoid getting the warning on the first output.

Hi Neil, thank for looking. Seems to do the same as what i have installed. I am looking for a numeric 1 not a string "1" which isn't interpreted by the next node as 1.

Okay let me figure out how to fix that.

As a temp fix I think you can use a function node and use:
msg.payload = parseInt(msg.payload);
Should really check to see if it's an int or do a catch.

I'll have to look at this later.

1 Like

When I search in the library for mytimeout the only one I can see/find was updated 13 months ago.

Which one is this one of which you speak?

Not sure who @Trying_to_learn was asking. My previous comment was adding a function node, like below. I was in a rush out the door so I couldn't create it then.

But to fix the flow I posted above, @davenrea can try this:

[{"id":"0e3463d5de466243","type":"mytimeout","z":"b431bcd1.51942","name":"","outtopic":"","outsafe":"1","outwarning":"Warning","outunsafe":"0","warning":"5","timer":"30","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":1150,"y":520,"wires":[["36212b13c94b889c"],[]]},{"id":"2c5b32d1bbd3d6f8","type":"inject","z":"b431bcd1.51942","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"0.2","topic":"","payload":"1","payloadType":"str","x":990,"y":420,"wires":[["0e3463d5de466243"]]},{"id":"ba574d575218a5ea","type":"debug","z":"b431bcd1.51942","name":"OneZero","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1357.895751953125,"y":406.8888854980469,"wires":[]},{"id":"93e9f666382d3fe5","type":"inject","z":"b431bcd1.51942","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"0.2","topic":"","payload":"0","payloadType":"str","x":990,"y":600,"wires":[["0e3463d5de466243"]]},{"id":"36212b13c94b889c","type":"function","z":"b431bcd1.51942","name":"function 1","func":"try{\n    msg.payload = parseInt(msg.payload);\n    return msg;\n} catch (error) {\n    // Do these two line as an example\n    msg.payload = error;\n    return msg;\n    // In actual code you can do this\n    //node.log(\"myTimeout: \" +error);\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1260,"y":460,"wires":[["ba574d575218a5ea"]]}]

The catch will catch the "warning" string as NaN. You can comment that out and uncomment the log code instead and you should only log the NaN instead.

In my myTimeout node I'll be trying to do something similar. but I need to make sure I keep the string functionality. I also need to figure out how to accept it from the properties dialog also. Not sure how I'm going to approach this yet.

This works, i actually had used the change node to same effect. My aim was to reduce the number of nodes in the belief it would have lower processor overhead.

The change node would be slightly more efficient than a function node but yes you are way down in the weeds now

Thanks, didn't know the change node would work better.

I'm thinking my code in the function node above (the try/catch) may work directly in the mytimeout node. The caveat being that if someone wants the string 1 or 0 instead of the number 1 or zero they will need to use quotes. I haven't tested this but I will. Still need to get time to sit down and create the pull/code/test. So that's sometime off at the moment (not today).

the function node actually wraps the function code into a sandbox - so there is a small overhead getting the context in and out of that. This won't be present of course if you use the same code in your own node., and isn't present in other core nodes. But it is small.

Sorry and I just noticed this is four years old.

Not a problem. I figured out what you meant. Pete updated his version of Timeout (the original) about 2 years about, I updated mine about a year ago. I think I need to change the color of my timer. I initially used Pete's timeout module for mine but I diverged quite a bit from his. I believe even the operation of the times works differently.

This topic was automatically closed after 4 days. New replies are no longer allowed.