Hi i wanted to realize a Alarmclock which triggers the Light… The light has to blink until someone pushes the Lightbutton, or reset it by hab webinterface or the maximum time is over… I did the tutorail for the alarmclock But now i dont know where to proceed… The knx is up and running… I need to understand how to write the rule…
Thanks
This isn’t quite so straight forward as you might think.
If your light is an Item called “Light” and your switch is an Item called “AlarmSwitch”:
NOTE: I just typed this in, there may be errors, I’m missing the imports
var Timer lightsBlinkingTimer = null
rule "Alam Lights"
when
Item Alarm_MasterEvent received command ON
then
if(lightsBlinkingTimer != null) {
lightsBlinkingTimer.cancel
lightsBlinkingTimer = null
}
lightsBlinkingTimer = createTimer(now.plusSeconds(1), [|
Light.sendCommand(if(Light.state == ON) OFF else ON)
lightBlinkingTimer.resechedule(now.plusSeconds(1))
]
end
rule "Stop Alarm"
when
Item AlarmSwitch received command
then
if(lightBlinkingTimer != null) {
lightBlinkingTimer.cancel
lightBlinkingTimer = null
}
end
This creates a timer that triggers every second that toggles the light. The timer resechedules itself so it will continue running forever until it is canceled. The second rule triggers when your switch receives a command and it cancels the timer.
1 Like
thanx