Simulated Sunrise - an improved wake up light in PLEG

I had used the Wakeup Light plug in for years to give me an artificial sunrise. I had hacked the original code a bit, but still desired a bit more. So I finally sat down and wrote one in PLEG. Here are a few of the design characteristics of my simulated sunrise, aka Simrise:

[ul][li]This uses a non-linear equation to compensate for how we perceive light. (If you want to see this, look at the difference in light change from 0 to 25% versus 75% to 100%. Significant change at the low end, barely noticeable at the high end). This equation effectively spends more time in the lower half of the dimmer band than the upper half. Also, most LEDs don?t dim below 10%, so I start the ramp at 10%. I use 90 steps at 20 seconds each to make a 30 minute ramp time. You’ll notice some math tricks to calculate this non-linear curve using only integers and the limited math functions available in PLEG.[/li]
[li]As a result of the non-linear curve, during the first part of the ramp light levels don?t change very often. Simrise only sends a z-wave command when the value changes. At the beginning there will be several minutes between updates but will quickly increase the frequency until every 20 seconds a new command is sent.[/li]
[li]Some mornings I get up early. If I am already up and the bedroom light is on, Simrise detects this and doesn’t run. Similarly, if I turn the light to 100% at any point during the ramp Simrise will detect this and stop. If I’m feeling lazy and turn the light off, Simrise will detect this, stop the ramp, and let me sleep in darkness.[/li]
[li]I don’t need Simrise to run during the summer when the natural sunrise is early. Simrise monitors the time of natural sunrise and automatically enables and disables itself by setting a MultiSwitch. One benefit of this method is that if I get home late and night and know I want to sleep in the next morning, all I need to do is toggle the MultiSwitch and the sunrise will be turned off for the next morning. The next morning Simrise will check against the natural sunrise and reset the MultiSwitch, so I don’t need to remember to turn it back on.[/li][/ul]
While I’ve tested this a bit, I’m sure there are one or two boundary conditions I didn’t think of. Please let me know if you have any improvements.

Triggers
tAtHome MultiSwitch Switch 1 is turned on
tMasterBedLightsOff Whenever the Master Bedroom Lights is turned off
tSimriseEnabled MultiSwitch Switch 7 is turned on
tSimriseInProcess MultiSwitch Switch 8 is turned on
Schedules
sSimriseStartTime Absolute start at 05:30:00. Off time: +00:15:00r
sSimriseTimer Self Trigger. Off Interval after 00:00:20
sSunrise Day of Week, on time r (sunrise), off Internal 00:01:00

Properties
pMasterBedroomLight Master Bedroom Light LoadLevelStatus
Counters
cSimriseCounter Ordinal
Conditions
SimriseEnable Repeats 05:45:00; sSunrise
SimriseDisable Repeats NOT SimriseEnable
SimriseStart sSimriseStartTime AND tSimriseEnabled AND tAtHome AND tMasterBedLightOff
SimriseStop (SimriseLevel >= 100) OR (pMasterBedroomLight == 100) OR tMasterBedLightsOff
SimriseLevel (((cSimriseCounter)(cSimriseCounter)) - (((cSimriseCounter)(cSimriseCounter)) % 90)) / 90 + 10
SimriseUpdateLight (SimriseLevel > pMasterBedroomLight) AND (SimriseLevel <= 100) AND tSimriseInProcess
SimriseIncrement (tSimriseInProcess AND !sSimriseTimer)
Actions
SimriseEnable MultiSwitch SetStatus7 newStatus7=1
SimriseDisable MultiSwitch SetStatus7 newStatus7=0
SimriseStart {This PLEG}ClearCounter counterName=cSimriseCounter
{This PLEG} StartTimer timerName=sSimriseTimer intervalTime=
MultiSwitch SetStatus8 newStatus8=1
SimriseUpdateLight Master Bedroom Light SetLoadLevelTarget newLoadlevelTarget={(SimriseLevel)}
SimriseIncrement {This PLEG}IncrementCounter counterName=cSimriseCounter counterIncrement=1
{This PLEG}StartTimer timerName=sSimriseTimer intervalTime=
SimriseStop MultiSwitch SetStatus8 newStatus8=0