How to calculate sunrise and sunset times for a particular location

Marijn

Active member
Joined
Mar 5, 2008
Messages
755
Reaction score
166
Points
43
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
696
Reaction score
259
Points
78
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).
 

Marijn

Active member
Joined
Mar 5, 2008
Messages
755
Reaction score
166
Points
43
Location
Amsterdam
Top