0 votes
in WeatherStationClassic by (210 points)

I'm abusing the excellent b/w weather station as a display for my own home automation system. I collect data from sensors, send them via MQTT to the broker for further processing via node-red. All the data for the weather station is fetched from a MQTT topic (JSON format, retained). That way uptime between 10min sleep is less than 2 seconds. Currently I'm using it for temperatures around the house, rain water tank level, solar power, etc. So far so good.

I'd like to display the current moon phase. The node-red data offers two values (from a astronomy node). And no, I do not have a clue what they mean:

moonPhaseNumber: 0.028

moonAge: 19.421

These values are for Switzerland, Nov 16, 2020, 15:35

I found from looking at the code from Daniel that with the following command I might be able to display a nice Icon, if I select the correct font first.

gfx.drawString(x, y, String((char) (nn)));

But I have currently no clue how to map the values I have from my home automation system to a Icon number nn. What Icon numbers are valid? Do they start at 0 with full moon up to 255 with full moon again?

I need to map from moonPhaseNumber/moonAge (which I currently do not understand) to a Icon number nn, which I do not understand neither. The first part I do probably need to figure out myself. But the second part is something where people on this board might be able to help.

Many thanks for any hints,

Urs.

1 Answer

0 votes
by (19.9k points)
selected by
 
Best answer
You first need a font  with "characters" representing moon icons such as this (aka font icons): https://github.com/ThingPulse/esp8266-weather-station-color/blob/master/moonphases.h

Then you calculate the number representing the correct character based on some moon properties (moon age or illumination) for the font table. We have exactly the same requirements and challenges for our Weather Station Color application: https://thingpulse.com/product/esp8266-wifi-color-display-kit-2-4/.

Ever since its inception the simple algorithm at https://github.com/ThingPulse/esp8266-weather-station-color/blob/master/esp8266-weather-station-color.ino#L439 was wrong or at least inaccurate. It ignores full moon and new moon and the fact that the moon representation on the southern hemisphere is different from ours. I have tried a number of different approaches recently but haven't arrived at an acceptable result yet.

`moonPhaseNumber` is incorrectly labeled. It's actually the illumination, a value from {0, 1}. Hence, 0.028 means: the moon is 2.8% illuminated.
`moonAge` is the position of the moon in its cycle. A full cycle is 29.530588853 days on average: https://en.wikipedia.org/wiki/Lunar_phase#Calculating_phase

Btw, we have a whole class in the Weather Station lib devoted to sun and moon properties: https://github.com/ThingPulse/esp8266-weather-station/blob/master/src/SunMoonCalc.cpp.
by (210 points)
Thanks. This was quick.

I got the values from the node-red node:
https://github.com/nobodyMO/node-red-contrib-astrodata
Since the values were not explained, I checked the code in the mean time, which gave me some hints.
(Maybe you can use the code as a basis for your calculations for the weather station.)

moonPhaseNumber (or illumination) is indeed a value between 0..1. But this does not help, since 0.5 could mean two different moon phases.
Therefore I need to use the moonAge. If I read the code correctly, then this is in degrees, where 0 is empty moon, 180 full moon and 360 empty again.

I already 'stole' the moonphases.h font file, many thanks.
There is now one remaining question. Which character in the font file corresponds to which moonAge?
by (210 points)
I got it running.
The moon phase icons in the font are from 65 (empty) to 90 (empty again).
Since my moonAge value goes from 0 to 360, the rest was easy.
Thanks for the font file and the hints.
by (19.9k points)
I'm glad it works for you. The link to the font is in the .h file: https://www.dafont.com/moon-phases.font Interesting that your moonAge is in {0, 360}.

"icons in the font are from 65 (empty) to 90 (empty again)" - not exactly. Neither of them is fully empty. There are separate icons for full and new moon. One is possibly 48 but I'm not sure about the other. A sample sketch that simply iterates through all the icons would reveal that.

Also, to my knowledge full and new moon never span more than a single day. Depending what your algorithm does exactly you might have to factor that in.

Welcome to ThingPulse Q&A, where you can ask questions and receive answers from other members of the community.

https://thingpulse.com

...