Using a small fabric, it is possible to create a 'wake up light' alarm clock that fades in the lights. It would be easy to extend this to include some audio, multiple times, longer fade-in time, etcetera!
<?xml version='1.0' ?>
<fabric author="Tommy van der Vorst" title="Alarm clock" version="2">
<group id="input" direction="in">
<connection type="udp" />
</group>
<group id="leds" direction="out">
<discover type="ep">
<requires>
<supports method="/ep/basic/color/set"/>
</requires>
</discover>
</group>
<variable id="h" type="int32" value="7" />
<variable id="m" type="int32" value="0" />
<variable id="enabled" type="bool" value="0" />
<rule id="set" name="Set alarm">
<pattern>/ep/basic/timed/set</pattern>
<parameter id="enabled" type="bool" friendly-name="Enabled" default="1" bind-value="enabled"/>
<parameter id="hours" type="int32" friendly-name="Hours" min="0" max="23" default="7" nature="discrete" bind-value="h"/>
<parameter id="minutes" type="int32" friendly-name="Minutes" min="0" max="59" default="0" nature="discrete" bind-value="m"/>
<script>
if(!globals.exists(var="timer")) {
globals.timer = null;
}
if(globals.timer!=null) {
globals.timer.cancel;
}
if(message[0]) {
state.enabled = true;
state.h = message[1];
state.m = message[2];
var now = new Date();
var offset = 1;
var ring = null;
if((state.h < now.hour) && (state.m < now.minute)) {
var tomorrow = new Date(now.absolute + (3600*24));
ring = new Date(day=tomorrow.dayOfMonth, month=tomorrow.month, year=tomorrow.year, hours=state.h, minutes=state.m, seconds=0);
}
else {
ring = new Date(day=now.dayOfMonth, month=now.month, year=now.year, hours=state.h, minutes=state.m, seconds=0);
}
var ringUTC = new Date(ring.absolute - offset*3600);
print("Enabling alarm clock at "+state.h+":"+state.m+" GMT+1 "+ring.dayOfMonth+"-"+ring.month+"-"+ring.year+" @ "+ring.hour+":"+ring.minute+":"+ring.second);
globals.timer = schedule(ringUTC, delegate {
if(state.enabled) {
send("leds", new Message("/ep/basic/color/fade", #255, #255, #255));
}
else {
print("Alarm, but was cancelled");
}
});
}
else {
state.enabled = false;
print("Turned off alarm clock");
}
</script>
<description>Sets the time for the wake-up light</description>
</rule>
</fabric>