I have been working on this for a couple of weeks (off an on) after my phone alarm app failed to wake me up three times (as soon as I unplugged my phone and turned on the screen the alarm activated). Most mornings I have no backup to get kids to school on time, I have lamps in OH to ensure their are woke up in time.
So why use cron over the numerous timer rule examples we have; I’ve tried to implement them and never quite fit, and at one point I created a loop with the logic…coming from a heavy self taught linux background I have a better understanding of cron, so just personal preference on my part and sharing for others that might also want to test.
So lets start with my items, I have two Lyfx mini white bulbs in my bedroom and its part of a fan combo, so the fan has to be running for the bulbs to have power/wifi.
Switch mbedroomlightV45 "Lifx bulb Switches timer" { expire="45s,command=OFF" }
Dimmer mbedroomlightdimV "Master bedroom dimmer" { channel="lifx:whitelight:mbedroom1:brightness", channel="lifx:whitelight:mbedroom2:brightness" [profile="follow"] }
Switch mbedroomlightV "Lifx bulb Switches" { channel="lifx:whitelight:mbedroom1:brightness", channel="lifx:whitelight:mbedroom2:brightness" [profile="follow"] }
Pay attention to the end of my channels (yes you read that right I have two channel on the same item) at this point you should take some time and read up on the documentation as I missed this in one of the releases - https://www.openhab.org/docs/configuration/items.html#profiles
First rule:
rule "Natural wakeup expire timer"
when
Time cron "0 45-59 5 ? * MON,TUE,WED,THU,FRI *" or
Time cron "0 0-30 6 ? * MON,TUE,WED,THU,FRI *"
then
mbedroomlightV45.sendCommand(ON)
end
So this rule runs at 5:45 to 5:59 and then 6:00 to 6:30 and simply turns on the virtual switch that turns off after 45 secs, I selected 45 to give OH a 15 sec gap and avoid timing problems, could be 5 secs if you wanted.
Second rule:
rule "Natural sunrise dim"
when
Item mbedroomlightV45 received command ON
then
val Number hour = now.getHourOfDay
if ( mbedroomlightV.state == OFF && hour < 6) {
mbedroomlightdimV.sendCommand((mbedroomlightdimV.state as PercentType) + 1 )
}
if ( mbedroomlightV.state == ON ) {
if ( mbedroomlightdimV.state < 45) {
mbedroomlightdimV.sendCommand((mbedroomlightdimV.state as PercentType) + 1 )
}
if ( mbedroomlightdimV.state == 45 ) {
mbedroomlightV.sendCommand(OFF)
}
}
end
So this rule just watches the virtual expiring switch and increases the dim level up by 1% and turns it off providing me enough time to wake up and be done getting dressed and other morning routines.