I have been playing around with the addition, Astronomy Engine npm_ package.
What a fantastic addition this is and well worth a play with.
After it is installed you will get a Global data ref called Astronomy in your node red workplace.
Just a quick check afterwards to see the list of commands
const Astronomy = global.get("Astronomy");
msg.payload = Astronomy;
return msg;
Then you can start building.
I have created multiple observation locations and you can then use that to feed the function with whatever you want to explore.
Here is an example of looking for Planets and their real time positions etc.
const Astronomy = global.get("Astronomy");
if (!Astronomy) {
node.error("Astronomy library not found in global context");
return null;
}
// Get location
const location = msg.location;
if (!location) {
node.error("msg.location is missing");
return null;
}
const latitude = Number(location.latitude);
const longitude = Number(location.longitude);
const elevation = Number(location.elevation);
const tzone = location.tzone;
const place = location.place;
const code = location.code;
// Validate location
if (
!Number.isFinite(latitude) ||
!Number.isFinite(longitude) ||
!Number.isFinite(elevation)
) {
node.error(
`Invalid location: latitude=${location.latitude}, longitude=${location.longitude}, elevation=${location.elevation}`
);
return null;
}
if (!tzone) {
node.error("Timezone (tzone) is missing");
return null;
}
// Create observer
const observer = new Astronomy.Observer(
latitude,
longitude,
elevation
);
// Current time
const now = new Date();
// Local time
const localTime = now.toLocaleString("en-GB", {
timeZone: tzone
});
// Format a date for display
function formatLocalDateTime(date) {
if (!date) {
return null;
}
return date.toLocaleString("en-GB", {
timeZone: tzone,
weekday: "short",
day: "2-digit",
month: "2-digit",
year: "numeric",
hour: "2-digit",
minute: "2-digit",
hour12: false
});
}
// Planets
const planets = [
["Mercury", Astronomy.Body.Mercury],
["Venus", Astronomy.Body.Venus],
["Mars", Astronomy.Body.Mars],
["Jupiter", Astronomy.Body.Jupiter],
["Saturn", Astronomy.Body.Saturn],
["Uranus", Astronomy.Body.Uranus],
["Neptune", Astronomy.Body.Neptune],
["Pluto", Astronomy.Body.Pluto]
];
// Output
const output = {
place: place,
code: code,
timestamp: now.toISOString(),
localTime: localTime,
timezone: tzone,
latitude: latitude,
longitude: longitude,
elevation: elevation,
planets: []
};
// Calculate each planet
for (const [name, body] of planets) {
// Current equatorial coordinates
const equator = Astronomy.Equator(
body,
now,
observer,
true,
true
);
// Current horizontal coordinates
const horizon = Astronomy.Horizon(
now,
observer,
equator.ra,
equator.dec,
"normal"
);
// Find next rise
const rise = Astronomy.SearchRiseSet(
body,
observer,
+1,
now,
2
);
// Find next set
const set = Astronomy.SearchRiseSet(
body,
observer,
-1,
now,
2
);
// Add planet data
output.planets.push({
name: name,
// Current position - nearest whole degree
azimuth: Math.round(horizon.azimuth),
altitude: Math.round(horizon.altitude),
// Equatorial coordinates
ra: Number(equator.ra.toFixed(5)),
dec: Number(equator.dec.toFixed(5)),
// Is the planet currently above the horizon?
aboveHorizon: horizon.altitude > 0,
// Next rise
rise: rise ? rise.date.toISOString() : null,
riseLocal: rise ? formatLocalDateTime(rise.date) : null,
// Next set
set: set ? set.date.toISOString() : null,
setLocal: set ? formatLocalDateTime(set.date) : null
});
}
// Put everything into msg.payload
msg.payload = output;
return msg;
Here is a snippet of the output to Home Assistant using a markdown card
In my pages on HA I have, Sun, Moon, Planets, Sun and Lunar Eclipses and much more and now my phone GPS is linked to it, so that wherever I am in the world it will show the correct information for that location
Have a go

