All, I have leveraged the AlarmClock function to program my rollershutter up/down. For each rollershutter and for each up or down i therefore need a separate rule that looks like the below. The amazing thing is, similar as in the Wiki for the alarm clock i can program the time etc. when a rollershutter should go down / up. Even this works fine, i think its quite a complicated solution. Has anyone a better, simpler and more efficent idea?
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.action.squeezebox.*
import java.util.concurrent.locks.ReentrantLock
var Timer timer1 = null
var java.util.concurrent.locks.ReentrantLock lock1 = new java.util.concurrent.locks.ReentrantLock()
rule “Initialization”
when
System started
then
postUpdate(StorenTimerSuedWeekendhochZeitStunde, 07)
postUpdate(StorenTimerSuedWeekendhochZeitMinute, 45)
postUpdate(StorenTimerSuedhochSamstag, ON)
postUpdate(StorenTimerSuedhochSonntag, ON)
end
rule “Herunterfahrzeit”
when
Item StorenTimerSuedWeekendhochZeitStunde changed or
Item StorenTimerSuedWeekendhochZeitMinute changed
then
// If the UI to change the Alarm time is clicked several times the code below
// is subject to race conditions. Therefore we make sure that all events
// are processed one after the other.
lock1.lock()
try {
var String msg = “”
// Copy the Alarm-Time from the UI to local variables var stunde = StorenTimerSuedWeekendhochZeitStunde.state as DecimalType var minute = StorenTimerSuedWeekendhochZeitMinute.state as DecimalType
// Combine the hour and minutes to one string to be displayed in the // user interface if (stunde < 10) { msg = "0" } msg = msg + StorenTimerSuedWeekendhochZeitStunde.state.format("%d") + ":"
if (minute < 10) { msg = msg + "0" } msg = msg + StorenTimerSuedWeekendhochZeitMinute.state.format("%d") postUpdate(StorenTimerSuedWeekendhochZeitMessage,msg)
// calculate the alarm time [min] var int weckzeit1 weckzeit1 = (StorenTimerSuedWeekendhochZeitStunde.state as DecimalType).intValue * 60 + (StorenTimerSuedWeekendhochZeitMinute.state as DecimalType).intValue weckzeit1 = weckzeit1.intValue
// calculate current time [min] var int jetzt1 jetzt1 = now.getMinuteOfDay jetzt1 = jetzt1.intValue
// calculate the difference between the requested alarm time and // current time (again in minutes) var int delta1 delta1 = (weckzeit1 - jetzt1) delta1 = delta1.intValue
// add one day (1440 minutes) if alarm time for today already passed if (jetzt1 > weckzeit1) { delta1 = delta1 + 1440 }
// check if there is already an alarm timer; cancel it if present if (timer1 != null) { timer1.cancel timer1 = null }
// create a new timer using the calculated delta [min] timer1 = createTimer(now.plusMinutes(delta1)) [| // This code will be executed if the timer triggers // ************************************************ // check if alarm clock is armed for this weekday var Number day = now.getDayOfWeek if (((day == 6) && (StorenTimerSuedhochSamstag.state == ON)) || ((day == 7) && (StorenTimerSuedhochSonntag.state == ON)) ) { // The things to do if the alarm clock is enabled for this day of week: Lamellen_EG_Whz_Sued.sendCommand(UP) } // Re-Arm the timer to trigger again tomorrow (same time) timer1.reschedule(now.plusHours(24)) // ************************************************ // Here the code ends that executes once the timer triggers ]
} finally {
// release the lock - we are ready to process the next event
lock1.unlock()
}
end