# \[ANNOUNCE\] node-red-contrib-chronos

**URL:** <https://discourse.nodered.org/t/announce-node-red-contrib-chronos/33350>\
**Category:** Share Your Nodes\
**Created:** [25 September 2020 14:03 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-chronos/33350 "2020-09-25T14:03:38Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![Kazzy](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@Kazzy](https://discourse.nodered.org/u/Kazzy)\
**Post date:** [25 October 2020 17:20 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-chronos/33350/21 "2020-10-25T17:20:39Z")

</div>

> [@jens\_rossbach](#):
>
> can have a look to s

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](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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/9/69d45eecc2ac91d69cbea5d4aed4f70a7760acbf.png)

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 🙂 lol

Many thanks,

---

<div class="post-metadata">

**Author:** ![jens\_rossbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jens_rossbach/32/98717_2.png) [@jens\_rossbach](https://discourse.nodered.org/u/jens_rossbach)\
**Post date:** [25 October 2020 17:25 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-chronos/33350/22 "2020-10-25T17:25:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kazzy](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@Kazzy](https://discourse.nodered.org/u/Kazzy)\
**Post date:** [25 October 2020 18:55 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-chronos/33350/23 "2020-10-25T18:55:58Z")

</div>

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 🙂

many thanks.

---

<div class="post-metadata">

**Author:** ![jens\_rossbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jens_rossbach/32/98717_2.png) [@jens\_rossbach](https://discourse.nodered.org/u/jens_rossbach)\
**Post date:** [7 November 2020 10:35 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-chronos/33350/24 "2020-11-07T10:35:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kazzy](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@Kazzy](https://discourse.nodered.org/u/Kazzy)\
**Post date:** [7 November 2020 15:52 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-chronos/33350/25 "2020-11-07T15:52:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kazzy](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@Kazzy](https://discourse.nodered.org/u/Kazzy)\
**Post date:** [8 November 2020 14:52 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-chronos/33350/26 "2020-11-08T14:52:42Z")

</div>

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

 ![Screenshot 2020-11-08 145203](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/e/ee51d151f49c44c552225d89170ec95f427ae3c3.png)

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.

 ![Screenshot 2020-11-08 144456](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/8/c888e12e49d4d6da12cd9808ae7ed45920225e35.png)

```auto
[{"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](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.

---

<div class="post-metadata">

**Author:** ![jens\_rossbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jens_rossbach/32/98717_2.png) [@jens\_rossbach](https://discourse.nodered.org/u/jens_rossbach)\
**Post date:** [8 November 2020 17:45 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-chronos/33350/27 "2020-11-08T17:45:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jens\_rossbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jens_rossbach/32/98717_2.png) [@jens\_rossbach](https://discourse.nodered.org/u/jens_rossbach)\
**Post date:** [8 November 2020 18:10 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-chronos/33350/28 "2020-11-08T18:10:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kazzy](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@Kazzy](https://discourse.nodered.org/u/Kazzy)\
**Post date:** [8 November 2020 20:39 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-chronos/33350/29 "2020-11-08T20:39:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jens\_rossbach](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jens_rossbach/32/98717_2.png) [@jens\_rossbach](https://discourse.nodered.org/u/jens_rossbach)\
**Post date:** [9 November 2020 18:56 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-chronos/33350/30 "2020-11-09T18:56:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kazzy](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@Kazzy](https://discourse.nodered.org/u/Kazzy)\
**Post date:** [9 November 2020 22:05 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-chronos/33350/31 "2020-11-09T22:05:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [24 November 2020 14:03 UTC](https://discourse.nodered.org/t/announce-node-red-contrib-chronos/33350/32 "2020-11-24T14:03:46Z")

</div>

Closed on 24 November 2020 14:03 UTC

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

[Previous page](https://discourse.nodered.org/t/announce-node-red-contrib-chronos/33350.md?page=1)
