I've slightly updated the script to make sure that the device is dimmable. If it's not then it just turns the light on. By the way, this seems to be a hit with the family. I think they like getting up in the morning and not be blasted by light in the bathroom!
--[url=applescript://com.apple.scripteditor/?action=new&script=using%20terms%20from%20application%20%22Indigo%22%0A%09on%20DimADevice(DeviceName)%0A%09%09tell%20application%20%22Indigo%22%0A%09%09%09set%20EarlyCurrentDate%20to%20(date%20string%20of%20(current%20date))%20%26%20%22%2012%3A00%3A00%20AM%22%0A%09%09%09set%20CurrentDateSunrise%20to%20(calculate%20sunrise%20for%20date%20EarlyCurrentDate)%0A%09%09%09set%20CurrentDateSunset%20to%20(calculate%20sunset%20for%20date%20EarlyCurrentDate)%0A%09%09%09if%20(current%20date)%20%3E%20CurrentDateSunrise%20and%20(current%20date)%20%3C%20CurrentDateSunset%20then%0A%09%09%09%09--It's%20daytime%20so%20lights%20are%20at%20100%25%0A%09%09%09%09set%20DimPercent%20to%20100%0A%09%09%09else%0A%09%09%09%09if%20the%20day%20of%20(current%20date)%20is%20the%20(day%20of%20(calculate%20sunset%20for%20(current%20date)))%20and%20(current%20date)%20%3E%20(calculate%20sunrise%20for%20(current%20date))%20then%0A%09%09%09%09%09set%20theSunset%20to%20(calculate%20sunset%20for%20(current%20date))%0A%09%09%09%09%09set%20theSunrise%20to%20calculate%20sunrise%20for%20((current%20date)%20+%20(1%20*%20days))%0A%09%09%09%09else%0A%09%09%09%09%09set%20theSunset%20to%20(calculate%20sunset%20for%20((current%20date)%20-%20(1%20*%20days)))%0A%09%09%09%09%09set%20theSunrise%20to%20calculate%20sunrise%20for%20(current%20date)%0A%09%09%09%09end%20if%0A%09%09%09%09set%20Totalsecs%20to%20theSunrise%20-%20theSunset%0A%09%09%09%09set%20CurrentSecs%20to%20theSunrise%20-%20(current%20date)%0A%09%09%09%09set%20DimPercent%20to%20(CurrentSecs%20%2F%20Totalsecs)%20*%20100%0A%09%09%09%09if%20DimPercent%20%3C%2010%20then%20DimPercent%20%3D%2010%0A%09%09%09end%20if%0A%09%09%09log%20DimPercent%0A%09%09%09if%20(on%20state%20of%20device%20DeviceName)%20is%20false%20and%20(value%20of%20variable%20%22isDaylight%22%20as%20boolean)%20is%20false%20and%20(supports%20dimming%20of%20device%20DeviceName)%20is%20true%20then%20brighten%20DeviceName%20to%20(DimPercent%20as%20integer)%0A%09%09%09if%20(on%20state%20of%20device%20DeviceName)%20is%20false%20and%20(value%20of%20variable%20%22isDaylight%22%20as%20boolean)%20is%20false%20and%20(supports%20dimming%20of%20device%20DeviceName)%20is%20false%20then%20turn%20on%20DeviceName%0A%09%09end%20tell%0A%09end%20DimADevice%0Aend%20using%20terms%20from]Click here to open this script in a new Script Editor window[/url].
using terms from application "Indigo"
on DimADevice(DeviceName)
tell application "Indigo"
set EarlyCurrentDate to (date string of (current date)) & " 12:00:00 AM"
set CurrentDateSunrise to (calculate sunrise for date EarlyCurrentDate)
set CurrentDateSunset to (calculate sunset for date EarlyCurrentDate)
if (current date) > CurrentDateSunrise and (current date) < CurrentDateSunset then
--It's daytime so lights are at 100%
set DimPercent to 100
else
if the day of (current date) is the (day of (calculate sunset for (current date))) and (current date) > (calculate sunrise for (current date)) then
set theSunset to (calculate sunset for (current date))
set theSunrise to calculate sunrise for ((current date) + (1 * days))
else
set theSunset to (calculate sunset for ((current date) - (1 * days)))
set theSunrise to calculate sunrise for (current date)
end if
set Totalsecs to theSunrise - theSunset
set CurrentSecs to theSunrise - (current date)
set DimPercent to (CurrentSecs / Totalsecs) * 100
if DimPercent < 10 then DimPercent = 10
end if
log DimPercent
if (on state of device DeviceName) is false and (value of variable "isDaylight" as boolean) is false and (supports dimming of device DeviceName) is true then brighten DeviceName to (DimPercent as integer)
if (on state of device DeviceName) is false and (value of variable "isDaylight" as boolean) is false and (supports dimming of device DeviceName) is false then turn on DeviceName
end tell
end DimADevice
end using terms from
[enter your name here]
-------------------------
[This script was automatically tagged for color coded syntax by
Script to Markup Code]