Node-Red Scheduler

I’m Peter Scargill and this is a scheduler for Node-Red (well, more of a timer really but someone surely has already used the term timer) for Node-Red which includes days and months, dawn and dusk with optional offsets and a time-out mode, You may notice this has improved since the first version – I’m learning as I go along.

Please note: This program was replaced some time ago with bigtimer – there is no down side – bigtimer is better. See

As you may know, I’m interested in using Node-Red on the Raspberry Pi (though for this purpose it could be any piece of kit) to control ESP8266 boards via a variety of mechanisms, one of them being MQTT.

Up until recently I would use a Node-Red standard  Inject function to trigger an event, lets say once a day. The Trigger function however is very limited. It does not know about months and it has no idea about concepts such as “dusk” and “dawn” which you might reasonably want to use for a porch light.

SunriseSo, I buckled down and learned how Node-Red nodes were made (with some help later from dceejay Dave and others in the googlegroups node-red group – for which I’m grateful) – and the first thing I did was to start off with the sunrise/sunset node (you’ll need that installed as I rely on one of their routines) to send the time, date, sunrise and sunset information to my boards based on longitude and latitude. In essence, in my case I use MQTT to tell boards about the time when they power up and at 12 hour intervals and in the meantime they maintain their own time in software.

However the more I get into Node-Red the more I see it doing the actual control… so the next thing I did was to sit down and wrote a node – again borrowing from the Sunrise calculations for dusk and dawn settings but gutted to actually send one of two messages (settable) to a message topic (settable and suitable for passing onto an MQTT node for example) at any given time with presets for dusk and dawn and allowing control over days and months as well as a time-out function (i.e. turn on at 10am for 5 minutes).  So a typical example might allow us to turn something on every Wednesday at dusk until midnight but only from November to January. My node of course does not actually send an MQTT message – it just passed the topic and message onto the relevant node (the MQTT node shown in purple here). You could use that message for a variety of other purposes – like sending you a tweet at regular intervals. That is so easy in Node-Red.

The code handles summer time adjustments (well, it did this time, you might want to check that very carefully). You can even offset the dusk and dawn offset times in minutes to save, say, lighting energy, I find garden lights come on WAY before you need them – hence building in the offsets.

Here’s what it all looks like.


