Cron Plus - Feature request - start up initiating & triggering of relevant schedule

Hi, I really like the many possibilities and flexibilities w this node. So I just wonder, something I realize I miss, a setting that makes the node wake up at startup and activates the current relevant schedule. Like inte the example below; depending on when the node is (re)started it should check which of the shedules is currently active and then trigger that so the payload is sent out. If sun is up, I would expect the sunrise schedule to be triggered and the opposite if the sun is already down (of course also take into account any eventual configured offsets)

With kind regards, Walter

Walter - your image is not accessible as it is stored on 'private-user-images'.
Could you just do a screenshot of your NR flow and post that?

I understand the use case. it's been requested before, but the challenge is there aint one correct behaviour that suits all. Not that I can see anyhoo.

Consider a few examples:

Example 1: Daily schedule

Schedule:

Every day at 09:00

Node-RED starts at 11:30.

Questions:

  • Should Cron Plus trigger immediately because today's 09:00 event was missed?
  • Should it do nothing because the event is already in the past?
  • Should it only trigger if startup occurred within a configurable period after 09:00?
  • How would it know whether the scheduled action was already performed before shutdown?
  • What if user doesn't want or need this behaviour?

If the scheduled job feeds a dog, triggering late could be useful.
If the scheduled job sends an email, triggers an alarm, or charges a battery, firing late may be bad.

Example 2: Repeating interval

Schedule:

Every 10 minutes

Node-RED starts at 09:08.

Should it:

  • wait until 09:10?
  • fire immediately?
  • fire immediately only if less than ½ the interval has passed since the previous schedule?
  • attempt to "catch up" on missed executions? (How would it know?)

Different users will want different options.

Example 3: Solar schedules

Schedule:

Sunrise -30 minutes

Today's event occurred at 07:15.

Node-RED starts at 11:30.

Should Cron Plus emit the event immediately because the startup time falls within the "daylight" period?

Or should it not, cos the sunrise event itself has already passed by more than 4h?

Again, both behaviours are reasonable depending on the application but I bet there 5 more expectations users would want!.

Example 4: State versus event

Suppose a flow uses:

Sunrise -30m => turn pump ON
Sunset +30m => turn pump OFF

User might need the correct state restored after a restart.

However, Cron Plus has no way of knowing:

  • whether the pump is currently on,
  • whether another flow or user action changed the pump state (and doesn't want node-red to alter that just because it restarted (because it was deliberately/manually overrode today)
  • whether the earlier event successfully executed

Determining the desired state is imo a state management problem not a scheduling problem.

The main problem

The scheduler can not easily determine:

  • whether missed events should be replayed,
  • how many should be replayed,
  • how old is "too old",
  • whether replaying them is safe,
  • whether the user actually wants the resulting action to happen (this time)

Because of all that :backhand_index_pointing_up: a startup trigger feature becomes a complex set of rules and edge cases ( different users will deffo want different behaviour)

IMO, in most cases it's better for the flow itself to decide what to do on startup by querying Cron Plus for the last/next event and along with other related state, have flow logic that does (or doesn't) do the thing!

So you know, I have mulled this over quite a few times (and I haven't even mentioned a tenth of the considerations I've made in my noggin on this matter) - but never reach a satisfactory set of rules/UI that would work for all users (and not be overly complicated). If you have a solid idea I'd love to hear it?

With a repeating inject we can use a function node and file based context to pass only one message in a given time period, regardless of restarts.

I don't think we can currently do this without a function, but I guess the delay node could be modified to retain a timestamp [per topic].
And a when gate can provide further filtering:

Agree fully that this is a hard problem. Solutions might end up being more complex than might be warranted - not sure.

However, I think that if you look at the Windows task scheduler, it does have settings/overrides for at least some of these situations. Might be worth a quick look.

Assuming you have several schedules defined in the node settings, I think all cron types are or can be well covered by the configuration itself since here you can set both start/end date & time as well as the frequency for the triggering. In addition, you can trigger those schedules with a few inject nodes set to fire at startup

But if you look at schedules for solar (and lunar) events, there are no such settings available. Triggering with inject nodes does not really work either because inject nodes does not know the actual state of the sun or the moon

Imagine if you could combine a ”normal” cron job schedule and use solar events as start/end criteria. This would allow you to use a very flexible setup including the frequency for the triggering. If you would need it, you could set "fire every minute" and the thing would sync automatically within a minute after a restart/reboot. You could then also trigger such a schedule with an inject node since the schedule itself would know, or could calculate, if it should fire based on the start & end criteria

Use a js lib or even a palette node? Use inject, add solar/lunar meta data, then you can process it any way you want in a function.

No need, OP already had the cronplus node & it can give you all the information you need via the "describe" or "status" command.

If you inject a topic, status, and payload with the name of the schedule, you will get solar/Luna info you can use to determine specific logic.

That is what the cronplus "when" node is for.


Example

Oh, if that is available I think is great, I must have missed where it is?

OK, that can very well be used

Introduced in the recent cronplus release (3.2.0 ?)

Ah, thanks, just found it, could not see it since it was located in functions....