Moon phases?

Can someone point me to an app/driver for detecting moon phases? The dark sky one has/had it but obviously is not a long term solution. Can’t seem to find something else...

Haven't done a driver for it, but it might be doable using

https://www.visualcrossing.com/resources/documentation/weather-api/how-to-include-sunrise-sunset-and-moon-phase-data-into-your-api-requests/

Free for up to 1000 requests per day.

Should also be a "simple" calculation using a starting date (a 29.5 day cycle so predictable)

2 Likes

Thanks. Seems like a good option if there’s not an existing app/driver. Hoping for a plug and play solution that doesn’t require me to develop another app in order to finish the app I’m currently developing :slight_smile:

Give me about 30 minutes and I might have something for you....

2 Likes

Try this:

https://raw.githubusercontent.com/thebearmay/hubitat/main/moonPhase.groovy

7 Likes

Wow, nice work, and quick too. Seems like the getPhase() function has everything I need. Would you mind if I use the getPhase() function integrated into my app, with attribution of course? Might be easier for the user than requiring them to install the device and choose it in the preferences. No worries if not though. Much appreciated either way!

Was thinking when I wrote it, that it might be easier for you to just grab the getPhase function and incorporate it. Was a good mental exercise for the morning.

3 Likes

Found a small bug in the calculation. It’s fixed now but if you grabbed the code earlier you may want re-pull it. Also added ability to give it a date other than the current date.

1 Like

Nice little code the @thebearmay, you might add the possibility to have pics of the moon phases on the dashboard? That might be cool some people that have a dashboard with weather and stuff.

2 Likes

I was looking at that, just need to find a good set of images for it.

1 Like

I’m actually writing an app right now that will be for this and more. Nearly done. Stay tuned!

I modified the driver slightly, now has a tile attribute, a path override for using your own icons, and an option to automatically run at midnight + 1 second.

image

Edit: I used the path override to point to a copy of the icons on my hub (http://hubIpAddress/local/) which eliminates any need for the internet.

4 Likes

Cool. Looks like you re-worked getPhase() too, huh? Can/should I use that updated version?

It's a little more accurate, so I would. Older version had an occasional rounding related error that would skew the result.

2 Likes

I put the driver in HPM, the search term moon should bring it up.

2 Likes

I added an option to widen the quarterly milestones by 1% to more closely align with what people are used to seeing on their calendars. The default method, which is more technically correct, only returns the quarterly milestones for a couple of hours, the 1% variation will allow for 2 days of the quarterly milestone. As an example, this means that instead of requiring exactly 0.50 of the lunar cycle for a full moon the option will return full moon for 0.49-0.51 inclusive.

2 Likes

Seems like you keep improving it! I'm just going to have the user select your device type from a dropdown, rather than have a copy of the getPhase function. Will stay up to date with whatever else you think of next! :slight_smile:

Lol, I’m always looking to see if I can improve things so no project is ever really done.

This was awesome! I'd been pulling an image to a tile to get this - this is so much more elegant!
On your attributes for dashboard placement, you have
MoonPhaseNum (the numeric value), MoonPhase (which gives the text) and MoonPhaseTile (which is Text and Image). How can I get just the image? Could there be a 4th attrib such as MooonPhaseImg which has only the image or am I overlooking something obvious?

It’s embedded in the image tile string, but if you pull down the latest I’ve also put the imagepath into an attribute

1 Like