I am looking for a way to run a macro at sunset.
Since none of the scheduler options allow for this I am at a loss to figure out a way to get a macro to run.
Any ideas ????
How to run a macro at sunset
Moderators: JRL, Dorian (MJT support)
-
- Newbie
- Posts: 13
- Joined: Tue Aug 29, 2006 1:50 am
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Depends what you mean I guess. To know exactly when sunset has occurred I guess you'll need some kind of light senser outside. You can probably get something like that and hook it up to a serial/usb port and have a macro watch the signal. Or, if you're happy to go with predicted sunset times there's probably a website which gives those which you could download and parse with HTTPRequest. Wait, let me try that trusty google thang ... yeh, here we go:
http://www.timeanddate.com/worldclock/a ... html?n=136
That's for London but you can change the location.
Could have Macro Scheduler suck that page down and parse it/store the times somewhere. The controlling macro would loop until the time matches ....
Or, of course, if you are happy to go with an approximation and simply update the schedule every few days, just enter the time in the schedule options (e.g. for London currently it would be around 20:15 and would be accurate enough for the next week or so, and I could then change it next week).
So, kind of depends exactly what you are trying to accomplish. Don't think there's a Windows function that can see out your window and go ping when it sees the sun slip below the horizon. I checked the Microsoft docs but didn't see one
http://www.timeanddate.com/worldclock/a ... html?n=136
That's for London but you can change the location.
Could have Macro Scheduler suck that page down and parse it/store the times somewhere. The controlling macro would loop until the time matches ....
Or, of course, if you are happy to go with an approximation and simply update the schedule every few days, just enter the time in the schedule options (e.g. for London currently it would be around 20:15 and would be accurate enough for the next week or so, and I could then change it next week).
So, kind of depends exactly what you are trying to accomplish. Don't think there's a Windows function that can see out your window and go ping when it sees the sun slip below the horizon. I checked the Microsoft docs but didn't see one

Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
VBScript can do it though http://www.paulsadowski.com/sadowski/suntimes.htmmtettmar wrote:Don't think there's a Windows function that can see out your window and go ping when it sees the sun slip below the horizon. I checked the Microsoft docs but didn't see one

- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Maths can do it of course. See the readme for how it works:
http://cpansearch.perl.org/src/RKHILL/A ... .91/README
http://cpansearch.perl.org/src/RKHILL/A ... .91/README
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Calculate sunrise and sunset times
I went ahead and coded up an example from one of the web links
given above..... seems to work pretty well
Enjoy|!
given above..... seems to work pretty well
Enjoy|!
Code: Select all
VBStart
'SunTimes.vbs
'=========================================================================
' Other Constants & Defs
Const pi = 3.1415926535897932384626433832795
RADEG=180/pi
DEGRAD=pi/180
'=========================================================================
' Main function
Function SunTimes (strYear, strMonth, strDay, longitude, latitude, TZ, isdst)
Dim d, n, i, w, m, l, e, e1, a, xv, yv, v, xs, ys, xe, ecl, lonsun, ye, ze, ra, dec, h
Dim GMST0, UT_Sun_in_south, LHA, hour_rise, hour_set, min_rise, min_set
'calculate days since 2000 jan 1
d = ( 367 * (strYear) - int((7 * ((strYear) + (((strMonth) + 9) / 12))) / 4) + int((275 * (strMonth)) / 9) + (strDay) - 730530)
' Orbital elements of the Sun:
N = 0.0
i = 0.0
w = 282.9404 + 4.70935E-5 * d
a = 1.000000
e = 0.016709 - 1.151E-9 * d
M = 356.0470 + 0.9856002585 * d
M = rev(M)
ecl = 23.4393 - 3.563E-7 * d
L = w + M
if (L <0> 360) then
L = rev(L)
end if
' position of the Sun
E1 = M + e*(180/pi) * sind(M) * ( 1.0 + e * cosd(M) )
xv = cosd(E1) - e
yv = sqrt(1.0 - e * e) * sind(E1)
v = atan2d(yv, xv)
r = sqrt(xv * xv + yv * yv)
lonsun = v + w
if (lonsun <0> 360) then
lonsun = rev(lonsun)
end if
xs = r * cosd(lonsun)
ys = r * sind(lonsun)
xe = xs
ye = ys * cosd(ecl)
ze = ys * sind(ecl)
RA = atan2d(ye, xe)
Dec = atan2d(ze, (sqrt((xe * xe)+(ye * ye))))
h=-0.833
GMST0 = L + 180
if (GMST0 <0> 360) then
GMST0 = rev(GMST0)
end if
UT_Sun_in_south = ( RA - GMST0 - longitude ) / 15.0
if (UT_Sun_in_south <0> -1 AND LHA < 1) then
LHA=acosd(LHA)/15
else
SunTimes = "No sunrise,No sunset"
exit function
end if
hour_rise=UT_Sun_in_south - LHA
hour_set=UT_Sun_in_south + LHA
min_rise=int((hour_rise-int(hour_rise)) * 60)
min_set=int((hour_set-int(hour_set)) * 60)
hour_rise=(int(hour_rise) + (TZ + isdst))
hour_set=(int(hour_set) + (TZ + isdst))
if (min_rise < 10) then
min_rise = right("0000" & min_rise, 2)
end if
if (min_set < 10) then
min_set = right("0000" & min_set, 2)
end if
SunTimes = hour_rise & ":" & min_rise & "," & hour_set & ":" & min_set
End Function
' Support Functions
Function sind(qqq)
sind = sin((qqq) * DEGRAD)
End Function
Function cosd(qqq)
cosd = cos((qqq) * DEGRAD)
End Function
Function tand(qqq)
tand = tan((qqq) * DEGRAD)
End Function
Function atand(qqq)
atand = (RADEG * atan(qqq))
End Function
Function asind(qqq)
asind = (RADEG * asin(qqq))
End Function
Function acosd(qqq)
acosd = (RADEG * acos(qqq))
End Function
Function atan2d (qqq, qqq1)
atan2d = (RADEG * atan2(qqq, qqq1))
End Function
Function rev(qqq)
Dim x
x = (qqq - int(qqq/360.0) * 360.0)
if (x <= 0) then
x = x + 360
end if
rev = x
End Function
Function atan2(ys,xs)
' from the Draw Arrows tip
' @ http://www.devx.com/upload/free/features/VBPJ/techtips/techtips11.pdf
' by —Jim Deutch, Syracuse, New York
Dim theta
If xs <> 0 Then
theta = Atn(ys / xs)
If xs < 0 Then
theta = theta + pi
End If
Else
If ys <0> 0 then
sqrt = Sqr(x)
else
sqrt = 0
end if
end function
VBEnd
//Orlando Florida
Let>longitude=-81.3799972534
Let>latitude=28.5300006866
Let>tzoff=-4
VBEval>Year(Now),Y
VBEval>Month(Now),M
VBEval>Day(Now),D
//VBEval>SunTimes(Year(Now), Month(Now), Day(Now), %longitude%, %latitude%, %tzoff%, 0),result
VBEval>SunTimes("%Y%","%M%","%D%",%longitude%, %latitude%, %tzoff%, 0),result
MessageModal>result
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
Did you try SUN or SOLARIS? They sound like naturals.Don't think there's a Windows function that can see out your window and go ping when it sees the sun slip below the horizon. I checked the Microsoft docs but didn't see one

Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!