Add moonrise and moonset times to the Moon integration

The built-in moon integration currently only provides the moon phase.

It would be really useful if it could also expose moonrise and moonset times — either as additional attributes or as separate sensors (e.g. sensor.moonrise and sensor.moonset), similar to how the sun integration works.

This data is available in newer versions of the Astral library via:

from astral import LocationInfo
from astral.moon import moonrise, moonset

moonrise(location.observer, date)
moonset(location.observer, date)

However, I understand that Home Assistant currently uses Astral v2.2, which does not support these functions. If feasible, upgrading Astral would greatly enhance the integration.

Use cases:

Astronomy/photography planning

Automations based on moon visibility

Theming dashboards with more complete lunar information

This has been asked before but nothing has been done:

Thanks for considering!

Just to add more context to this request, I have been working on an integration that uses astral library and I’m trying to get moon rise and set times from it but I’m unable to use a newer version of astral since it would clash with the Home Assistant install and the one in HA requires updating.

So as well as it being generally useful for the moon integration to have these additional sensors, its also useful from a dev viewpoint to update astral itself.

You forgot to add Werewolves :stuck_out_tongue_closed_eyes:

2 Likes

our cat’s nuttiness alerts us to the presence of a full moon

1 Like

I did at one point attempt upgrading the Astral library to 3.2, but it seems it has some undisclosed breaking changes, as other integrations using the library started failing tests as it seems Astral changed some of its computations for the worse. Some details here: https://github.com/home-assistant/core/pull/143853#issuecomment-2854281535

Looking at the Astral library itself didn’t give me a lot of confidence… it has dozens of open issues with no feedback and it hasn’t merged a pull in 3 years. Seems somewhat abandoned.

oh yikes. Seems we need to move away from Astral altogether. Looking further into what I could use for my own integration and Skyfield looks solid.

https://rhodesmill.org/skyfield/

It has moon phases + rise/set as well as a tonne of other stuff. Not sure if its overkill for the moon integration though.

I’m probably going to refactor my code to use it actually.