Made some adjustments. Now it gets true midday and goes from sunset to midday (min-max) and midday to sunset (max-min), because temperature function should be a parabola.
Code:
-- minimum/maximum color temperature
tmin = 2700
tmax = 5800
-- device coordinates
latitude = 0
longitude = 0
sunrise, sunset = rscalc(latitude, longitude)
midday = (sunset + sunrise) / 2
date = os.date('*t')
now = date.hour * 60 + date.min
now = math.max(now, sunrise)
now = math.min(now, sunset)
if (now < midday) then
pos = (now - sunrise) / (midday - sunrise)
color = math.floor(tmin + (tmax - tmin) * (pos))
else
pos = (now - midday) / (sunset - midday)
color = math.floor(tmin + (tmax - tmin) * (1 - pos))
end
grp.checkupdate('1/1/1', color)