So every minute, my node (in blue) self-triggers  (my thanks to dcjay for showing me how to add JS timers) to do it’s calculations and decide whether or not to send a message to the MQTT output node in purple (you could easily alter the code to do something other than send an MQTT output. You will notice in the image above that there are now TWO outputs.. the top output sends a message on change – i.e. when it wants to turn something on or off.. the lower output sends a simple 1 or 0 message every minute regardless – think of it as a regular status output just like the little text and icon indicator under the node itself in the picture above. In this case each output is also sending out a debug message to the debug window in green – that’s just for testing purposes.

If you double-click on my scheduler node, here’s what you get…



Simple enough, give it a name (any name), on-time and off-time which includes every 15 minutes of the day and dusk and dawn dropdown options as well as timeout options for off time… then set your longitude and latitude (from Google Maps or memory if you are like that), the topic you want to send and the two messages – one to turn something on and another to turn something off. In my case I have an MQTT message system going to ESP8266 units – I’ve detailed this elsewhere in the blog.

Tick or un-tick boxes for the weekday/month combination you want. The code is checked once every minute but the top output only sends something out at power up or when the state changes.

If this isn’t powerful enough for you? – let’s say you want something to happen twice a day? – put two of them in there.

2 schedulers[4]

So – to make this work – i.e. to make your own node there are two files – and you just create a directory in your node-red/node-red-nodes folder called scheduler, dump these two files in and restart Node-Red.

The two files are the HTML file and the .JS file called scheduler.html and scheduler.js respectively.

If you make good use of this mode, a credit would be encourage me to support it.

Also if you spot any mistakes especially in the timing – or have ideas for improvement – do let me know.

The purpose for the timeout to the end time options – is so you can say for example – turn a sprinkler on every night for 5 minutes after dusk. And that’s exactly what I plan to use it for – but only in the summer months!

Attach for example an MQTT node onto the first output and put your broker details in there. The node will pick up the topic and message from my node.

And finally  – this code is deliberately NOT constantly sending out the ON instruction every minute but only when the state changes. At any time you can press the button on the left of the node to force an output of the currently relevant message.

Enough of this – here are the goods – no guarantee implied.

Some folk had issues reading the SOURCE CODE files – so I’ve put the files on Github here..

This node is relatively simple but I think that’s the point. It still took me several days to get it right and I’d appreciate any testing reports.  My next job is a thermostat node and that’s coming along nicely.

Make sure you sign up to the blog to be kept up to date or, if you prefer social media – there’s always  or


70 thoughts on “Node-Red Scheduler

    1. It's down to time - it is a learning to use Github and I'm spending what time I have improving the code. As of 15 mins ago I've fixed a timing problem - did it completely the wrong way before...and to be honest right now having just a few people playing with this works for me. So - get the latest, read the blog - it now shows you how to add a test injector - and in timer mode the status is updated underneath the node itself. This is now a very useful tool. Just needs testing to make sure it will work utterly reliably 🙂 Thanks for comments and fixes so far - keep them coming. Like - do we want two on-off times or are we happy to use 2 modes for that...

  1. Right - now the node has it's own icon - I've improved my use of normal naming conventions, fixed an issue with timing and improved some of the naming for messages.

  2. Hi Peter,

    I can't seem to get these to work. I'm using the latest NR release on a Pi2. Putting these files in my user nodes folder gives me an error that scheduler.js cannot be found. If I put them in the node-red/nodes folder, I get the error:

    “use strict”;
    9 Apr 12:48:23 - [warn] ------------------------------------------
    9 Apr 12:48:23 - [warn] [scheduler] SyntaxError: Unexpected token ILLEGAL

    1. It's OK, I got it. Copying from this website changed all the single and double quotes to "smart" quotes. It would be great if you could put the files up onto github.

      Regards, Julian.

      1. In fact, the whole things was a mess, I had to correct 3 different sets of quotes and a load of formatting issues.

        I took the liberty of rationalising some of your block statement formatting too - the use of if and other blocks without {} is generally frowned upon as it can lead to logic errors that are hard to spot. Especially as you have a lot of nested if's some in different styles.

        Do you want me to put the corrected files up onto my github profile?

        1. Drat! It's no good, there is something else wrong that I cannot spot I'm afraid. I managed to get rid of the obvious errors but it will only load from the node-red/nodes location (rather than user nodes locations) and when I try, it hangs the admin interface.

          Any chance you could send me copies of the working files? Or post them to the Google group?

          1. Do you want to send yours... or do you want me to simply send you my latest copy? - Oh , I've just realised there's an email like mine but diffent in the top left here next to your name... ??

          2. See the updated blog - I have removed the source code (I cannot find a decent source code utility for WordPress that doesn't mess something else up) and put the files on Github.

        2. Well of course it was a mess - I'm still developing it! If you'd care to send your update I'll go through it as I'm busy making changes right now. I suggest at this point it would not be sensible to put it on a github for the same reason I have not. It's new, I'm making it up as I go along and getting feedback. At some point in the future I'll stick it up on NPM. Thanks. Oh, my email address... pete at if you'd care to send your updates.


          1. Hi Peter, thanks for doing that. The email address is valid by the way, I just use a different address on every site! Helps manage spam issues.

            As you've probably realised, you don't need to worry about putting something half finished on github, most of the stuff there NEVER gets finished! Including most of mine - I'm TotallyInformation on github btw. In fact, the only fully finished repo I have is the NR moment node.

            I'll grab a new copy from github and get that to work first then I may send you some suggested reformatting if you are happy.

            1. Hah, well yes I had gathered that a lot of stuff there never gets finished.. Thankfully I've found a few. Well I have 2 items up there (the first one I did so long ago I could not remember how to use GitHub. However now I have the Github desktop for Windows it is all coming back. I've added the icon up there as well and yes I did a little reformatting of the code. I'm new to node-red but I've been programming for some time and I do not like the way automatic formatters work I'm afraid. I generally use NotePad++ who's formatting plug-ins are not that clever. I eventually formatted the JS file on Eclipse (Windows) but for reasons beyond me if I try to edit an HTML file it simply tries to display it in an internal browser so that was by hand in Notepad++

              If I have my timings right this should work a treat now and I can concentrate on my thermostat node (which I urgently need as we're moving house shortly!!)

    1. Ah now I've always wanted to talk to someone who has bought one of these. Is this going to simply corrode in the soil? I thought you had to use stainless steel? That is exactly what I want too. I could read the analog value from a sensor via MQTT and then apply a timer accordingly... I have a watering system which runs on a 12vc solenoid (or will when I take the replacement 12v power supply over there in May - the last one died due to rubbish electricity). I've looked at these before and just though... corrosion... Have you done anyhing with these?

  3. We will have to wait and see. There is a very similar device available that has a relay built in to open a water valve so they must be intended for permanent installation. If it does corrode then I'll try different metals. The copper plated steel earth spike for the power system doesn't corrode and, I guess as the currents are miniscule then galvanic erosion shouldn't be an issue. I'm going to use one of the 24v irrigation valves that are very common in the merchants here.
    On another issue, I've just ordered a ready built unit from Sophia, Bulgaria. It looks nicely made, mains powered and perfect for a job I have. He has managed to set it up as a webserver on first power up to allow configuration from a browser which is clever. It then switches over to MQTT but (I think) still allows browser access as well. There are masses of code on GitHub for it, follow the WiKi link.

    1. Yes, your point about galvanic current - that's what I was thinking about - corroded battery compartments etc.. but if the current is tiny that's not such an issue. I note the copper is tin-plated.. I don't know whether that's a good or a bad thing in a plantpot - do let me know how that turns out. I would have thought stainless steel was the answer but then you can't plate that onto a board.

      We've been working on VERY similar software. I've developed the MQTT software (TUAN's code) to do all sorts of IO magic on the ESP-12 and right now we're trying to integrate the power-up-web-server part but it's messy right now and throwing out all sorts of warnings.. I really want to end up simply with a subroutine call at the start of my code that if a button is pressed goes off and creates a temporary website. The code that is out there involves web page compression that won't compile under Eclipse/windows etc... (there is no need for images on a simple setup web page so I'd really like to find a much simpler version). That board looks good - not cheap though.

  4. Hi Peter, you probably saw that I cloned your repo to my own (TotallyInformation) any changes I've made have been committed back to there. Mainly just sorting out {} brackets and other JSHint issues.

    I used to use NP++ but switched to SublimeText and then to Adobe Brackets, about the only good thing they produce! It is actually written using node.js. Has many of the features of Sublime but is a lot faster. With JSHint instead of the default JSLint and with the interactive linter plugin, you can immediately spot any issues.

    For some strange reason I can only run your node if I put it under the main node-red/nodes folder not in the userDir/nodes folder. Odd but at least it works for now. I need to rethink my strategy for scheduling now I've moved everything onto my new Pi2. But I'm doing some work on email integration first. I want to be able to control NR by email and to be able to send info out on request. The last part is easy, the former not so much.

    Good luck with your Thermostat code. Julian.

    1. Hiu Julian

      Your code will get out of date as I update mine??

      Also - I tried Brackets. Looks good but if you take the scheduler.html file, dump that in there and mess up the formatting of the options for example - changing the indents on individuals - I could not find a beautifier for Brackets that would fix this for you? Ideas?

      1. Hi again, I can simply update from your repo on a different branch and merge if I need to. Or if you let me know if you take the changes you want (if any) back into your code, I'll just blitz it.

        Re Brackets. There is Beautify ( which I've used to reformat HTML. But generally I don't do that to JavaScript as I tend to want to understand the code as I go so I tend to reformat as I'm reading. Rather like I did with your code. In any case there are, of course, a number of different "house styles" and my style wont suite everyone (I hate having opening curly brackets on their own line for example as, to me, it breaks the pattern of reading - probably because I started life with COBOL, PL/1, APL and other high-level languages).

        1. Thanks for the info Julian. I'm VERY new to GIT but as I understand it you can indeed make a copy and do your stuff. I would not mess about though as I'm about to make more changes:-) Right now I'm setting up a second Raspberry Pi2 with knowledge I've gained recently so as to have a "clean" version - as against the current one which is full of abandoned experiments 🙂

          1. No problem Peter, I've moved on since your module works anyway - though I've not yet included it "live" in my project, I sure I will since I need something like it for some of our house lighting.

            It would be really nice if you could package it for npm of course 😉

  5. Hi, just wanted to know what software do you use to make the little graphs on this article (and the others) with nodes and links between them. I found them very nice. thanks.

  6. Peter,
    Since your post about node-red I've been getting deeper into it and am finding it really useful, I've just come across your scheduler node and have been trying to get it to work on my RPi, first model, but can't seem to get it to appear in the list of nodes.
    I've tried copying it to various folders but it just doesn't seem to be recognised, will it work OK on the earlier RPi? and any suggestions as to where it should go?


      1. Hi, I had the same problem. For some reason I haven't been able to fathom, it only works when put into Node-Red's own nodes folder. It does not work if put into any of the user nodes folders.

  7. Hi Peter,

    Thanks for your job on scheduler. Just a question... I don't answer the folowing sentence :
    "The purpose for the timeout to the end time options – is so you can say for example – turn a sprinkler on every night for 5 minutes after dusk. And that’s exactly what I plan to use it for – but only in the summer months!"
    How do you specify the timeout and where?
    Additonnaly, would you please explain the usage of {out1,1} option? Is it possible to add an other term ( like {out1,1};TRUE )? What separator have to be used?


  8. Hello Peter,
    Been testing your scheduler for a while and it is working fine. I looked deeper into it, actually wanted to extend the options to include also 2359. Then I saw something, for start value options starting from 1290 it looks like this:

    Should it not be

    and so on?

    Kind regards, Walter

  9. I don't know why but what I tried to explain was not presented correctly in the posting, I try again modifying the tag (removing the initial 21:30
    option value="1315">21:45
    option value="1330">22:00
    option value="1345">22:15
    option value="1360">22:30
    option value="1375">22:45
    option value="1390">23:00
    option value="1405">23:15
    option value="1420">23:30
    option value="1435">23:45
    option value="5000">Dawn
    option value="6000">Dusk

    Should be

    option value="1290">21:30
    option value="1305">21:45
    option value="1320">22:00

    and so on?

  10. option value="1290">21:30
    option value="1315">21:45
    option value="1330">22:00
    option value="1345">22:15
    option value="1360">22:30
    option value="1375">22:45
    option value="1390">23:00
    option value="1405">23:15
    option value="1420">23:30
    option value="1435">23:45
    option value="5000">Dawn
    option value="6000">Dusk

    Should be

    option value="1290">21:30
    option value="1305">21:45
    option value="1320">22:00

    and so on?

  11. Dear Pete,
    I am about testing TheThingBox distro a bit and I wanted to install your Scheduler there. The thing is, I hardly remember how I did it earlier...just something tells me it was done manually...or was it possible with npm?

    Great if you could enlighten me...

    Thanks & best regards,

    1. You'll need duskdawn as a dependency.

      NO guarantees but here's what we use in a script - so assuming you're in the node-red directory in a terminal - I now use WINSCP but not that horrible terminal - I installed putty and there's an option in WINSCP to use putty - makes life easy as the right mouse button does a paste from windows..

      So change below to wherever your node-modules directory is... and..

      npm install suncalc
      wget -O
      mv scargill-scheduler* node-red-contrib-scheduler
      npm install node-red-contrib-duskdawn

  12. I keep trying to get this node but all I get is: -

    npm ERR! 404 Not Found
    npm ERR! 404
    npm ERR! 404 'node-red-contrib-duskdawn' is not in the npm registry.
    npm ERR! 404 You should bug the author to publish it
    npm ERR! 404
    npm ERR! 404 Maybe try 'npm search red contrib duskdawn'
    npm ERR! 404
    npm ERR! 404 Note that you can also install from a
    npm ERR! 404 tarball, folder, or http url, or git url.

    npm ERR! System Linux 3.18.11-v7+
    npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "node-red-contrib-duskdawn"
    npm ERR! cwd /home/pi/Node Red/nodes
    npm ERR! node -v v0.10.38
    npm ERR! npm -v 1.4.28
    npm ERR! code E404
    npm ERR!
    npm ERR! Additional logging details can be found in:
    npm ERR! /home/pi/Node Red/nodes/npm-debug.log
    npm ERR! not ok code 0

    Any suggestions?

  13. Hi Phil

    I've no idea - my code is not in any registry and I've no great desire to ensure it is - a bit of a cheap the authors of that who are also volunteers... however... here without anything missing is what we actually have in our script - bearing in mind that you should be in your node-red directory when you do this - or if you set it up as root, in something like /usr/lib/node_modules (don't ask me why - logically I'd have expected the node-red directory to be in the root folder if a root user set it up - but then I'm only a Linux relative newby .

    # Install suncalc, duskdawn, grove, scheduler, mysql & pushbullet
    echo -e '\n\n====================Installing Duskdawn node ================\n\n'

    cd /usr/lib/node_modules
    npm install suncalc
    wget -O
    mv scargill-duskdawn* node-red-contrib-duskdawn
    npm install node-red-contrib-duskdawn

    wget -O
    mv scargill-scheduler* node-red-contrib-scheduler
    npm install node-red-contrib-duskdawn

    This definitely works - I've used it on Raspberry Pi and it has also been used in DROPLETS...

  14. Just as info if you would like to get the thing going in TheThingBox distro. This is what I did, partly manually copying:

    1) Log in as root (default for TheThingBox) with Putty and WinSCP

    2) In Putty

    cd userdir
    npm install suncalc
    Check that it was installed in userdir/node_modules

    3) In Putty
    wget -O
    unzip node-red-contrib-scheduler.zipmv scargill-scheduler* node-red-contrib-scheduler
    mv scargill-scheduler* node-red-contrib-scheduler

    wget -O
    mv scargill-duskdawn* node-red-contrib-duskdawn

    4) In WinSCP

    Move the newly created 'node-red-contrib...' folders from userdir to /node_modules
    Navigate to /node_modules
    Open the folder 'node-red-node-suncalc'
    Copy the subfolder 'node_modules' to a disk (to the left side of WinSCC gui)
    Navigate now to /node_modules/node-red-contrib-scheduler
    Copy the 'node_modules' folder to here
    Repeat this for node-red-contrib-duskdawn

    5) In WinSCP

    Navigate back to /userdir and clean up downloaded files if needed

    6) In Putty


    7) Once rebooted, you should find nodes in 'advanced' section for sunrise, scheduler and duskdawn

    1. Sounds great Walter. Having just finished updating a Pi to the spec I want, I wonder how the Thingbox version compares because my way is likely the hard way (takes a while to setup)... I have:

      Node + node-red
      Ramlog (important)
      Latest Raspbian with Linux 4.1+
      MQTT (one has Mosquitto, the other has another MQTT server)
      MywebSQL SQl manager

      How does that compare to the Thingbox version?

  15. Thanks for the info. I just get loads of errors when I try it.
    I think I'm going to start from scratch, I updated to the latest Node red and I have node red folders all over the place and I've lost the plot, some things install OK and others don't ??

    I'm a bigger Newbie!

    1. Don't knock yourself - it can be a pain to set up.... one option is - if you look at the home control page.... my friend made a script (which I can't get to work on a PI yet) for those DROPLETS - explained in "Home Control 2015 or at least linked to - you get a month's free trial - it's basically linux online..... and the script sets up pretty much everything we do without any manual intervention - including Node-Red and all the various nodes... costs nothing but time if you want to give that a go.

  16. Thanks Walter and Pete,
    Followed the instructions and now got it working, good tip on using Putty from within WinSCP it made navigating around the folders a lot easier with copy the path from WinSCP to putty.

    Now to get the S20 socket working from scheduler, I think that maybe a tad more difficult!

  17. I'm new to node-red and love this module,
    I have a home automation set up, using your module and XRF (radio) light and temp sensors.
    I'm just wondering where the module gets its time from as in the UK we move our clocks back and fore twice a year.
    I' like to get the time from a local server.
    Thanks again for a great module

      1. Raspberry Pi, running Thingbox. Pi configured to local time + DST. Debug window shows correct (DST) time.
        Scheduler installed via npm Dusk dawn seems to work fine.
        However I need to select a time 1 hour earlier than required to switch on / off lights. easy enough.
        DST finishes at midnight tonight, so I'll see what happens then.
        Once again thanks for a great module.

  18. hi. I just can't get this recognised by node-red. when you say "install" do you mean just copy the files across to the required directory? i've done this and also issued the npm command as per their site but neither has resulted it in the node appearing in my menu bar. please can you let me know if i'm doing something wrong? i'm using thethingbox and have placed the files in root@thethingbox ~/thethingbox/node_modules/node-red/node_modules Others in that folder are in folders called ttb-node-NAME so I've tried that too but no joy.thanks, don

    1. Forget scheduler... install using npm. So in your .node-red directory and NOT anywhere else.... npm install node-red-contrib-bigtimer

      scheduler is the predecessor of bigtimer - you'll love it. Don't "place" any files - use npm install.


  19. So awesome! I use it to manage my home automation.

    I notice a strange behavior when there is no action planned. When no action is planned, 1st output ticks Off value. Is it possible to no more tick when no action is planned ?

    Thank you!

    Best regards.

  20. Hi, what to do when the scheduler does not appears in the node red web gui after npm. I can see its folder installed correctly? Thank you

  21. Hi,
    I am a beginner in Raspberry pi and Node-red. I actually have a Raspberry Pi 3 I need to install the Scheduler Node but it doesn't work.
    I used that command to install the Scheduler Node : npm install node-red-contrib-scheduler
    I don't know if it isn't compatible with the latest version of RPi or i need to install something else ?
    Please help me !!

    1. So.. sitting in your raspberry pi home page go to the .node-red folder

      i.e. cd .node-red

      From there (assuming you are in there as user PI) the command you gave should work - you do, when finished have to restart node-red - or reboot as you prefer. This applies to all node installs - they don't normally show up until you restart node-red. If you do this from the right directory - you should find scheduler at /home/pi/.node-red/node_modules

      1. even if the command i use to install Scheduler returns errors, in the directory /home/pi/node_modules i found a folder called : node-red-contrib-scheduler

        i reboot the RPi and i there is no Scheduler Node in the localhost page of Node-red

        1. I have no answer. Assuming you used an up to date Node-Red and installed everything as user Pi then this should work.

          If your node-red is installed differently you will need to find where it is installed. The settings.js file in there has an option to include other directories.

          Right now are there any other libraries appearing in your /home/pi/.node-red/node_modules directory?

          1. I didn't install node-red it's include in the Raspbian Jessie last version.

            In the /home/pi directory i have :
            1: .node-red
            2: node_modules (node_modules not include in .node-red !!)
            ... and others

            In the /home/pi/node_modules directory i have a lots of files like:
            firebase , nan , rpio, suncalc ....

          2. In the /home/pi/node_modules directory i have a lots of files like:
            firebase , nan , rpio, suncalc ....

            and also node-red-contrib-scheduler

      1. this command end with some errors :

        npm WARN enoent ENOENT, open '/home/pi/package.json'
        npm WARN pi No description
        npm WARN pi No reposity field.
        npm WARN pi No README data
        npm WARN pi No licence field.

  22. I've just realised - you're installing scheduler. Don't. Install node-red-contrib-bigtimer instead. Scheduler is an early version of this and no longer updated.

    I will update the blog accordingly. You will get the same warnings.

        1. even if i use node-red-contrib-bigtimer i have the same problem ; there is no bigtime icon in the localhost page of Node-red !

          1. Unfortunately, Node-Red as installed (as against re-installed) in the Pi is not in the /home/pi directory - it is in /usr/lib/node_modules/node-red

            Stand by for updated instructions

  23. In directory /usr/lib/node_modules/node-red : there is no node-red-contrib-bigtimer (that i just installed before) but in the /home/pi/.node-red/node_modules the folder is there !

    So i go to the directory /usr/lib/node_modules/node-red as a root and i install SCHEDULER and BIGTIMER, then i restart node-red and it work!

    Thank you very much for your help and for this amazing technology blog. THANK YOU !

    1. Yes things have changed a little and I'm updating my info - I have mine running in /home/pi/.node-red/node_modules now but if that is working for you - that is fine... suggest you scrap scheduler because it may have bugs - I stopped developing it some time ago - BIGTIMER is much, much better and you can use as many of them as you like in a project without any problems.

Comments are closed.