Big Timer is probably the best timing node for Node-Red, providing a general purpose timer as well as handling summer/winter correctly as well as (importantly) lighting up time (for which it needs longitude and latitude). After all you probably don’t turn the outside lights on at 6pm!! You turn them on when it gets DARK. Now with new seconds timer mode AND updated for the latest Node-Red 0.17.0+ including new help formatting and tips on input and output.
What: Node-Red-Contrib-Bigtimer is both a simple timer – and a full-function timer – depending on your needs. At it’s simplest, you set on and off times, the topic and payload you need to go out to, say, MQTT and your longitude and latitude (most browsers will fill this in automatically), you then set your schedule and you are done.
Why: Existing timers didn’t do what I wanted – also – I have a watering system – I want it to run at dusk and dawn every day – but not in December through February (ice)! I had to have control over both days of the week and months. Existing timers didn’t do that either. Many seemed to be based on the old mechanical timers but without moving parts. That won’t do.
Firstly: the name. It’s a timer – but it’s a BIG one – so I’ve called it BigTimer. (note: the original "Scheduler" node is no longer developed – BigTimer does everything Scheduler did and much, much more).
Secondly: it has an input. You can inject various words into BigTimer – and get instant over-ride action. "1" or “on”, "0" or “off”. "auto" or “default”, “timer”, “sync” etc.
Does that need explaining? “on” for manual override to on, “off” for manual override to off (both of which reset on the next auto state change), “default” or “auto” to return the timer to normal operation. More details further on.
Manual Override: If you set the timer to turn on, say at dusk and off at midnight, you can override the setting during the day by sending “on” to the input. This override will reset at the next auto change of state.
If you inject "manual" in conjunction with “on” and “off”, the state will change until the set timeout (in minutes) times out - so if you turn the lights on in manual and forget you did it? The unit will return to default operation in X minutes (which you can set - defaulting to 24 hours - 1440 minutes) after any manual change you make.
You can also send a "sync" command which simply outputs the current state with a side effect of decrementing the timeout counter - handy for testing.
Here is a test setup for BigTimer, just using simply injection nodes:
And here’s what happens if you press ON (a simple inject – you can send that message in the payload by any means you like)…
But what are those other two outputs?
Output 1: is a message – you control the topic and payload – so I use it, for example, as I do, to send a message to MQTT to control something. You can have this message go out once – or every minute. There are other components to the msg object on the first output, there for information only.
In this example (version 1.5.5 of Bigtimer onwards) you see various items in the output -also note that this view is in Node-Red 0.16.2 which is different to older versions – I strongly recommend you upgrade if using an earlier version.
You can see msg.payload which is whatever you enter in order to fire a message off to another node or function to make something happen. In addition (and for information only) we have msg.state, msg.value, msg.AutoState, msg.manualState and others.
For simple use, you can of course ignore the additional outputs, but they are handy for checking. msg.state shows “on”, “off” or “none” and in the case of the first two (on/off) msg.time shows the time for the next change of state.
Output 2: outputs a 1 or 0 every minute when checking (in msg.payload) – you can use that to light up something.
Output 3: puts out another text message in msg.payload which you can set – I point it to a speech synth so it might say “external lighting coming on”. There is one message for the ON state, another for the OFF state. Ignore it if you don’t have a use for it.
And to get this node?
Make sure you are in your Node-Red installation folder (for example /home/pi/.node-red) and type:
npm install node-red-contrib-bigtimer
So in my case, I keep all my nodes under /home/pi/.node-red/node-modules. So I do the install from /home/pi/.node-red
Restart Node-red and Bob’s your uncle – it should appear on the left with the other Nodes. If you happen to have the ADMIN node in Node-red you don’t even need to do any of that – you can install node-red-contrib-bigtimer straight from the admin tab.
In addition, I have recently, as a response to a sensible request from one of our blog readers, changed the code so that if either the ON payload or OFF payload is blank – then no message will be sent at that time – this means you can now easily OR timers together. So if you need several time intervals in a day or other complicated setup you can simply use a number of timers and feel the first output to one common destination!
Here’s an example of TWO timers simply sending stuff to a debug node for testing…
Backtrack for Beginners: Node-Red is a simple-to-use but very powerful visual tool for wiring the Internet of Things and a tool for connecting together hardware devices, APIs and online services in new and interesting ways. It is also a lot of fun.
I control a range of Arduino and ESP-8266 devices using Raspberry PI2 and similar. You can of course run Node-Red and the other tools on a wide range of machines – Orange Pi, Roseapple Pi, Odroid C2 etc using Debian, DietPi, Xenial etc. I even have my normal installation script running on a laptop using Mint Linux.
On this particular Pi I run MQTT (Mosquito with Websockets), SQLITE, APACHE and Node-Red. I started using Blynk as my mobile remote controller then went on to using ImperiHome but today I concentrate on using Node-Red Dashboard which has (IMHO) so very much potential. I also use Nextion touch-LCD display devices for local displays. All of this can be managed within Node-Red. If you find this interesting you might like my home control 2016 post here or the Nextion Wi-Fi Touch Display article.
Here (as requested): to the upper right is a screenshot of a typical setup… click on the image to enlarge.
So in total you have a timer you can set to go on and off at specific times of the day, or dusk and dawn, on certain days, certain months, you can even set it to run on specific days of the month (Christmas day?) or even certain weekdays of every month (second Tuesday).
You can tick a box to have it output on power-up or not, you can tick a box to have it auto-repeat the message every minute or not. You can add positive and negative offsets to the times (including dusk and dawn etc.), you can optionally add your OWN offset to the UTC time of the host computer and you even select a random value within the limits of the offsets (security lighting etc.) You can temporarily suspend the schedule via a tick box or a message.
And here are the words the node will accept at the input to override automatic operations. The input is not case-sensitive.
|sync||simply forced output|
|on or 1||turn the output on|
|off or 0||turn the output off|
|default or auto||return to auto state|
|stop||stop the scheduler|
|on_override||manually override the on time ( specify time as minutes or hours:minutes) - also if you specify the time in minutes, you can use special values like:
|off_override||manually override the off time( specify time as minutes or hours:minutes) - also if you specify the time in minutes, you can use special values like:
|timer||a new feature allowing manual override for X seconds (timer X) - handy for watering systems etc.|
In the drop-down boxes for on and off times you can select times or words like dusk,dawn, sunrise, sunset, night etc. All are dependent on the longitude and latitude you put into the relevant boxes and will adjust every day as necessary.
A good way to learn about BigTimer is to put a debug node (set to show the complete message) on the top output – and inject text payloads (using the INJECT node) to the inputs as demonstrated above.
Out of the first output, as well as the normal msg.payload, you can extract msg.state which might be “on”, “off”, or “auto” – and msg.value which might be 1 or 0. This is so that if you are using say, ImperiHome and store states in global variables, if the time reverts back to auto, you can let ImperiHome know what is happening.
Another way to test BigTimer a good way to do it is like this..
In the FUNCTION nodes to the right of BigTimer, I’ve simply put node.error(msg); and node.error(msg); respectively. The only difference is one has a red bar (error) the other a yellow bar (warn). These make a handy alternative to using the debug node for testing.
Recent additions to the inputs include on_override and off_override. These are in response to requests to be able to change the on and off times from the Dashboard. Please note that override information you inject here (in hours and minute or just minutes, space-delimited) is lost when Node-Red is restarted or the board rebooted.
Not shown on the photos above are two new options – to kill the output on even days of the month, odd days (or of course both).
If you make good use of this node – please put a link to this blog entry somewhere in your writings so people will come back here. Or if proves REALLY useful you could feed my Ebay habit – there’s a link on the right of the blog.
See the Node-Red info panel in Node-Red for up to date information.
Enjoy and please do report any issues back here.
If you like this post – please share a link to it by social media, by email with friends or on your website.
More readers means more feedback means more answers for all of us. Thank you!