Why are the sunrise and sunset times wrong?

That is exactly the point pnbruckner and I concluded. The altitude found on non-local sources have no meaning. Only the observation of the surroundings on the specific location makes sense.

The bug is that the description is plain and simple wrong.
You might call it common understanding, but then common understanding is wrong too.
Trying to argue for the common understanding here would be like arguing the earth is flat again. :slight_smile:

So your suggestion for the right description is ?

I mean , i took an average of what Google, and a “national” map-provider suggested, and came pretty close (only had to change few meters ( in height above sea-level ) :wink: , to match the Temperature of Met.no (weather-integration) , with my own local temp-Device
Even coordinates are slightly different for these 2 sources (so my house floating around a bit, depending upon which map-source i look at) :slightly_smiling_face:

Sorry i can’t see the forest because of all the trees :slightly_smiling_face: , so looking out the window i have no idea of how high up in the sky i am

Temperature?
We are talking about sunrise and sunset. Not temperature.

Trees are actually one of the things you could take into account and the lower your height because of that.

I don’t know what astral would do with a negative observer elevation.

Astral does have a second option for specifying observer elevation. Instead of a single number (i.e., height above ground level), it can also accept a tuple of two numbers, distance to, and height of, and obstruction, like mountains, or trees, etc. HA doesn’t support that (but I’m thinking about adding it to my custom Sun2 integration.)

Yeah, the sun integration is a bit lacking.
That is also why I am your excellent Sun2 instead. Thanks for that work! :slight_smile:

1 Like

Yeah, well others use the altitude for temperature as well, as it in fact makes a different
If you stand at the foot of a 300meter high cliff / mountain , you can be sure that the temperature, is not the same at the top , same principle as you use for the “surroundings” when you consider sunrice/sunset, if you live in a valley, or on top

Yes i do also take the trees into account, when i consider sunrice/sunset, obviously :wink:

PS: You are not talking about sunrice/sunset, you are talking about cordinates and altitude and their sources in HA, which btw some other than native integrations makes use of

True, the altitude might be used for temperature too, which just makes it a lot more complicated, because the temperature needs to be calculated as altitude over sea level.
This is require some rewriting of HA to make it right or maybe the sun integration in HA should be ignored and Sun2 recommended instead, so the altitude setting in HA can be used for those other things.

Indeed , i even found that the definition of sunset/sunrise ( and sun above/below horizon ) variates, some sources use the tip of Sun , others use the center of the sun, who knows some might even use 2/3 or 3/4 :grin:
I don’t even remember why i or when i installed Sun2, but it must have been doe to “missing” options in the native ( or because it was already dark when my very first automation kicked in :smile:

PS: But speaking about sunrise/sunset , and OP’s question, i admit i have to agree, sun-integration does shows wrong time, for me more than the 8 min OP has …
So i do really wonder where it “picks” the data from.
My coordinates are fairly right cording to met.no and google, same is the altitude (height above sea level , cording to met.no and google ) , only thing (data) that i could suspect as misleading is the “timezone” we have to choose, as that places me in Stockholm, 600km north east of here ( and definitely at a level near sea ) :grin:
Well atleast the timezone is right in HA , guess on just have to be “observant” upon which sources various integration make use of, and “adapt/fine-tune” best way possible

So, i had to follow your “suggestion” , while i’ve never had sunrise/sunset correct here ( Living at 132-134m above sea-level (i guess) , so i always type 132 when i have to type in altitude.
Followed your example, more or less, i just typed 0 zero meters, in the Map-settings.

Sunset/sunrise changed to 1 minute off ! , compared to the +8 min off, i had when typing 132m
:+1:

Now i just wait out the next weeks temperatures, to monitor the ( met.no )variation, compared to my outside sensors
So indeed “altitude” in the context of the HA Map settings, is misleading ( kind of ) , and probably totally irrelevant in 99 of 100 use-cases here.

Go to the Met.no integration entry and click CONFIGURE. I’m pretty sure its elevation setiing is independent. It probably uses HA’s value as a default when it is first set up, but you can change it to whatever you want afterwards.

EDIT:

In fact, i know it is. I changed my HA elevation seeing to zero, but the Met.no elevation setting is still 187.

i tried, but couldn’t find these setting, even thou i thought that i must have type this info there also …somewhere :grin: … i’ll check again

Bummer , one have to get use to this “configure” button :laughing: ( yep, it’s still 132m ) so i guess im in the right spot there
While i have to get use to the Map Setting in HA , been 132m for about 3 years now !

Where is the WTH of the month, i can click :joy:

Seems my sunrise/sunset times got totally wrong without me changing anything. I use it to trigger blinds go up / go down commands, so we noticed quickly…
Gone through this thread, checked my location on the map (even the elevetion set to 0m…), everything seems correct. But the only way to get the correct sunrise/-set times is to set my location 1300km south, so instead of Switzerland, my home is set in Tunesia now :dromedary_camel:. I would love to see my real home location in HA (not that it really disrupts anything but the weather prediction).

Use the Sun2 integration instead

Has anyone reported this as a bug? It seems like the altitude shouldn’t be fed to the integration, since altitude here is height above sea level, not ground.

It seems that there is a lot of confusion here about calculating the position of the sun with respect of the observer.

While the formulas tend to get a bit bulky if you want to do it “right”, there is no such thing as “elevation above ground”. Never. It’s always elevation with respect to the “geoid” or simpler “sea level”.

On a smartphone or tablet you don’t even need a map for this, as they all have built in GPS. As long as you don’t be near an area of military interest, you can rely on that position to about <5m horizontaly and about 10-50m vertically.

You don’t even need mobile network access. This works perfectly in open sea and in “airplane mode” too. You should have a fair share of free sky above you and walking along in NY-City or Grand-Canyon might induce signal echoes that disturb the measurements. Mobile network just might speed up initial satellite fix, as the current trajectories can be fetched over a fast date line instead of decoding the same values from the data broadcasted by the satellites. GPS (and other networks) is a RADIO RECEIVER, utilizing an antenna.

It WILL get complicated, if you want to include the profile of your local horizon to determine, when the sun will climb behind the nearby ridge. This indeed will not only need YOUR 3D coordinates in space, but that of your surrounding too.

There ARE elevation maps that can (and do) be used to calculate that. Results my vary, depending on how thoroughly the country of your position has measured and published these values. Austria for instance has a near perfect elevation map for both ground AND buildings/vegetation. No problem to calculate the time when the sun climbs behind the little forest on the east side of a nearby hill or even the building up there.

You can time it within a second when either upper limb, center or lower limb crosses the line - refraction of the atmosphere included.

But a calculation that does not state what reference it uses, is to be trusted not better than 15 minutes, no matter how many different sources “agree” on a value. They may all be wrong. The proof is in the pudding. You might not even get DST correction. Without further notice I would think of “center of the sun above mathematical horizon with no air correction”. The latter is about a full Sun diameter or 2 minutes in difference that the “real” sun is early in the morning and late in the evening compared to “air free earth”.

I know this, as I am an astronomer and know how to do it. It’s math, not magic.

If you want the numbers from the penthouse of a sky-scraper, just add the building height to the ground level for your personal “elevation” - or read the numbers from your smartphone.

No one will ever need elevation above “ground” for this. This might be interesting with flying a drone to comply with the regulations, but not for calculating celestial positions.

You keep arguing this everywhere however the built in python function calculates it this way, not HA. So you’re not correct in regards to Python and how python calculates it.

https://astral.readthedocs.io/en/latest/

If you have an issue with this, take it up with the dependency owner, not HA.

Or use GitHub - pnbruckner/ha-sun2: Home Assistant Sun2 Sensor
which can actually take the users position into account

Wait, scrolling months back, Sun2 was already mentioned and even joined by the author.

What petro is arguing against is this sentence.

The elevation is the elevation above ground for the sun library and not the elevation above the sea level.

The elevation in the sun library is used to handle this part of your explanation.

Preamble:

I use the term “sea level” for convenience, as it is the term that can be understood by everyone as “the zero reference from which all geographical elevations are measured”. It makes some assumptions about the general shape of the earth, not the actual sea level. When talking about geographical locations, different definitions of this reference surface are in use, most notable the WGS84 reference frame.

When doing astronomical calculations on angles between an earth-based observer and solar system bodies (= nearby objects), the value of interest is the distance to the gravitational center of the earth (that defines the celestial trajectory), which can be a totally different number but mainly make a difference when calculating stellar eclipses by satellites or such.

So there it is:

At the summit of mount Everest (8,848 m) the maximum difference is 0.00338821 degrees.

Due to the very small difference the astral package does not currently adjust the solar elevation for changes in observer elevation.

r+elevation = “reference surface” + elevation = commonly referred as "elevation above ‘sea level’ " as it makes no difference whether you sit atop of an 8000m high mountain (whose “height” is given as “above sea level” anyway) or an 8000m tall building at the beach.

Sunrise
The time in the morning when the top of the sun breaks the horizon (assuming a location with no obscuring features.)

All examples of “elevation above ground” within Astral are in fact examples of elevation above sea level. At the summit of Mount Everest, the elevation above ground is certainly zero. Even the ISS sample, when talking about elevation above ground is as of how far “down” you see beyond a theoretical, flat horizon due to the curvature of the earth i.e. because of “the sea level reference geoid”. Reading this document, I always find “ground” noted, where “sea level” is meant. I bet the ground reference is the WGS84 definition not the very soil you are standing on.

And according to the docs, this value isn’t even used to calculate Sun elevation.

If you sit in a plane flying over a big mountain, the height above ground will change by big numbers. This however does not change the time of sunrise as seen from your seat at a distant horizon. It’s because your cruise height (elevation above sea level) does not change. Not surprising, the sun is not jumping up and down, mimicking the surface profile below you.

It seems as Astral does “Upper limb, with atmospheric refraction for unobstructed (mathematical, flat) horizon”. That in fact should be fine within a few seconds of reality.

Even if calculated correctly, the effect on elevation for locations on earth surface (not satellites) should be very, very minuscule, not “8 minutes”.

I’ll go through the code to determine where this weird dependency comes from.

Dude, quit pulling things out of thin air and read the code please. Here’s the calculation HA uses:

And here’s where HA uses it in the code, you can see we are calling a direct getattr on the Location object, i.e. pointing directly to the function in the previous link:

And the observer elevation effects at my location every 100 meters:

observer_elevation sunrise offset in minutes
0 06:55:36 0.0
100 06:53:27 -2.1476496333333333
200 06:53:17 -2.3217881166666667
300 06:53:00 -2.59045255
400 06:52:43 -2.875768133333333
500 06:52:26 -3.1597126666666666
600 06:52:10 -3.43689495
700 06:51:54 -3.705733133333333
800 06:51:38 -3.965997633333333
900 06:51:23 -4.217969666666667
1000 06:51:08 -4.462115966666667
1100 06:50:54 -4.698954083333334
1200 06:50:40 -4.928995183333333
1300 06:50:27 -5.15272065
1400 06:50:14 -5.370573733333333
1500 06:50:01 -5.58295825
1600 06:49:49 -5.790240266666667
1700 06:49:36 -5.99275115
1800 06:49:24 -6.190790833333334
1900 06:49:13 -6.3846312
2000 06:49:01 -6.574519183333334
2100 06:48:50 -6.760679499999999
2200 06:48:39 -6.943317133333333
2300 06:48:29 -7.122619566666667
2400 06:48:18 -7.298758716666667
2500 06:48:08 -7.4718925333333335
2600 06:47:57 -7.642166516666666
2700 06:47:47 -7.809715016666667
2800 06:47:37 -7.974662366666666
2900 06:47:28 -8.13712385
3000 06:47:18 -8.29720655
3100 06:47:09 -8.455010216666667
3200 06:46:59 -8.610627849999998
3300 06:46:50 -8.764146366666667
3400 06:46:41 -8.915647116666666
3500 06:46:32 -9.065206366666667
3600 06:46:23 -9.212895716666667
3700 06:46:14 -9.3587825
3800 06:46:06 -9.502930133333333
3900 06:45:57 -9.645398433333334
4000 06:45:49 -9.786243833333334
4100 06:45:40 -9.925519733333335
4200 06:45:32 -10.06327665
4300 06:45:24 -10.199562483333333
4400 06:45:16 -10.334422633333332
4500 06:45:08 -10.467900250000001
4600 06:45:00 -10.600036366666666
4700 06:44:52 -10.730869983333333
4800 06:44:44 -10.8604383
4900 06:44:37 -10.988776766666666
5000 06:44:29 -11.115919183333334
5100 06:44:21 -11.241897866666667
5200 06:44:14 -11.366743683333334
5300 06:44:06 -11.490486183333333
5400 06:43:59 -11.613153633333333
5500 06:43:52 -11.734773133333334
5600 06:43:45 -11.85537065
5700 06:43:37 -11.9749711
5800 06:43:30 -12.0935984
5900 06:43:23 -12.21127555
6000 06:43:16 -12.328024616666665
6100 06:43:09 -12.443866883333333
6200 06:43:02 -12.55882275
6300 06:42:56 -12.672911966666668
6400 06:42:49 -12.786153466666667
6500 06:42:42 -12.89856555
6600 06:42:35 -13.010165866666666
6700 06:42:29 -13.12097145
6800 06:42:22 -13.230998733333333
6900 06:42:16 -13.340263599999998
7000 06:42:09 -13.4487814
7100 06:42:03 -13.556566983333333
7200 06:41:56 -13.663634683333333
7300 06:41:50 -13.769998399999999
7400 06:41:43 -13.875671583333334
7500 06:41:37 -13.980667266666668
7600 06:41:31 -14.084998083333334
7700 06:41:25 -14.188676233333332
7800 06:41:18 -14.291713616666668
7900 06:41:12 -14.394121716666666
8000 06:41:06 -14.495911733333333

That’s an 15 minute swing over 8k meter elevation change. The elevation makes a difference and it’s not calculated by HA. There’s really no other proof you need. If you don’t like this calculation, take it up with astral. Thanks.