Light Scheduler


Light Scheduler is a node-red node that provides a weekly schedule, and is mainly focused on controlling light in home automation scenarios but could be used to control anything in your node-red setup.

PLEASE NOTE: I try to keep up with all issue reports at github, so please make sure to report any findings so that I have a chance to look into the problem! If you have any improvement suggestion, those are also most welcomed!

Docker: Please note that it's very common that node-red instances that runs in docker containers have the time settings wrong, and especially the time zone. I will try to detect and report on faulty settings so that these problems can be resolved faster.

Main features

Graphical Schedule Editor

The graphical scheduler makes it quick and easy to define when you want your output to turn on / off. The schedule is on a weekly basis, so each week day can be individually defined.


Schedule Randomization

On top of the schedule a randomization of the start and end-times can be added by defining a Randomness value in minutes. The start and end-times will be offset positively and negatively with a random time up to the defined number of minutes (Example: a value of 5 equals +/- 5 minutes). 60 is the maximum random time that can be configured.

Dusk / Dawn overrides

To save energy it's nice to be able to only have the lamps and other functions only turn on / off when it bright / dark outside. The Light Scheduler default is to calculate the sun's position for the given position (latitude / longitude) and make sure that the output is only triggered to on / off based on both the schedule and "it it's dark" outside. The sun elevation threshold can be used to control how early / late this setting will have effect.


The automatic state of the Light Scheduler can be overridden by injecting a string in msg.payload. Overrides

msg.payload can be either 'on', 'off', 'schedule-only', 'light-only', 'stop' or 'auto'. Auto will remove the override and make the light scheduler work as normal. Schedule Only will ignore the light level and control the output only according to the schedule. Light Only will ignore the schedule and only care about the light level. The stop keyword can be used to suspend all output from the node.

The override functionality could for example be used to force lights to turn on when motion is detected, but with the condition that it's dark.

Motion Override

External Trigger

When a message with the msg.payload set to 'trigger' is received, the schedule is evaluated and the output is triggered according to the result of the evaluation result. The only exception is when the stop override is in effect since that will block any output from being sent.

Customizable on/off payloads (and topic).

Since this node don't forward any input msg to the output, the payloads for both the on state and the off state must be defined. It's also possible to define the topic (if needed).

Controlled output

The Light Scheduler have three modes that control how and when a message will be sent:

  • "when state changes" - Will only output a message when the state changes. The state is evaluated on a minutely basis, so it can take up to a minute after deploy of a new configure before the output it triggered.
  • "when state changes + startup" - Will only output a message when the state changes and directly after a deploy and a restart of node-red.
  • "minutely" - Will only output a msg on a minutely basis even if the state have not changed.

Planned features / changes

These are some of the planned but not yet implemented features:

  • Date-based schedule exceptions (for holidays etc).
  • Lux-based control (instead of sun-position based).
  • meta-data output (JSON data with information about current state and next change).

If you have any suggestion, please don't hesitate to report it as a new issue on GitHub. For a list of suggested improvements please see open enhancements on github.


v0.0.15 (May 23, 2019)

  • Quick fix for bug #33 causing gaps in the schedule when using randomization and having events back-to-back over midnight. For example an event that ends at end of day midnight (24:00) on Saturday and another event starting at Midnight (00:00) on Sunday.

v0.0.14 (May 3, 2019)

  • Added a first version of a "Light Scheduler Filter" node to the package. This one has the same basic settings but works as a filter for incoming messages. Passing the input to the first output when there's a match and the second when there's no match.

v0.0.13 (April 30, 2019)

  • Fixed the trigger keyword, it now always trigger output regardless of previous output.
  • Cleaned up the readme docs.
  • Fixed problems regarding initial evaluation that could be the culprit for issue #28 (No output produced)

v0.0.12 (April 9, 2019)

  • Added schedule randomization. You configure the max number of minutes to randomize start and end-times for the schedule.
  • Fixed #15 (Node-red crashes). Error when no Latitude / Longitude is configured.
  • Fixed #16 (Problem with when-state-changes?). Now obeying the "when state changes" setting on node-red restart and for newly placed nodes.
  • Merged pull request #26 by @WizBangCrash that fixes a state change compare to cater for objects not referenced
  • Merged pull request #25 by @davidevertuani that Adds a "trigger" keyword to the accepted inputs.

v0.0.11 (December 7, 2017)

  • Added a sun elevation threshold to the dusk/dawn section. It's now possible to adjust how early / late the sun position should affect the output. Sun elevation over the horizon is used instead of a time-offset, this will cater for a more consistant result over the year as the sun trajectory changes over time. (Fixes issue #3)
  • Added drag-and drop. Thank you @erikalveflo!
  • Fixed problem with schedules ending at sunday midnight (Issue #6). Thank you @erikalveflo!
  • Added setting for showing the Sun elevation in the Node Status.

v0.0.10 (December 5, 2017)

  • Improved code that calculates "if it is dark" based on sun position.

v0.0.9 (September 1, 2017)

  • Fixed payload type fault. The type did not get saved correctly.
  • Changed dusk / dawn edit control to be more clear.
  • Added setting that controls when the node send out a message.

v0.0.8 (August 30, 2017)

  • Improved unit tests.
  • Fixed fault that caused event that ended Saturday at midnight (Sunday 00:00) to be faulty interpreted.
  • Changed Node status message to not show payload.
  • Global configuration node now gets the latitude and longitude from the browser (if available).

v0.0.7 (August 22, 2017)

  • Jest Unit tests.
  • Quality improvements and bug fixes.

v0.0.6 (August 21, 2017)

  • Mainly documentation updates.

v0.0.5 (August 21, 2017)

  • New storage format for schedules. (Unfortunately means that old schedules are lost and must be added again).
  • New graphical schedule editor (should work better for all browsers).
  • Started to prepare for unit-tests.

v0.0.4 (August 13, 2017)

  • Added override functionality.

v0.0.3 (August 12, 2017)

  • Added "Only when dark" setting. If checked the On payload will only be sent when the schedule matches and it is dark.
  • Fixed some typos which prevented the "Only when dark" setting from working correctly.

v0.0.2 (August 11, 2017)

  • Fixed some missing dependencies.

v0.0.1 (August 11, 2017)

  • Initial version


This node was initially based on tyrrellsystems's node-red-contrib-simple-weekly-scheduler but has evolved to now be more or less totally rewritten. It uses as a graphical editor for the schedule, and is using SunCalc for sun position calculations.