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:
if( isSunrise(-40, 51.5072, 0.1275) == true) then
doSomething()
end
example 2, if its 30 minutes after then you would use
Code:
if( isSunset(30, 51.5072, 0.1275) == true) then
doSomething()
end
And when you need to know if its Sunset or Sunrise then set the offset parameter to 0.
Code:
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
end
Hope this may help.
Thanks,
Roger