Time range node recommendation

Hi all

I have been playing around with Node-Red for a little while and really enjoying it a lot.

I have a Philip Hue Motion and wanted to take more control over it in NR.

So i wanted a Node that would allow me to say, only do motion action the current time is within a
time range. for me that is starts after Sunset and End time at 2am.

One i found and i am using is

this works great however, it range is 00:01 to 23:59 so it wont let me cross over days,
ie 18:00 (current sunset time) to 02:00 (2am next morning).

as anyone know of different that can do it..

Currently i have to create two copies.. one that says 18:00 to 23:59 and another that is 00:01 to 02:00

this works fine.. but it is messy and i like to keep things more simple :slight_smile:

thanks, Bru.

If you use the cron plus node, you can send a message through it that will output current solar state (including dusk, dawn, golden hour etc) (see the built in demos/examples and built in documentation for the describe command).

Using these solar properties & a switch node or function node you can decide what to do.

1 Like

Thanks.. i had a quick look around it and its not really what i am after..

I can see i can set a SUNSET Start.. but can't see who i can create a range so it ends at a certain time.

Also seem like not sure how this would fit with my existing flow..

Must be a node that can just take current time and say is it within a range.. that can cross into the next day?

I'm sure a function could be written it not really a route i wanted to go down just yet as i i figure this would have been a fairly standard built in request. :frowning:

oh well.. ta..

having a look at the flow library and

seems to be nice and simple and looks like it does do a Start to End Range. so going to try testing it out.

the CronPlus i think it good so im sure i might need it from when i need something trigging or testing every x min/day/months type to checks.

Also worth a try are these nodes:

No worries.

The reason I suggested it was because you want a msg to pass IF time was sunset to 02:00.
The cron-plus node can be queried for sunset time / solar status - so you only needed to check (in a function or switch+JSONata) that the time was BEFORE 02:00

e.g....

[{"id":"426a978b.442178","type":"cronplus","z":"462180de.0f254","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[],"x":260,"y":480,"wires":[["fc656b97.6cd0e8","ee078b8e.73d938"]]},{"id":"83aea31b.5cd13","type":"inject","z":"462180de.0f254","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"command\":\"describe\",\"expressionType\":\"solar\",\"location\":\"54.9992500,-1.4170300\",\"solarType\":\"selected\",\"solarEvents\":\"sunset\",\"timeZone\":\"Europe/London\"}","payloadType":"json","x":130,"y":480,"wires":[["426a978b.442178"]]},{"id":"292746f0.fbd64a","type":"debug","z":"462180de.0f254","name":"is sunset ~ 2am","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":720,"y":540,"wires":[]},{"id":"fc656b97.6cd0e8","type":"switch","z":"462180de.0f254","name":"Is Sunset","property":"(payload.result.solarState.twilight = true)\tor\t(payload.result.solarState.night = true)\t\t \t\t\t\t","propertyType":"jsonata","rules":[{"t":"true"}],"checkall":"false","repair":false,"outputs":1,"x":420,"y":480,"wires":[["cb34562e.c5a4d8","5fd56c59.289da4"]]},{"id":"cb34562e.c5a4d8","type":"function","z":"462180de.0f254","name":"Is time < 2am?","func":"var hrs = new Date().getHours();\n\n//since it is unlikely to be dusk at 2pm, a simple check\n//for HOURS being >= 14 OR < 2am is enough\nif(hrs >= 14 || hrs < 2)\n    return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":480,"wires":[["292746f0.fbd64a"]]},{"id":"ee078b8e.73d938","type":"debug","z":"462180de.0f254","name":"cron","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":290,"y":540,"wires":[]},{"id":"5fd56c59.289da4","type":"debug","z":"462180de.0f254","name":"is sunset?","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":480,"y":540,"wires":[]}]
1 Like

Hello,

I think this subflow timerange switch I build a while back would also do this and work across midnight:

Of course as @Steve-Mcl suggested cron plus would be a lot more flexible and sophisticated.

Johannes

Thanks Steve-Mcl

That's an interesting approach.. i couldnt think how to the the end range with cron+

But it adding more Nodes to the solution where i like to try and do it all as a single node, so the current way i am doing is no better and no worse off :slight_smile:

I did try Chronos & Thingzi but i think they two also fail to allow for the end time to be anything past 23:59... they make the assumption is a 24Hour clock so starts at 00:00

I used https://www.epochconverter.com to inject a timestamp,. saves me having to be awake at 2am to see if any these would work :slight_smile:

Both allowed the flow to pass through with times like 4am being sent to it..

@JGKK just seen yours so will give yours a test as well thanks.

lots of examples so just a case to blend them into what works best ..

thanks chaps.

Hi,

I wrote the thingzi timer mainly for my own uses but i actually use it as you suggest myself. While it only allows one time range a day this can be wrapped or inverted as required. Eg. Start at 5pm and end at 2am should wrap round just fine. If not though I’m always interested in suggestions.

Thanks,
Bryan

Thanks Bryan,

what i failed to understand when testing Thingz and Chronos was that it calculates the current time
when it receives a msg and not me trying to fake a time and passing it to the node. oops.

Yeah it doesn’t do that :grinning: the time check node is the one I use in this instance though. So given any motion event pass it on, but only if the current time is within the valid range. Much more useful if something else is the trigger and you need a time constraint applied.