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.
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.
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.
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.
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.
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.
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).
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.
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.
- 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.
- 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.
- 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)
- 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.
- 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.
- Improved code that calculates "if it is dark" based on sun position.
- 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.
- 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).
- Jest Unit tests.
- Quality improvements and bug fixes.
- Mainly documentation updates.
- 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.
- Added override functionality.
- 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.
- Fixed some missing dependencies.
- 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 fullcalendar.io as a graphical editor for the schedule, and is using SunCalc for sun position calculations.