Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Quiet the chatty sun.sun #23832
This might be a breaking change to some, the sun's location updates less frequently.
After this report on reddit, I have tuned the sun.sun sensor so it doesn't update nearly so frequently.
Previously the sun.sun sensor was updating every 30 seconds, day and night.
The Sun moves along its path by 1° of arc for every 4 mins.
With reference to Twilight states I have tuned the sun.sun senor to update depending on the solar elevation:
The total effect of this is that in equatoral areas the sun.sun device goes from generating 1441 events daily, to just 272, which is far more reasonable. It will generate more during some times of the year in polar areas, up to 720 around the equinox where the sun stays low on the horizon, but this will average out over the year and still be a lot less. Hopefully we can save Santa's SD card!
I haven't documented this at this point, happy to contribute it though. There's nothing too much to document though really, for the most part the change is opaque.
I'll explain this a different way, it took me a bit to get my head around
So the Sun moves in the sky by 1° of arc for every four minutes. It doesn't matter what time of the day or night it is, this is happening everywhere on the Earth. This vector can be either perpendicular to parallel to the horizon.
For reference, the disk of the sun takes up approximately 0.5° in the sky, so a shift of less than 0.5° is pretty meaningless since the light will cast more-or-less the same shadows and brightness.
The old code updated the sun's position every 30 seconds, which is just 0.125° of arc. This is a pretty meaningless amount of movement for the most purposes, and we can see that it's causing more issues than benefits since it's flooding the update log.
My first approach focused entirely on the movement with respect to the horizon, and just updated the Sun's position when it moved up or down with respect to it. This isn't so great however because at the poles the Sun moves quite parallel with the horizon, and might not change its elevation all day but in the mean time the light and shadow will change quite a lot. I realised it's really the arc change that matters. I also tried rounding out the elevation and azimuth (the bearing from North of the Sun), but near noon the Sun's azimuth changes rapidly and so you end up with a bunch of useless updates around Noon.
So, angular movement matters. First I cut down the update frequency to 1° of arc, so every 4 mins, but there are times of the day when you care more about where the Sun is. You really don't care much at all during the night, a bit more during twilight, quite a lot as the Sun is low on the horizon, and less during the middle of the day. The outcome of all of this is the update frequency changes depending on where the Sun is in the sky and throws away a lot of the useless position updates during the night and the middle of the day, and concentrates them on the times when the Sun is close to the horizon.
The other thing the PR does is makes sure that the timer for the 'next update' resets when the Sun crosses the horizon, or a few other important elevations, and the position is calculated. As soon as the Sun hits the horizon for example, the sun.sun sensor will update. You have to be careful with solar noon and solar midnight, naively we'd expect solar midnight to be at night, but in the polar winter it isn't.
Example entry for