Brain teaser: Find first moon phase in defined time range

Hi Guys!
Well, at least it is a brain teaser for me - I only don't have enough brain to figure it out (obviously :smiley: )

That is what I want to achieve: We have several Holidays on earth linked to a specific moon phase. Some of them are linked to a moon phase in a specific time range, e.g. between 24th of October to 22nd of November.

I already found the node for moon phases in the node node-red-contrib-sun-position and played around with it for a while.

Well, and then I failed.
How can I proceed now, for I need to define a time range which reappears every year. Than the node we show up and tells me when the wanted moon phase is and: Voila, I would have the specific holiday I was searching for.

Does any one has an idea how I can proceed?

Thanks a lot in advance!


...not quite clear what you need/want to achieve here, but from what I gathered, this might work:

  • create an inject node that would generate a message in desired recurrence (i.e.every hour)
  • feed the output into the "within time" node of the node-red-contrib-sun-position library and configure the within time node to the specific period you need (i,e. 24th of October to 22nd of November)
  • If the current time falls within the range specified in the "within time" node configuration, the message is routed to output 1. Otherwise the message is routed to output 2. ... feed the message from output 1 into a "moon position" node.
  • check the output if the desired moon position has been reached (i.e. with a switch node).

Hi hominidae,
yes, this is pretty much what I need. I tried to implement your idea, but I didn't find a way to define a date (e.g. 24th october) without the need of define the year as well. In "within-time" I only find the possibility to either define a month (but not a specific day) or define a date including the year.
How can I define, that the node should start on october 24th each year?

Ahhh...ok, I wasn't aware of that restriction in the "within time" node... :thinking:

Have a look into this node-red-contrib-cron-plus (node) - Node-RED
You should be able to generate repeating events within a specific time span....haven't used it myself until now, though.

Great one! I'm thinking about use two of them:
first one to define the start (24th OCT) to set a variable, e.g. msg.payload.moonstart, to true.
second one to define the end (22nd NOV) to set the variable to false.

Now I guess I'll use a switch to trigger "within time" to get the moon phase only when .moonstart is TRUE.

I'm gonna chew a bit more on that and will keep you informed. Meanwhile many thanks for that helpful hint!

I think this way is still too complicated.
Another "problem" is, that the time when the moonphase will be reached is dependent on the location.
Hence you will need to create a dedicated moonphase node and configuration for each desired location.

That said, I think the "inject enhanced" node would work best. Use it to create updates to the current moonphase (based on location) and then feed it through two switch nodes, narrowing down the month-range and day-range required.
Like this:

