Hi,
If you need to know if the current time is equal to an minute offset ( + or - ) of Sunset or Sunrise place these scripts in the Common script. For example, if its 40 minutes before sunrise, you would create a resident script to run every minute.
example 2, if its 30 minutes after then you would use
And when you need to know if its Sunset or Sunrise then set the offset parameter to 0.
Hope this may help.
Thanks,
Roger
If you need to know if the current time is equal to an minute offset ( + or - ) of Sunset or Sunrise place these scripts in the Common script. For example, if its 40 minutes before sunrise, you would create a resident script to run every minute.
Code:
123
if( isSunrise(-40, 51.5072, 0.1275) == true) then
doSomething()
endexample 2, if its 30 minutes after then you would use
Code:
123
if( isSunset(30, 51.5072, 0.1275) == true) then
doSomething()
endAnd when you need to know if its Sunset or Sunrise then set the offset parameter to 0.
Code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445
function isSunset(offset, latitude, longitude)
local sunrise, sunset = rscalc(latitude, longitude)
local now = os.date("*t")
local yr =now.year
local mth = now.month
local dy = now.day
local hr = math.floor(sunset / 60)
local minute = sunset % 60
local tm = os.time{year=yr, month=mth, day=dy, hour=hr, min=minute, sec=0}
local offsettm
if(offset >=1) then
offsettm= tm+(offset*60)
else
offsettm= tm-((offset*-1)*60)
end
local now = os.time()
if(offsettm>=(now-30) and offsettm<=(now+30))then
return true
else
return false
end
end
function isSunrise(offset, latitude, longitude)
local sunrise, sunset = rscalc(latitude, longitude)
local now = os.date("*t")
local yr =now.year
local mth = now.month
local dy = now.day
local hr = math.floor(sunrise / 60)
local minute = sunrise % 60
local tm = os.time{year=yr, month=mth, day=dy, hour=hr, min=minute, sec=0}
local offsettm
if(offset >=1) then
offsettm= tm+(offset*60)
else
offsettm= tm-((offset*-1)*60)
end
local now = os.time()
if(offsettm>=(now-30) and offsettm<=(now+30))then
return true
else
return false
end
endHope this may help.
Thanks,
Roger