[ANNOUNCE] node-red-contrib-chronos

Hi Jens

Cool.. i'm having another play and maybe it the way i am do the testing.

Im converting the time so 26Nov @3.am to EPOCH Time format (https://www.epochconverter.com)
and just using an Inject node to as a number to pass it into the Chronus Time Range.

So maybe thats where thing are going wrong?
Screenshot 2020-10-25 171746

so inject into msg.payload : 1603681591 instead of the builtin timestamp

Time filter is simple BETWEEN 17:00 to 02:00

when i run this.. both debugs give outputs.. i was expect the one after the Time Filter node not to output.

so maybe i am injecting it wrong.. i just dont want to be away at 2am to test the proper way :slight_smile: lol

Many thanks,

The time that is checked against the time range is the current time at the moment, when the message arrives at the filter node. It is not the timestamp contained in the message (the content of the incoming message is not evaluated at all).

So if you want to have the timestamp of the message to be checked in the filter node, this would be a new feature which is currently not implemented.

ah perfect.. i figured i must have been assuming it all around.. thanks for the info it make complete sense.

now i can have a proper play with this Node :slight_smile:

many thanks.

The new release 1.6.0 is available and adds support in the switch and filter nodes for specifying custom base times for evaluation against the conditions. Besides the message ingress time as used before, it is now possible to use timestamps from an arbitrary message property, global variable or flow variable. This new feature was inspired by the discussion above, thanks to @Kazzy.

Additionally some minor bugs have been fixed in this version.

Excellent... I've been using Chronos and it doing what i was after. i find the Switch node one i used most.

1 Like

HI @jens_rossbach

I was testing my flow again and i think the date range when it goes past midnight does not work,
I noticed that once it was after Midnight the lights no longer turned on, even though i still had it range to 00:30.

Now that you got this new version out i can now test it properly and pass it some example times to see
what output the switch takes.

so did the test.. but times are based on today 08/Nov/20

So ran the 5 test from top to bottom and you can see the 5 outputs and the debug node description.
fyi.. Sunset for me here is 16:22pm

  1. 14:20:06 = 6am to Sunset (-5) == This is correct .
  2. 18:00:00 = Sunset to 00:30 == This is correct
  3. 23:59:00 = Sunset to 00:30 == This is correct
  4. 00:10:00 = Otherwise == this is wrong it should still be within Sunset to 00:30 block
  5. 03:00:00 = Otherwise == This is correct.. outside both range checks.

[{"id":"1ec5327b.09e4be","type":"inject","z":"a8cb5dfc.c57cf","name":"14:20:06 (08/11/20)","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1604845206000","payloadType":"num","x":670,"y":720,"wires":[["3ffb9391.04c7fc"]]},{"id":"3ffb9391.04c7fc","type":"chronos-switch","z":"a8cb5dfc.c57cf","name":"Time Check","config":"1beadeb4.3a4291","baseTime":"payload","baseTimeType":"msg","conditions":[{"operator":"between","label":"between Sunset (start) and 00:30","operands":[{"type":"sun","value":"sunsetStart","offset":0,"random":false},{"type":"time","value":"00:30","offset":0,"random":false}]},{"operator":"between","label":"between 06:00 and Sunset (start)","operands":[{"type":"time","value":"06:00","offset":0,"random":false},{"type":"sun","value":"sunsetStart","offset":-5,"random":false}]},{"operator":"otherwise","label":"otherwise"}],"stopOnFirstMatch":true,"outputs":3,"x":890,"y":800,"wires":[["beb84e0f.fa897"],["68add903.96f4a8"],["3c8ed21f.acf22e"]]},{"id":"beb84e0f.fa897","type":"debug","z":"a8cb5dfc.c57cf","name":"Sunset to 00:30","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1080,"y":740,"wires":[]},{"id":"68add903.96f4a8","type":"debug","z":"a8cb5dfc.c57cf","name":"6am to Sunset (-5)","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1090,"y":800,"wires":[]},{"id":"3c8ed21f.acf22e","type":"debug","z":"a8cb5dfc.c57cf","name":"Otherwise","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1060,"y":860,"wires":[]},{"id":"ae242ef2.e05d","type":"inject","z":"a8cb5dfc.c57cf","name":"18:00:00 (08/11/20)","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1604858400000","payloadType":"num","x":670,"y":760,"wires":[["3ffb9391.04c7fc"]]},{"id":"fcd24def.d2349","type":"inject","z":"a8cb5dfc.c57cf","name":"00:10:00 (09/11/20)","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1604880600000","payloadType":"num","x":670,"y":840,"wires":[["3ffb9391.04c7fc"]]},{"id":"3da95f6.86915a","type":"inject","z":"a8cb5dfc.c57cf","name":"3:00:00 (09/11/20)","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1604890800000","payloadType":"num","x":670,"y":880,"wires":[["3ffb9391.04c7fc"]]},{"id":"276932ab.01224e","type":"inject","z":"a8cb5dfc.c57cf","name":"23:59:00 (08/11/20)","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1604879940000","payloadType":"num","x":670,"y":800,"wires":[["3ffb9391.04c7fc"]]},{"id":"1beadeb4.3a4291","type":"chronos-config","name":"Chronos","sunPositions":[]}]

I used https://www.epochconverter.com to get those times for the Inject node.

Does it all look right or have i missed something or doing it wrong.?

Much appreciated .. Thanks.

Hi @Kazzy,

this is how the node works:

First it takes the base time and applies the date part to the configured times of the conditions. So let's say in case of #4, the base time is 00:10:00 on 8th of November, then the times for the first condition would be:

First time: Start of sunset, in your case 16:22 on Nov, 8th
Second time: 00:30:00 on Nov, 8th

Then the node recognizes that the second time is ealier than the first time, so it adds one day in order to have a valid range. This means, the times are now:

First time: 16:22 on Nov, 8th
Second time: 00:30:00 on Nov, 9th

As the base time is 00:10:00 on Nov, 8th, it is outside of the range, so the algorithm works correctly. But I have to admit that this is a disadvantage as it will never work for base times which already crossed the midnight border.

I'm thinking of performing two checks, one with one day added to second time (as done now) and another one with one day substracted from first time.

Regards, Jens

Or in case of the second time being earlier than the first time, I could just flip the times (to have a valid range) and negate the result. This should solve the issue.

cool..

i observed it last night, it was working fine to 23:50 but then after mid-night it stopped.

had to add an extra check for 00:00 to 00:30

my debug in the example above did in #4 flip the date so i made it be 9/11 @00:10

so what was happening last night (Saturday) was.

First time: 16:22 on Nov, 7th (saturday)
Second time: 00:30:00 on Nov, 8th (sunday morning)

The real world time was 00:10 Nov 8th... but it was not working,
which was why i had to add that extra condition of 00:00 to 00:30

Fixed it in version 1.6.1 (should be available within the next hours).

Cheers Jens. just testing it now with the test flow i did and it working now. thank you. :slight_smile:

This topic was automatically closed after 60 days. New replies are no longer allowed.