-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sunset shows 00:00 with certain longitude values. #3601
Comments
Duplicate of #3400 and possibly others. |
@blazoncek I found this in wikipedia, is it the same calculation as in WLED? The wikipedia formula also seems to work above the arctic circle. |
I have no idea where I borrowed that algorithm from (perhaps some NOAA resource). Not from Wikipedia though. |
Could become complicated ... The wikipedia formula avoids However some deeper thinking and lots of testing might be needed if we want to improve the calculations in WLED. Looks like something for 0_15, but I don't see a quick fix in 0_14_1. |
Update: A quick fix could be to avoid angles where tan() becomes unstable. Something like if (abs(L-90.0f) < 1.0f) L = (L<90.0f) ? 89.0f : 91.0f;
if (abs(L-270.0f) < 1.0f) L = (L<270.0f) ? 269.0f : 271.0f; Maybe the angle "L" should first go through In worst case, this would make the final result wrong by 4-8 minutes. |
@blazoncek maybe we could try my "quick fix" in 0_14_1, activated by a special checkbox like "alternative sunset formula (experimental)". So in normal case the unmodified "proven in use" calculation is used, but we could instruct people with problems to try and set the checkmark that activates my workaround. What do you think? |
Agreed to work on it but not for 0.14.1. Perhaps 0.14.2 next month. The use of Even though these types of errors are annoying they are transient in nature (will go away in a day or two) and are limited to certain combinations of LAT & LON. So I would deem them low priority. |
I've looked at the math again - the critical calculation involving Actually another workaround is possible
This way we avoid touching the math, but still we are able to return a useful approximation if case of error. "No sunrise" should actually not happen unless users are behind the polar circles, which is excluded in the settings page already. @blazoncek what's your opinion on this two step approach:
|
That would be good. Perhaps just do it without wrapper? Calling recursively? |
if case of invalid or impossible sunset/sunrise results, retry with the previous day. max 3 days back, to prevent infinite loops and far-away results.
Thanks so much everyone for your help! 😁🙏 For what it's worth, it seems like it didn't come on for at least three nights in a row (before I got around to troubleshooting it). If you implement a recursive function that goes back until it hits a valid day, that could work! Alternatively, you could simply store a valid sunset time. Then, only allow it to be overwritten if the newly calculated sunset time is non-zero. 😀👍 |
Also, storing a valid sunset time (and overwriting it with newly calculated times) seems less likey to crash the system if for some reason it cannot calculate a valid sunset time (i.e. bad input coordinates etc.). |
workaround for invalid sunrise/sunset times (#3601)
Thanks :-) The problem we found is "transient", meaning it will only last for one or two days, but could repeat one year later. There are two possible "triggers":
we don't store a previous days value, because the user might enter a new location, or she/he could experience "arctic day/night". Also we don''t search recursively for more than 3 times, because there is a danger of infinite loops and going back too many days will produce meaningless results. But our fix should improve stability a lot. |
For this scenario, WLED historically follows a "you asked for it, you got it" approach 😉 - also know as "WYGIWYAF what you got is what you asked for" I understand you want the feature to be as reliable as possible, so we try to reduce errors but we won't try to read user's minds. Makes life easier for us developers 😅 |
if case of invalid or impossible sunset/sunrise results, retry with the previous day. max 3 days back, to prevent infinite loops and far-away results.
if case of invalid or impossible sunset/sunrise results, retry with the previous day. max 3 days back, to prevent infinite loops and far-away results.
if case of invalid or impossible sunset/sunrise results, retry with the previous day. max 3 days back, to prevent infinite loops and far-away results.
What happened?
A few days before December 7th (and including December 7th), if the longitude was set to 11.74, the sunset time displayed "00:00" and the sunset scheduling didn't work properly. If I changed the longitude to 111 flat, it worked properly.
A few days ago (around December 18th) 111 stopped working as well, but 110 now works. It appears to be a calculation error that changes over time.
To Reproduce Bug
As of last night, the bug can be recreated by setting the latitude to 40.40 and the longitude to 111. The exact numbers that reproduce the error will likely change over time. After setting that latitude and longitude and clicking "Save", you should see the sunset time display as "00:00".
Expected Behavior
It should calculate an actual sunset time for any valid latitude and longitude (which should be around 17:00 in this case for locations in Utah, USA).
Install Method
Binary from WLED.me
What version of WLED?
0.14.0
Which microcontroller/board are you seeing the problem on?
ESP32
Relevant log/trace output
No response
Anything else?
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: