@jackcfl/node-red-dashboard-2-simpler-schedule 1.1.0

A simple, on/off scheduler node for Node-RED Dashboard 2.0

npm install @jackcfl/node-red-dashboard-2-simpler-schedule

ui-schedule: simple on/off scheduler for Node-RED Dashboard 2.0

A scheduler node for Node-RED Dashboard 2.0 with a clean schedule editor that end users can manage themselves. It combines all of its schedules into one on/off output and sends a plain true (on) or false (off) whenever that output changes, so there are no payloads to configure.

This is a fork of node-red-dashboard-2-simple-scheduler by macdudeuk, used under the MIT licence. See What's different from the original.

Features

  • Daily, weekly, one-time, timespan and duration schedules
  • One combined output: on while any schedule is on, off only when all are off
  • Overlapping schedules work together, with no flicker and no repeated messages
  • Windows that run past midnight (for example 21:00 to 07:00) work correctly, including after a restart
  • Schedules persist across Node-RED restarts, with a backup copy of the previous save
  • Timezone support with automatic daylight saving handling
  • A status badge on the node shows whether the output is on, and which schedules are holding it on

Installation

From the Node-RED palette manager, search for @jackcfl/node-red-dashboard-2-simpler-schedule and install it.

Or from the command line, in your Node-RED user directory:

cd ~/.node-red
npm install @jackcfl/node-red-dashboard-2-simpler-schedule

Then restart Node-RED. Requires Node-RED 3.0 or later and Dashboard 2.0.

Usage

  1. Drag the ui-schedule node from the palette onto your flow.
  2. Open it and choose a Dashboard 2.0 group. Optionally set a timezone and a persistence method.
  3. Wire its output to whatever you want to switch.
  4. Deploy, open the dashboard, and add schedules with + Add Schedule.

How the output works

The node looks at all of its schedules together and sends one state:

  • true while any schedule is holding the output on
  • false only when every schedule is off

It sends a message only when that combined state changes. Two overlapping windows give one true when the first opens and one false when the last closes. Editing an unrelated schedule sends nothing.

Windows (weekly and timespan) hold the output on while they are open. A duration holds it on until its minutes run out. Daily and one-time schedules work like a switch, described below.

Changing a schedule that is running also updates the output. If you delete or disable a running schedule, or edit it so it is no longer running, and nothing else is on, the node sends false straight away.

After a restart or a deploy, the node sends its current state once, about five seconds after it starts.

Schedule types

Type When it fires Effect on the output
Weekly On the selected days, between a start and end time On while the window is open
Timespan Every day, between a start and end time On while the window is open
Duration When you press the play button, for a set number of minutes On until the time is up. Pressing play again restarts the countdown
Daily Every day at a set time Turns the switch ON or OFF, as chosen in the Action dropdown
One-time Once, at a set date and time Turns the switch ON or OFF, as chosen in the Action dropdown

Weekly days: the day you tick is the day the window starts. A window that runs past midnight belongs to the day it starts. Ticking Tuesday for 9:00 pm to 7:00 am covers Tuesday night until Wednesday morning.

Overnight windows: if the end time is earlier than the start time, the window ends the next day. A window with the same start and end time never opens, and the editor will not let you save one.

Example: charge an EV overnight with a weekly window from 21:00 to 07:00 on every day, plus a second weekly window on Sunday from 00:00 to 23:59. The output stays on from Saturday 21:00 until Monday 07:00 with no break.

Daily and one-time schedules

A daily or one-time schedule fires once and sets a switch. The switch stays in that state until another daily or one-time schedule changes it. For example, a daily ON at 07:00 and a daily OFF at 18:00 turn something on every morning and off every evening.

The output is on if the switch is on or any window or duration is on. A daily OFF cannot turn the output off while a window is still open.

For anything that should switch itself off, use a weekly or timespan schedule (or a duration) instead.

If you delete or disable the schedule that last set the switch, the switch is cleared.

Output

Each time the combined state changes, the node sends:

  • msg.payload: true (on) or false (off)
  • msg.topic: the name of the schedule that caused the change
  • msg.active: a list of the schedule names currently holding the output on
  • msg.schedule: details of that schedule
    • id: the schedule ID
    • name: the schedule name
    • type: daily, weekly, once, timespan or duration
    • event: start or end, or startup for the message sent after a restart

After a restart

  • Windows are worked out from the current time, so a window that is open when Node-RED starts is on straight away, including one that started before midnight.
  • The daily and one-time switch is restored from the most recent daily, one-time or single-time weekly action. A one-time action only counts if it happened in the last 24 hours.
  • A running duration does not resume. After a restart it is off.

Persistence

  • File system (default): schedules are saved as scheduler-[node-id].json in your Node-RED user directory. Each save is written to a temporary file and renamed into place, so a power cut part-way through cannot leave a half-written file. The previous save is kept as scheduler-[node-id].json.bak. If the main file cannot be read, the node loads the backup and logs a warning. The backup is one save behind, so the most recent change may be lost.
  • Context store: schedules are saved to a Node-RED context store of your choice. This needs a persistent store configured in settings.js. There is no backup copy.

Timezone

Set a timezone in the node's settings using an IANA name such as Pacific/Auckland. Leave it empty to use the system timezone.

Controlling schedules from a flow

Besides the dashboard, you can send messages to the node's input. Set msg.topic to one of these commands:

Topic msg.payload
add or update A schedule object
remove or delete The schedule ID
enable or disable The schedule ID
trigger The ID of a duration schedule
resend (not used) sends the current state again
list (not used)

For daily and one-time schedules, set action to "on" or "off" in the schedule object. Any payload fields from the original node are ignored.

What's different from the original

  • The output is a single combined true or false. The original sends a message for every schedule start and end, with payloads you type in and choose the type of.
  • Overlapping schedules no longer fight each other, and editing a schedule no longer repeats messages.
  • Deleting, disabling or editing a running schedule turns the output off when nothing else is on. The original left the output stuck on.
  • Weekly and timespan windows that cross midnight are recovered correctly after a restart or an edit.
  • One-time schedules can be set any distance ahead. The original fires them at once if they are more than about 24 days away.
  • Daily and one-time schedules have an On/Off action dropdown.
  • Schedules are saved safely, with a backup copy.
  • The editor colours follow the Dashboard 2.0 theme.
  • The node type is ui-simpler-schedule and the package has a different name, so it installs alongside the original without a clash. Schedules saved by the original are not carried over.
  • The build script works on Windows.

Credits and licence

Based on node-red-dashboard-2-simple-scheduler by macdudeuk. Released under the MIT licence; see the LICENSE file.

Changelog

1.1.0

  • First release of the fork.
  • One combined on/off output, sent only when it changes.
  • Fixed true/false payload, with an On/Off action for daily and one-time schedules.
  • Overnight windows recover correctly after midnight, restarts and edits.
  • Deleting, disabling or editing a running schedule turns the output off when nothing else is on.
  • Long-range one-time schedules no longer fire early.
  • Safer saving with a backup copy.
  • Theme-aware editor colours, overnight and day-of-week hints, and a check against identical start and end times.
  • Node and package renamed.

Node Info

Version: 1.1.0
Updated 4 days ago
License: MIT
Rating: not yet rated

Categories

Actions

Rate:

Downloads

266 in the last week

Nodes

  • ui-simpler-schedule

Keywords

  • node-red
  • node-red-dashboard-2
  • scheduler
  • time-scheduler

Maintainers