This is a quick update to my node-red-contrib-timeout node for Node-Red. This is as always, available at https://flows.nodered.org also at https://www.npmjs.com/package/node-red-contrib-timeout
The current version then is 1.1.5 which puts out the SAFE message at start-up and starts the default count-down.
Interested viewers will find that as well as the normal msg.payload showing the status, there also exists msg.countdown showing the remaining time in seconds.
You need to activate auto-repeat to use this (v1.0.8 or later) feature. The node is a simple countdown timer, self-documenting. Here is an extract from the readme file:
‘After setting the topic and both safe and unsafe messages, for, for example MQTT (or simply putting 1 and 0 into the two messages) the node is triggered by any input and will send the SAFE message out. If continually triggered nothing more will happen but if allowed to timeout, the UNSAFE message will be sent. Hence this can be used as a watchdog. Options include “repeat message every second” and “auto-restart when timed out”. As well as msg.payload showing “Safe”, “Warning” or “Unsafe”, there is also msg.countdown showing the remaining time in seconds.’
See also in the above image a simple function (not related to the timeout node but exceedingly useful anyway) which can show status info including the time and any object property within the Node-Red editing screen (not to be confused with the Dashboard””) – in this case msg.payload and msg.countdown. The function displays time correctly formatted. I recommend putting this in your Node-Red snippet library.
Number.prototype.pad = function(size) {
var s = String(this);
while (s.length < (size || 2)) {s = “0” + s;}
return s;
}
var date=new Date();
var now=Number(date.getHours()).pad(2)+ “:” + Number(date.getMinutes()).pad(2)+”:” + Number(date.getSeconds()).pad(2);
node.status({fill:”blue”,shape:”dot”,text:now + ” ” + msg.topic+”:”+msg.payload + ” ” + msg.countdown});
See also: node-red-contrib-bigtimer, node-red-contrib-esplogin, node-red-diode
In Node-Red-Contrib-Timeout, It would be very useful to allow an option to pass through payload and topic on output topic, and on safe, warning, and unsafe states… with an option for a pull-down menu for other settings or variables. (like in done in edit switch node and other functions) This would make it a more universal function…
thanks
Hi Pete, have you considered allowing the Countdown seconds and maybe the Warning seconds to be set via an input?
This would need to be something other than msg.payload, as injecting the current timestamp on msg.payload would mess things up somewhat!
Maybe a value on msg.countdown and msg.warning would do the trick, with the option to trigger the timeout timer when the msg.countdown message is received.
My use-case behind this is the something similar to a “sleep timer” that you might see on a TV or set-top-box, where you can get your device to sleep after a chosen period time. For me, this would be for putting our outside lights on for a variable length of time.
Yes, I realise that this can be done using BigTimer, and that is my current solution, but the timeout timer is a nice lightweight alternative, which could potentially be much more powerful with this type of feature.
Just a little food for thought…
Liam, one possibility is to use a ‘flag’ stored in EEPROM on your ESP8266 to ‘remember’ if the device has been triggered on that day, assuming mail is delivered once a day. Using a simple NTP time you could inhibit the ESP8266 output once a mail delivery has arrived for that day. Then reset the EEPROM flag at the start of the next day. EEPROM’s are good for 100,000 + writes but you could use a different flag for each day if you wanted.
Thank you Peter for your prompt reply. I understand there may be consequences to making changes to the code. . . I was just looking for an easy way out 🙂
Cheers from Toronto Canada
Liam
Hello Peter,
I have a mailbox that when mail arrives opening the flap applies power to the esp8266 sending an MQTT message that “Mail has arrived” and casts it to Google Mini, repeating the message every 15 minutes. When I pick up the mail, to save on battery life, power is removed from the esp8266. I used your “timeout node” to stop sending messages once the timeout has expired (no trigger input for 20 minutes).
The problem his when Node Red restarts the timeout restarts also, alerting me again that “Mail has arrived” even though there is no input.
Is there a way that “timeout” could be started in warning mode until the first trigger arrives?. Maybe a check box next to “Safe”, “Unsafe, “Warning” to select “Startup/Restart Mode”
Thank you for all your contributions Peter, from someone who has been around the Sun 76 times and still learning.
Hi – I’m wary of making changes that might affect the many existing users…. maybe a function or other node added to prevent this?
You can guarantee that any change of behaviour will upset SOMEONE….
REgards
Pete
Thanks Peter.
Still would be cool to have the option to start in Timeout Mode on deploy. For my scenario it would make it a one step process so more convenient.
cheers,
Rob.
Hi Peter. Really like the Timeout node but it’s not working quite the way I intend.
Whenever I deploy a flow It’s starting up in countdown mode, not in Timeout mode. For instance I have a stobe light I want to strobe for 1 day (86400 seconds). Safe payload set to 1 and unsafe to 0. No messages. So just want it to be a toggle input/output. Countdown when it receives 1. Timeout when it receives 0.
But on deploy it starts it’s countdown at 86400 seconds. Anyway to start it in Timeout mode?
Thanks.
Rob.
Never mind. I found that I maybe should have been using the Trigger node.
Out of interest what advantages would your Timeout have over Trigger?
Good point, erm, I don’t think TRIGGER has a programmable warning and it can’t send a topic (which of course is handy if your output is MQTT).
1.1.4 onwards – you can set the node to unsafe immediately at any time by injecting “unsafe” to the input. Remember also that you can view the current count at any time.
Still at version 1.1.1 on https://flows.nodered.org/ for some reason!
Tried with auto-restart, same issue – timeout fired at restart of node-red server (without any input given to node)
here are versions —
node-red-contrib-timeout – 1.1.1
node-red – 0.19.5
on Ubuntu 18.04.2 LTS (on a regular computer , not raspberry pi)
Yes, Timeout WILL timeout on restart of Node-Red. The input STOPS the timeout. I just attached a default Timeout node to debug and tested this. After 30 seconds it timed out – that is the intended operation.
Pete
my mistake.
here is what I am trying to do — i have a garage door status hooked to node red. I want to start the timer when it gets the message that door is open. and after a set time (let’s say 30 minutes) unless timer is cancelled (by garage close notification) it will send an alert. any thoughts if I could use bigtimer or timeout node for this functionality ?
Ignore my comments about Auto, I was thinking about BigTimer…
i just installed this node. it seems timer is also triggered on node-red restart (without any input). can you please check ?
Check the auto option. If you are still having any issues, describe exactly along with Node-Red version, BigTimer version and what you are using this on (Raspberry Pi ?) etc.
Great work Peter and thank you. I have been trying to get something similar working but my limited knowledge (still learning @69) of Node-Red programming is nowhere near your standard. This is going to be very useful in several security projects I’m working on.
Appreciate the efforts you and others are putting into helping the newbies get to grips with Node-Red.
Thanks Pete. Great contribution, just what I needed.
Peter – thanks for this – just wondering is there any reason you tied the countdown output into the auto activate option ? i.e. i can not get countdown without enabling auto activate – i have looked at the JS file and can not see a reason for it – but do not want to copy you work just to enable the countdown output
Craig