How to calculate sunrise and sunset times for a particular location

Marijn

Member
Joined
Mar 5, 2008
Messages
585
Reaction score
11
Points
18
Location
Amsterdam
Hello,

For my DIY smart lighting system, I am downloading data from https://sunrise-sunset.org/api once a day to get various timestamps for nautical dawn, sunrise, solar noon etc. for my location.

This API is bugged in some situations. Also, it's my only dependency on the internet which I like to get rid of.

Since I don't need much accuracy (5 minutes difference with the real thing is acceptable), I like to calculate it locally using some math.

But I am unsure if that's actually possible and where to start. Anybody who can help or point me towards some example?

Thanks!
 

asbjos

tuanibrO
Addon Developer
Joined
Jun 22, 2011
Messages
618
Reaction score
44
Points
28
Location
This place called "home".
Try to look at this: https://en.wikipedia.org/wiki/Sunrise_equation

I haven't used it myself, but it looks promising.
If you plan on publishing your program, I would recommend you to already now implement a solution for polar days/nights, to avoid the inevitable bug report coming from people at more than +-66.56 degrees latitude (polar circle).
 
Top