Thought I would share my wake up light. It’s pretty simple and could definitely been done in a more advance way.
The idea
Set the alarm for a given time based on hours and minutes. When the alarm is triggered
the light (using a dimmer) will slowly increase its intensity. Once it reached 100% (or more), the alarm has finished.
I’ve only used it one night, so probably some bugs, but could give you an idea how to use it.
wakeup.items
Group WakeUpAlarm
Number WakeUpHour "Wake up hour [%d]" <clock> (gRestore,WakeUpAlarm)
Number WakeUpMinute "Wake up minute [%d]" <clock> (gRestore,WakeUpAlarm)
Number WakeUpDimStep "Wake up Dim Step [%d]" <light> (gRestore,WakeUpAlarm)
Number WakeUpTimeStep "Wake up Time Step [%d]" <clock> (gRestore,WakeUpAlarm)
Switch WakeUpAlarmSwitch "Wake up alarm [%s]" (gRestore,WakeUpAlarm)
Switch WakeUpAlarmTriggered "Wake up alarm triggered [%s]" <alarm> (gRestore,WakeUpAlarm)
Sitemap
Group label="Wake up Alarm" icon="clock" {
Setpoint item=WakeUpHour minValue=0 maxValue=23 step=1
Setpoint item=WakeUpMinute minValue=0 maxValue=59 step=1
Setpoint item=WakeUpDimStep minValue=1 maxValue=100 step=1
Setpoint item=WakeUpTimeStep minValue=1 maxValue=60 step=1
Switch item=WakeUpAlarmSwitch
Text item=WakeUpAlarmTriggered
The group gRestore could be removed if you don’t want to persist, or if you already presist everything. For more info on gRestore see Design Pattern: Group Based Persistence
wakeup.rules
import org.eclipse.smarthome.core.library.types.DecimalType
import org.eclipse.smarthome.model.script.actions.Timer
var boolean mAlaramTriggered = false
var int mCurrentDimLevel = 0
val String LOG = "WakeUp"
var Timer mWakeUpTimer = null
var Timer mDimmerTimer = null
var int mDimStep
var int mTimeStep
val int DEFAULT_DIM_STEP = 2
val int DEFAULT_TIME_STEP = 1
rule "WakeUpAlarmSwitchOn"
when
Item WakeUpAlarmSwitch changed to ON
then
if (WakeUpMinute.state == NULL || WakeUpHour.state == NULL) {
logInfo(LOG, "WakeUpAlarmMinute or WakeUpAlarmHour not set, alarm not processed")
} else {
var int nowHour = now.getHourOfDay
var int wakeUpHour = (WakeUpHour.state as DecimalType).intValue
var int hours = 0
val int hourDiff = wakeUpHour - nowHour
if (hourDiff >= 0) {
hours = hourDiff
} else {
hours = 24 + wakeUpHour - nowHour
}
var int minutes = 0
val int nowMinute = now.getMinuteOfHour
val int wakeUpMinute = (WakeUpMinute.state as DecimalType).intValue
var int minuteDiff = wakeUpMinute - nowMinute
if (minuteDiff >= 0) {
minutes = minuteDiff
} else {
minutes = 60 + wakeUpMinute - nowMinute
if (hourDiff == 0) {
hours = 24
}
hours--
}
var int totalMinutes = (hours*60) + minutes
logInfo(LOG, "Alarm will be set for: " + totalMinutes + " minutes")
logInfo(LOG, "Alarm: " + hours + " h " + minutes + " min")
WakeUpAlarmTriggered.sendCommand(OFF)
if (mWakeUpTimer != null) {
mWakeUpTimer.cancel
mWakeUpTimer = null
}
mWakeUpTimer = createTimer(now.plusMinutes(totalMinutes), [|
logInfo(LOG, "Alarm triggered! ")
WakeUpAlarmTriggered.sendCommand(ON)
mWakeUpTimer = null
])
}
end
rule "WakeUpAlarmTriggeredOn"
when
Item WakeUpAlarmTriggered changed to ON
then
logInfo(LOG, "Alarm trigger starting to dim")
mCurrentDimLevel = 0
if (WakeUpDimStep.state == NULL) {
logInfo(LOG, "Dimstep not defined using default")
mDimStep = DEFAULT_DIM_STEP
} else {
mDimStep = (WakeUpDimStep.state as DecimalType).intValue
}
if (WakeUpTimeStep.state == NULL) {
logInfo(LOG, "Dimstep not defined using default")
mTimeStep = DEFAULT_TIME_STEP
} else {
mTimeStep = (WakeUpTimeStep.state as DecimalType).intValue
}
mDimmerTimer = createTimer(now.plusMinutes(mTimeStep), [|
mCurrentDimLevel += mDimStep
logInfo(LOG, "Dimming " + mCurrentDimLevel)
if (mCurrentDimLevel >= 100) {
logInfo(LOG,"Dimming is at its max, finished")
mCurrentDimLevel = 100
} else {
logInfo(LOG, "Reschedule dimmer " + mTimeStep + " min")
mDimmerTimer.reschedule(now.plusMinutes(mTimeStep))
}
// Enter your dimmer name here
MYDIMMER.sendCommand(mCurrentDimLevel)
if (mCurrentDimLevel == 100) {
WakeUpAlarmSwitch.sendCommand(OFF)
}
])
end
rule "WakeUpAlarmSwitchOff"
when
Item WakeUpAlarmSwitch changed to OFF
then
logInfo(LOG, "Switch off wakeup")
if (mDimmerTimer != null) {
mDimmerTimer.cancel
mDimmerTimer = null
}
if (mWakeUpTimer != null) {
mWakeUpTimer.cancel
mWakeUpTimer = null
}
WakeUpAlarmTriggered.sendCommand(OFF)
end