Big Timer is probably the best timer 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.
Updated to v 1.5 – February 18, 2017
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 is no longer developed – BigTimer does everything Scheduler does 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” 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.
If you set the timer to come 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.0 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 put in there to go off to, some other node to make something happen. In addition and for information only we have msg.state, msg.value, msg.AutoState, msg.manualState and others. You can ignore them but 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 (version 1.2.86 and above)
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 Newbies: 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. I control a range of Arduino and ESP-8266 devices using a Raspberry Pi2 (RPi3 would be even better but I’ve not yet noticed a slow down despite having many, many nodes in Node-Red) as my central controller using the Jessie operating system as of late May 2016 as it now has an excellent backup system. You can of course run Node-Red and the other tools I use 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 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 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.
on (or 1)
off (or 0)
auto (or default)
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.
The best way to learn is to put a debug node on the top output – and inject text payloads (using the INJECT node) to the inputs as demonstrated above. Have fun. I could not manage without this node.
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 vars, if the time reverts back to auto, you can let ImperiHome know what is happening.
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.
Enjoy and please do report any issues back here.