Thank you for everything!

If you are talking to me, and I'm not sure if you are, I did make progress. I'll show you how close I am, even though it's not working yet. I presumed that you were going with noisneil's solution.

Note that until the KM v11 "Get Location action" is fixed (it usually times out) I can't use that action, but I can let the user enter his latitude, longitude in a variety of ways, like the following, and in this example I have entered the latitude and longitude into the variables X and Y, and also converted them to radians at the same time (because KM's SIN() function works with radians only.)

The numbers -45 and 49 are longitude and latitude numbers picked at random for some random location in my time zone. I'm not quite sure where that location is. It doesn't matter.

In addition, you need to know the numeric value of the day of the year, and I didn't realize it takes two KM actions to accomplish that. Notice in the first action that I get the integer day of the year, then I convert it to a real number by adding the fractional hours and minutes:

Then for the real magic, which isn't quite working yet:...

What this is supposed to do is convert the X and Y values to an angle that represents how high the Sun is above the horizon. I think it's close, but there's something wrong with it.

The formula I'm using is a well-known approximation for calculating the solar altitude, but it's off by under 1%. I don't think 1% is a problem for most people anyway.

I didn't google whether there was such a formula, because I knew from common sense that there was such a formula. After 10 minutes of not being able to figure it out myself, I googled whether it was possible, and found this formula, which represents the maximum solar angle at noon on the equator for a given day of the year "d" (irrespective of longitude):

When I saw that, I knew I was close. The first half of that equation is just a constant. Inside the SIN() function is a single variable and a couple of constants. When I saw this I knew immediately that the Sun's maximum angle is nothing more than a Sine wave function. The part that depends on the Sine wave is the day of the year and the time of day. The part that doesn't depend on the Sine wave is the latitude. All I had to do was modify the equation to take those extra two factors into account.

I suspect that the Sunset trigger in iOS is nothing more than the code I am trying to write, above. I can't imagine what else it could be. It's just a simple formula.

I'm not very good with trig functions, but I have experience using them to do things in KM like "move the mouse X pixels in direction Y radians."

P.S. COS() and SIN() are identical functions. Just shifted.

Could you use this?

```
#!/bin/bash
# Fetching the location based on IP address using ipinfo.io
LOCATION=$(curl -s https://ipinfo.io/loc)
echo "Your approximate location based on IP address is: $LOCATION"
```

Wow! I sure could use that! It's so hard to find websites that return succinct, useful information.

As a matter of fact, that web page returns the smallest amount of information that I've ever seen any web page return.

Yup, I was asking about your solution. That's some serious calculations. Wow. I'd love to try your solution too when it's ready to test. Thank you so much!

Yup, I would like to use my solution too. As I said, it's probably the same formula that Apple uses for its own calculation for Sunset and Sunrise. Also, as I said, my formula has (slightly under) a 1% error rate, and there's a formula that is more accurate but it's three times as long and uses functions I hate like Arctan. I have enough trouble with Sine and Cosine. Most likely Apple uses the more advanced formula, which accounts for the elliptical orbit of the Earth around the Sun.

I'll probably get it to work, but today I received my new M3 iMac and I'm having a lot of fun setting it up.

Well, the solution I'm using is not working. I've tried it for several days, reboots too & it's not working. Independently: The Shortery is good. The Shortcut is good. And the Macro is good. BUT the Shortcut is failing to trigger the Web Server even though it is running, so the Macro is never run. Any thoughts? Thanks!

Try running the shortcut via native automation on your iPhone instead of Shortery.

Ok. I just tried the iOS Shortcut itself before I made an automation for it & it failed, so it's still not triggering the Web Server that triggers the Macro. and the Web Server is 100% up and running.

Can you show us a screenshot of the shortcut?

I did. I did all 3 screenshots above several days ago. I haven't changed any of them. Do you see anything I'm doing wrong? Thanks so much!

Ah so you did. Hmm, maybe try copying the URL trigger again, just to be doubly sure? Other than that, I'm stumped.

I'm assuming the macro works on its own and is in a global group?

THANK YOU!!! That was it! I must have missed that information previously! The Macro was not in a Global Group! Duh I'm so stupid. Thank you so much!

Shortery Dev also responded to let me know that the Sunrise/Sunset function does indeed every day. Just thought I'd post that info here as well. Thanks again!

Although I struggled to complete the math above to make this work, I found a new way to make it work. I will post my solution in another thread shortly.