[{"id":"41eb733e.08c3dc","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"22eca0d1.39f5d","type":"time-inject","z":"41eb733e.08c3dc","name":"update moonphase","nameInt":"\"Mondphase\"","positionConfig":"8c7609ce.dd5798","props":[{"p":"","pt":"msgPayload","v":"","vt":"pdmPhase","o":"","oT":"none","oM":"60000","f":0,"fS":0,"fT":"Millisekunden UNIX-Zeit","fI":"0","next":true,"days":""}],"injectTypeSelect":"none","intervalCount":1,"intervalCountType":"num","intervalCountMultiplier":60000,"time":"","timeType":"entered","offset":0,"offsetType":"none","offsetMultiplier":60000,"timeEnd":"","timeEndType":"entered","timeEndOffset":0,"timeEndOffsetType":"none","timeEndOffsetMultiplier":60000,"timeDays":"*","timeOnlyOddDays":false,"timeOnlyEvenDays":false,"timeMonths":"*","timedatestart":"","timedateend":"","property":"","propertyType":"none","propertyCompare":"true","propertyThreshold":"","propertyThresholdType":"num","timeAlt":"","timeAltType":"entered","timeAltDays":"*","timeAltOnlyOddDays":false,"timeAltOnlyEvenDays":false,"timeAltMonths":"*","timeAltOffset":0,"timeAltOffsetType":"none","timeAltOffsetMultiplier":60000,"once":false,"onceDelay":0.1,"recalcTime":2,"x":190,"y":100,"wires":[["fcc44e2e.be97e","517c6f2.812ee9"]]},{"id":"fcc44e2e.be97e","type":"debug","z":"41eb733e.08c3dc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":390,"y":40,"wires":[]},{"id":"463753dc.03a8dc","type":"switch","z":"41eb733e.08c3dc","name":"moonphases","property":"","propertyType":"msg","rules":[{"t":"eq","v":"waxingCrescentMoon","vt":"str"}],"checkall":"false","repair":false,"outputs":1,"x":590,"y":100,"wires":[["e9978ac9.40c918","29f23f29.37d83"]]},{"id":"e9978ac9.40c918","type":"debug","z":"41eb733e.08c3dc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":140,"wires":[]},{"id":"517c6f2.812ee9","type":"change","z":"41eb733e.08c3dc","name":"Month and Day","rules":[{"t":"set","p":"day","pt":"msg","to":"$fromMillis($._ts,'[D01]')","tot":"jsonata"},{"t":"set","p":"month","pt":"msg","to":"$fromMillis($._ts,'[M01]')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":100,"wires":[["463753dc.03a8dc"]]},{"id":"29f23f29.37d83","type":"switch","z":"41eb733e.08c3dc","name":"months (ranges)","property":"month","propertyType":"msg","rules":[{"t":"eq","v":"01","vt":"str"},{"t":"eq","v":"02","vt":"str"},{"t":"eq","v":"03","vt":"str"},{"t":"eq","v":"04","vt":"str"},{"t":"eq","v":"05","vt":"str"},{"t":"eq","v":"06","vt":"str"},{"t":"eq","v":"07","vt":"str"},{"t":"eq","v":"08","vt":"str"},{"t":"eq","v":"09","vt":"str"},{"t":"eq","v":"10","vt":"str"},{"t":"eq","v":"11","vt":"str"},{"t":"eq","v":"12","vt":"str"}],"checkall":"true","repair":false,"outputs":12,"x":780,"y":300,"wires":[["ce5ef60f.34b018"],[],[],[],[],[],[],[],[],[],[],[]]},{"id":"ce5ef60f.34b018","type":"switch","z":"41eb733e.08c3dc","name":"day range","property":"day","propertyType":"msg","rules":[{"t":"btwn","v":"22","vt":"num","v2":"24","v2t":"num"},{"t":"eq","v":"19","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":940,"y":229,"wires":[["77547727.aaba38"],["77547727.aaba38"]]},{"id":"77547727.aaba38","type":"debug","z":"41eb733e.08c3dc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1093,"y":228,"wires":[]},{"id":"8c7609ce.dd5798","type":"position-config","name":"DACH-1","isValide":"true","longitude":"0","latitude":"0","angleType":"deg","timeZoneOffset":"99","timeZoneDST":"0","stateTimeFormat":"3","stateDateFormat":"12"}]

...still not perfect for intersection in months/days but as an example, U might get the picture.
Maybe create a JSONATA timestamp query for each desired date-range in the first switch and you*re done

1 Like

Hi hominidae,
that for sure is a very interesting setup! I'm still digging through whilst trying to arrange everything for the tightened lockdown here in Germany. So it may take some time 'til I have the space to think that through properly. But for what I saw that definitivley could work. So I have something to look forward to at weekend :smiley:

I'll keep in touch (is that phrase still allowed to say in times like these? ^^ ) always there is more than one possible solution to a problem.
Looking forward to see your own version soon :wink:

Viel Spass und immer schon gesund bleiben!

I use the node-red-contrib-astrodata node for my own application.
But I have a very simple usage, just display the phase of the moon.
But if you look at the data it provides, you might be able to figure out a solution to your problem.
Kind regards,

1 Like

Hey guys!
@hominidae Your solution does work quite good. Nonetheless I found an ical which provides the data, so, to avoid uneccesary overhead I chose the simple solution over the brilliant one. Even though that does have some fun reducing effect on the storyline here - hope you'll pardon me!

Thanks for your suggestions, I really feel welcome here even though being a newbe - that's not common in the world of "DIY home automatisation" :smiley:


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.