Node-RED is a fantastic and powerful yet easy to use programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. For more information on Node-Red go to the Node-Red site.
Big Timer is the the most powerful and best-ever, most comprehensive 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 you should provide your longitude and latitude from Google maps or similar).
After all you probably don’t turn the outside lights on at 6pm!! You most likely want them on when it gets DARK.
BigTimers can be used singly or in groups. Full support is provided for dusk/sunset dawn/sunrise and variations also for day/week/month (and special days) control.
The node offers outputs suitable for MQTT, speech and databases (but you don’t HAVE to use these). You can also manually over-ride the UTC time setting on the host computer if required.
General purpose and very powerful yet simple to use, BigTimer has three outputs, the first of which updates when there is a change of state and presents one of two messages (for, for example, MQTT or other control mechanism)
The second of three outputs offers a simple 1 or 0 every minute in the payload and also presents additional information reflecting the status message in msg.state, message.time and others – see the entire msg output in debug for more.
The third output presents a message which could be used for speech or debugging.
There is also real-time status information displayed below each BigTimer node.
February 11, 2018 Updated to - v2.1.7
I added moonrise and moonset – as well as improving the layout and docs. moonrise code in module sunCalc seems less than perfect so although I added the moonrise and moonset properties in 2.1.3 BigTimer, there were issues now resolved in moonrise and moonset thanks to adding my own checking to the sunCalc module.
Recent additions/changes include timestamp on outputs, additional on/off inputs, improvements to "timer" input option (default seconds) example:
timer X (mins)
timeoff X (mins)
December 9, 2018. Recent features include a seconds timer and even/odd day of the month selection. December 2018 I note I have not yet documented the timer mode – so here goes. In manual override (injection), assuming the timer is off, inject “timer 30” to turn it on for 10 seconds. This is also handy if you have lights turning off at midnight for example and you need an extra hour of light and don’t want to have to remember to turn them off at the end of that period. Inject “timer 3600”.
Update November 25, 2017 – added “toggle” override mode and as I recently realised that the little icon was not quite the right format and might look odd on some people's systems - something pointed out by the FRED people who want to use my nodes... I've updated node-red-contrib-bigtimer, node-red-contrib-timeout, node-red-contrib-diode, node-red-contrib-grove and node-red-contrib-esplogin and also moved them from the "scargill" category to the "advanced" category.
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”, “manual” 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. Please note "night" and "endNight" are included for completeness but are not guaranteed to work depending where you are in the world. Perhaps better to stick with dusk/dawn, sunset/sunrise etc.
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 mode (as against simple override) 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 manually press ON (a simple inject in this example – 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 and second outputs, use these extra messages or not as you prefer.
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.18.5 – I strongly recommend you upgrade if using an earlier version.
You can see the value in 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 not essential for normal operation) 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”. “auto” or “none” and in the case of the first two outputs, msg.duration shows the time until the next change of state and msg.now shows the time in minutes since midnight.
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.
December 2018: Typical use of BigTimer in my home, controlling ESP8266 devices and accepting control from Blynk Android App and their server:
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 PI3 and similar. You can of course run Node-Red and the other tools on a wide range of machines – Orange Pi, Odroid C2 etc using Debian, DietPi, Xenial etc. I even have my normal installation script "The 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 then Node-Red Dashboard which has (IMHO) so very much potential, however it also has lousy RGB control so now I've reverted back to Blynk. I use Nextion touch-LCD display devices for local displays as well as low-cost ILI9340 displays. All of this can be managed within Node-Red. If you find this interesting you might like my home control 2018 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) - as of version 2.0.0 (August 2018) these can be included or excluded.
You can tick a box to have output on power-up or not, you can tick a box to have the node 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.
From 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 is as follows..
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 the node 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!