jensrossbach / node-red-contrib-chronos

Time-based Node-RED scheduling, repeating, queueing, routing, filtering and manipulating nodes
https://jensrossbach.github.io/node-red-contrib-chronos
MIT License
28 stars 1 forks source link

SCHEDULER : Publish current event #130

Closed xX-Nexus-Xx closed 7 months ago

xX-Nexus-Xx commented 8 months ago

Hello,

thanks for providing this node, it works really well so far.

Is there a way to publish the current event?

Example: I have configured

If I restart the system at 11am, NR will not now the current event .. which is of course DAYLIGHT

Please let me know if there is a possibility to publish the current event? .. or if this can be provided in a future release

thx a lot

jensrossbach commented 8 months ago

Hi @xX-Nexus-Xx, this is not in scope of the scheduler node.

But you could realize this easily with two inject nodes and two time filter nodes. Both inject nodes need to be configured to inject after deployment/loading (the checkbox at the bottom). The first inject node produces a message with payload DAYLIGHT and is connected to the first time filter node. The latter is configured to pass the message if ingress time is after sunrise and before sunset. The second inject node produces a message with payload NIGHT and is connected to the second time filter node. The latter is configured to pass the message if ingress time is after sunset and before sunrise.

xX-Nexus-Xx commented 8 months ago

Sorry. I was not clear enough before ... the daylight was just an example

I woul need an "UPDATE" trigger for the schedule node which is pushing thru the current event.

Another example: I have a schedule defined from NOON time till SUNRISE start to run my Pool pump, as this is peak time for my solar panels.

In case I have to restart my stystem between NOON and SUNRISE, than my Pool pump will not start with your current scheduler. I would need to inject an UPDATE trigger to the scheduler to publish the current event and activate my Pool pump.

I have dozents of these events spcified and in normal operation the scheduler works fine, but sometimes it is necessary to publish the current event. It should be easily done internally as you already show the next event in the Node-Status.

Thanks for considering

jensrossbach commented 8 months ago

I woul need an "UPDATE" trigger for the schedule node which is pushing thru the current event.

There is no "current" event existing. Events are single moments in time at which the node triggers something. What you request would be the last triggered event but the node does not remember events from the past, it triggers at certain moments and then forgets about the event.

I have a schedule defined from NOON time till SUNRISE start to run my Pool pump, as this is peak time for my solar panels.

As stated above, events are single moments in time and not time ranges, but I assume that you turn on your pump at noon and turn it off at sunrise (do you really mean sunrise or do you mean sunset?). So when you restart Node-RED within that time range, there shouldn't be a problem (your pump should continue to run), only if the down time of Node-RED would cover one of the time range borders.

It should be easily done internally as you already show the next event in the Node-Status.

Yes, the node knows about all upcoming events but not about past events. I don't see the point how triggering the next event could help (although implementing this would indeed be an easy thing).

jensrossbach commented 8 months ago

I had some more thoughts about the topic and I can confirm that implementing an "UPDATE" trigger for the next upcoming event is easy to implement (as stated above), so I can add this in the next version.

But what is more or less impossible is to provide an "UPDATE" trigger for the previous event (i.e., the most recently past event). This is because scheduler node does not persist the actual time of past events (as already stated above) and it's also not possible to calculate past events (for instance because triggers could have a random offset and we do not know, what that random offset was or could have been; additionally, for crontable triggers, there is no API existing to fetch events from the past, only events from the future).

jensrossbach commented 7 months ago

The new release 1.21.0 hopefully solves your issue. On one side, there is the new command trigger:next for scheduler node which triggers the next upcoming event. On the other hand, I added a brand new node, the so called state node, which internally maintains a state and can therefore provide the state value at any time. Feel free to try it out!